[30] | 1 | <?php |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | if (!defined("_ECRIRE_INC_VERSION")) return; |
---|
| 5 | |
---|
| 6 | include_spip('inc/texte'); |
---|
| 7 | include_spip('inc/presentation'); |
---|
| 8 | include_spip('inc/agenda_filtres'); |
---|
| 9 | include_spip('inc/agenda_gestion'); |
---|
| 10 | |
---|
| 11 | function inc_voir_agenda($flag_editable){ |
---|
| 12 | global $visu_evenements; |
---|
| 13 | $type = _request('type'); |
---|
| 14 | $partie_cal = _request('partie_cal'); |
---|
| 15 | if (!$type) $type='semaine'; |
---|
| 16 | $id_evenement = intval(_request('id_evenement')); |
---|
| 17 | $ajouter_id_article = intval(_request('ajouter_id_article')); |
---|
| 18 | global $annee,$mois,$jour; |
---|
| 19 | $annee = intval(_request('annee')); |
---|
| 20 | $mois = intval(_request('mois')); |
---|
| 21 | $jour = intval(_request('jour')); |
---|
| 22 | |
---|
| 23 | $visu_evenements=array(); |
---|
| 24 | |
---|
| 25 | if ((!$annee)||(!$mois)||(!$jour)){ |
---|
| 26 | if (!$id_evenement){ // pas d'id_evenement--> date du jour |
---|
| 27 | $stamp=time(); |
---|
| 28 | } |
---|
| 29 | else { // date de l'evenement |
---|
| 30 | $res = spip_query("SELECT date_debut FROM spip_evenements WHERE id_evenement="._q($id_evenement)); |
---|
| 31 | if ($row = spip_fetch_array($res)) |
---|
| 32 | $stamp=strtotime($row['date_debut']); |
---|
| 33 | else |
---|
| 34 | $stamp=time(); |
---|
| 35 | } |
---|
| 36 | $annee=date('Y',$stamp); |
---|
| 37 | $mois=date('m',$stamp); |
---|
| 38 | $jour=date('d',$stamp); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | $urlbase=self(); |
---|
| 43 | $urlbase=parametre_url($urlbase,'edit',''); |
---|
| 44 | $urlbase=parametre_url($urlbase,'del',''); |
---|
| 45 | $urlbase=parametre_url($urlbase,'ndate',''); |
---|
| 46 | $urlbase=parametre_url($urlbase,'id_evenement',''); |
---|
| 47 | $urlbase=parametre_url($urlbase,'neweven','1'); |
---|
| 48 | |
---|
| 49 | //$urlbase=str_replace("&","&",$urlbase); |
---|
| 50 | |
---|
| 51 | // creation des boites creneaux horaires pour ajout rapide |
---|
| 52 | list($ts_start,$ts_fin) = date_debut_fin($annee,$mois,$jour,$type); |
---|
| 53 | if ($flag_editable) |
---|
| 54 | ajoute_creneaux_horaires($urlbase,$ts_start,$ts_fin,$type,$partie_cal,$echelle); |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | $categorie_concerne=array('plage'=>'calendrier-plage','evenement'=>'calendrier-evenement'); |
---|
| 58 | $categorie_info=array('plage'=>'calendrier-plage-info','evenement'=>'calendrier-evenement-info'); |
---|
| 59 | |
---|
| 60 | $datestart=date('Y-m-d H:i:s',$ts_start-24*60*60); |
---|
| 61 | $datefin=date('Y-m-d H:i:s',$ts_fin+24*60*60); |
---|
| 62 | |
---|
| 63 | // tous les evenements |
---|
| 64 | $res = spip_query("SELECT * |
---|
| 65 | FROM spip_evenements AS evenements |
---|
| 66 | WHERE ((evenements.date_debut>='$datestart' AND evenements.date_debut<='$datefin') |
---|
| 67 | OR (evenements.date_fin>='$datestart' AND evenements.date_fin<='$datefin') |
---|
| 68 | OR (evenements.date_debut<'$datestart' AND evenements.date_fin>'$datefin')) |
---|
| 69 | ORDER BY evenements.date_debut;"); |
---|
| 70 | $urlbase=parametre_url($urlbase,'neweven',''); |
---|
| 71 | $urlbase=parametre_url($urlbase,'annee',$annee); |
---|
| 72 | $urlbase=parametre_url($urlbase,'mois',$mois); |
---|
| 73 | $urlbase=parametre_url($urlbase,'jour',$jour); |
---|
| 74 | while ($row = spip_fetch_array($res)){ |
---|
| 75 | $is_evt=($row['horaire']!='oui') |
---|
| 76 | ||($row['date_debut']<$datestart && $row['date_fin']>$datefin); |
---|
| 77 | $concerne=(!$ajouter_id_article) || ($ajouter_id_article==$row['id_article']); |
---|
| 78 | |
---|
| 79 | $url=parametre_url($urlbase,'id_evenement',$row['id_evenement']); |
---|
| 80 | $url=parametre_url($url,'ajouter_id_article',$row['id_article']); |
---|
| 81 | $args = explode('?',parametre_url($url,'exec','')); |
---|
| 82 | // $url sous forme d'array pour appeler ajax_action_auteur |
---|
| 83 | $url = array('action'=>'voir_evenement','id'=>"0-voir",'script'=>'calendrier','args'=>end($args)); |
---|
| 84 | |
---|
| 85 | $titre = typo($row['titre']); |
---|
| 86 | $descriptif = typo($row['descriptif']); |
---|
| 87 | $lieu = typo($row['lieu']); |
---|
| 88 | $texte=wordwrap(entites_html($row['titre'],ENT_QUOTES),15,"<br />\n"); |
---|
| 89 | if (($type!='mois')&&(!$is_evt)) |
---|
| 90 | $texte.="<hr />" . wordwrap(entites_html($row['descriptif'],ENT_QUOTES),15, "<br />\n"); |
---|
| 91 | if (strlen($texte)==0) $texte=_L("(sans objet)"); |
---|
| 92 | |
---|
| 93 | if ($concerne) $categorie = $categorie_concerne; |
---|
| 94 | else $categorie = $categorie_info; |
---|
| 95 | if ($is_evt) $categorie = $categorie['evenement']; |
---|
| 96 | else $categorie = $categorie['plage']; |
---|
| 97 | if ($id_evenement==$row['id_evenement']) |
---|
| 98 | $categorie.='-selection'; |
---|
| 99 | |
---|
| 100 | if (!$is_evt) |
---|
| 101 | Agenda_memo_full($row['date_debut'], $row['date_fin'], $titre, $descriptif, $lieu, $url, $categorie); |
---|
| 102 | else{ |
---|
| 103 | //if ($type!='mois') |
---|
| 104 | // Agenda_memo_evt_full($row['date_debut'], $row['date_debut'], Agenda_rendu_boite($titre,$descriptif,$lieu), "", "", $url, $categorie); |
---|
| 105 | //else |
---|
| 106 | Agenda_memo_evt_full($row['date_debut'], $row['date_fin'], $titre, $descriptif, $lieu, $url, $categorie); |
---|
| 107 | } |
---|
| 108 | $visu_evenements[$row['id_evenement']]=1; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | $s = "<span class='agenda-calendrier'>\n"; |
---|
| 112 | // attention : bug car $type est modifie apres cet appel ! |
---|
| 113 | $s .= Agenda_affiche_full(1,'', $type, 'calendrier-creneau','calendrier-creneau-today','calendrier-creneau-sunday','calendrier-plage','calendrier-evenement','calendrier-plage-info','calendrier-evenement-info','calendrier-plage-selection','calendrier-evenement-selection'); |
---|
| 114 | $s .= "</span>"; |
---|
| 115 | |
---|
| 116 | return $s; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | function date_debut_fin($annee,$mois,$jour,$type){ |
---|
| 120 | if ($type=='jour'){ |
---|
| 121 | $ts_start=strtotime("$annee-$mois-01 00:00:00"); |
---|
| 122 | $ts_start+=($jour-1)*24*60*60; |
---|
| 123 | $ts_fin=$ts_start+24*60*60; |
---|
| 124 | } else |
---|
| 125 | if ($type=="semaine"){ |
---|
| 126 | $ts_start=strtotime("$annee-$mois-01 01:00:00"); |
---|
| 127 | $ts_start+=($jour-1)*24*60*60; |
---|
| 128 | while (date('w',$ts_start)!=1) $ts_start-=24*60*60; |
---|
| 129 | $ts_fin=$ts_start+7*24*60*60+60*60; |
---|
| 130 | $ts_start-=2*60*60; |
---|
| 131 | } else |
---|
| 132 | if ($type=='mois'){ |
---|
| 133 | $ts_start=strtotime("$annee-$mois-01 00:00:00"); |
---|
| 134 | if ($mois<'12') |
---|
| 135 | $ts_fin=strtotime("$annee-".($mois+1)."-01 00:00:00"); |
---|
| 136 | else |
---|
| 137 | $ts_fin=strtotime(($annee+1)."-$mois-01 00:00:00"); |
---|
| 138 | } |
---|
| 139 | return array($ts_start,$ts_fin); |
---|
| 140 | } |
---|
| 141 | function ajoute_creneaux_horaires($urlbase,$ts_start,$ts_fin,$type,$partie_cal,$echelle){ |
---|
| 142 | // creneaux pour ajout uniquement si ajouter_id_article present |
---|
| 143 | if (($type!='mois')&&($partie_cal!='sansheure')&&($partie_cal!=NULL)) |
---|
| 144 | { |
---|
| 145 | if ($echelle<=120) |
---|
| 146 | $freq_creneaux=30*60; |
---|
| 147 | else |
---|
| 148 | $freq_creneaux=60*60; |
---|
| 149 | |
---|
| 150 | $today=date('Y-m-d'); |
---|
| 151 | $heuremin='08';$heuremax='20'; |
---|
| 152 | if ($partie_cal=='matin'){ |
---|
| 153 | $heuremin='04';$heuremax='15'; |
---|
| 154 | } |
---|
| 155 | if ($partie_cal=='soir'){ |
---|
| 156 | $heuremin='12';$heuremax='23'; |
---|
| 157 | } |
---|
| 158 | for ($j=$ts_start;$j<=$ts_fin;$j+=$freq_creneaux){ |
---|
| 159 | $heure=date('H',$j); |
---|
| 160 | if (($heure>=$heuremin)&&($heure<=$heuremax)){ |
---|
| 161 | $url=parametre_url($urlbase,'ndate',urlencode(date('Y-m-d H:i',$j))); |
---|
| 162 | $args = explode('?',parametre_url($url,'exec','')); |
---|
| 163 | // $url sous forme d'array pour appeler ajax_action_auteur |
---|
| 164 | $url = array('action'=>'voir_evenement','id'=>"0-editer",'script'=>'calendrier','args'=>end($args),'fct_ajax'=>'wc_init'); |
---|
| 165 | $creneau=date('Y-m-d H:i:s',$j); |
---|
| 166 | if (date('Y-m-d',$j)==$today) |
---|
| 167 | Agenda_memo_full($creneau,$creneau,preg_replace(",\s+,"," ",date('H:i',$j)." "._T('agenda:ajouter_un_evenement')), " ", "", $url,'calendrier-creneau-today'); |
---|
| 168 | else if (date('w',$j)==0) |
---|
| 169 | Agenda_memo_full($creneau,$creneau,preg_replace(",\s+,"," ",date('H:i',$j)." "._T('agenda:ajouter_un_evenement')), " ", "",$url,'calendrier-creneau-sunday'); |
---|
| 170 | else |
---|
| 171 | Agenda_memo_full($creneau,$creneau,preg_replace(",\s+,"," ",date('H:i',$j)." "._T('agenda:ajouter_un_evenement')), " ", "",$url,'calendrier-creneau'); |
---|
| 172 | } |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | function http_calendrier_ics_message($annee, $mois, $jour, $large) |
---|
| 178 | { |
---|
| 179 | return ""; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | function http_calendrier_aide_mess() |
---|
| 183 | { |
---|
| 184 | return ""; |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | function http_calendrier_semainesh($annee, $mois, $jour, $echelle, $partie_cal, $script, $ancre, $evt) |
---|
| 188 | { |
---|
| 189 | global $spip_ecran; |
---|
| 190 | if (!isset($spip_ecran)) $spip_ecran = 'large'; |
---|
| 191 | |
---|
| 192 | $init = date("w",mktime(1,1,1,$mois,$jour,$annee)); |
---|
| 193 | $init = $jour+1-($init ? $init : 7); |
---|
| 194 | $sd = ''; |
---|
| 195 | |
---|
| 196 | if (is_array($evt)) |
---|
| 197 | { |
---|
| 198 | list($sansduree, $evenements, $premier_jour, $dernier_jour) = $evt; |
---|
| 199 | if ($sansduree) |
---|
| 200 | foreach($sansduree as $d => $r) |
---|
| 201 | $evenements[$d] = !$evenements[$d] ? $r : array_merge($evenements[$d], $r); |
---|
| 202 | $finurl = "&echelle=$echelle&partie_cal=$partie_cal$ancre"; |
---|
| 203 | $evt = |
---|
| 204 | http_calendrier_semaine_noms($annee, $mois, $init, $script, $finurl) . |
---|
| 205 | http_calendrier_mois_sept($annee, $mois, $init, $init+ 6, $evenements, $script); |
---|
| 206 | } else $evt = "<tr><td>$evt</td></tr>"; |
---|
| 207 | |
---|
| 208 | return |
---|
| 209 | "\n<table class='calendrier-table-$spip_ecran' cellspacing='0' cellpadding='0'>" . |
---|
| 210 | http_calendrier_semaine_navigation($annee, $mois, $init, $echelle, $partie_cal, $script, $ancre) . |
---|
| 211 | $evt . |
---|
| 212 | "</table>" . |
---|
| 213 | (_DIR_RESTREINT ? "" : http_calendrier_aide_mess()); |
---|
| 214 | } |
---|
| 215 | ?> |
---|