source: plugins/widget_calendar_1_9/inc/calendar_init.php @ 6

Last change on this file since 6 was 6, checked in by guille, 17 years ago

plugin agenda para poner eventos en SPIP.js

File size: 10.2 KB
Line 
1<?php
2
3$p=explode(basename(_DIR_PLUGINS)."/",str_replace('\\','/',realpath(dirname(dirname(__FILE__)))));
4define('_DIR_PLUGIN_WIDGET_CALENDAR',(_DIR_PLUGINS.end($p)));
5
6function WCalendar_point_entree($suffixe){
7        return "<div id='container$suffixe' style='position:absolute;display:none;z-index:5000;'></div>
8        ";
9}
10
11function WCalendar_body_prive($flux){
12        global $WCalendar_independants,$WCalendar_lies;
13        if (count($WCalendar_independants)+count($WCalendar_lies)){
14                $flux.= "<script type='text/javascript'>window.onload = init;</script>";
15                foreach($WCalendar_independants as $infos)
16                        $flux .= WCalendar_point_entree($infos['suffixe']);
17                foreach($WCalendar_lies as $infos){
18                        $flux .= WCalendar_point_entree($infos['suffixe1']);
19                        $flux .= WCalendar_point_entree($infos['suffixe2']);
20                }
21        }
22        return $flux;
23}
24
25function WCalendar_statique_jsinit($t, $s){
26        $vars = "
27                        var cal$s;";
28        $js_a = "";
29        $js_b = "
30                        var selected$s = '';
31                        this.content$s = document.getElementById('selected_date$s');
32                        if (this.content$s){
33                                selected$s=this.content$s.innerHTML;
34                        }
35                        cal$s = new SPIP.widget.Calendar2up_INT_multi('cal$s','container$s','',selected$s);
36                        cal$s.title = '$t';
37                        cal$s.sync();
38                        cal$s.render();
39                        ";
40        $js_c = "
41                function getSelectedDate$s() {
42                        var res = document.getElementById('selected_date$s');
43                        res.innerHTML = cal$s.getSelectedDates();
44                }
45        ";
46        return array($vars,$js_a,$js_b,$js_c);
47}
48
49function WCalendar_jsinit($t, $s){
50        $vars = "
51                        var cal$s;";
52        $js_a = "
53                        if (cal$s)
54                                cal$s.hide();";
55        $js_b = "
56                        this.link$s = document.getElementById('dateLink$s');
57                        if (this.link$s){
58                                this.selYear$s = document.getElementById('annee$s');
59                                this.selMonth$s = document.getElementById('mois$s');
60                                this.selDay$s = document.getElementById('jour$s');
61                                thisYear$s = this.selYear$s.selectedIndex+parseInt(this.selYear$s.options[0].value);
62                                thisMonth$s = this.selMonth$s.selectedIndex;
63                                thisDay$s = this.selDay$s.selectedIndex +1;
64                                cal$s = new SPIP.widget.Calendar2up_INT('cal$s','container$s',(thisMonth$s+1)+'/'+thisYear$s,(thisMonth$s+1)+'/'+thisDay$s+'/'+thisYear$s);
65                                cal$s.title = '$t';
66                                cal$s.setChildFunction('onSelect',setDate$s);
67                                cal$s.render();
68                        }
69                        ";
70        $js_c = "
71                function showCalendar$s() {
72                        hideall();
73                        cal$s.outerContainer.style.top = (link$s.height-1+findPosY(link$s)) + 'px';
74                        cal$s.outerContainer.style.left = (findPosX(link$s)) + 'px';
75                        cal$s.outerContainer.style.display='block';
76                }
77                ";
78        return array($vars,$js_a,$js_b,$js_c);
79}
80function WCalendar_js_verifie_lies($sd,$sf){
81        return "
82                function verifie_date$sd$sf(modif){
83                        var Date$sd = new Date;
84                        Date$sd.setFullYear(this.selYear$sd.selectedIndex+parseInt(selYear$sd.options[0].value));
85                        Date$sd.setMonth(this.selMonth$sd.selectedIndex);
86                        Date$sd.setDate( this.selDay$sd.selectedIndex + 1);
87                        var Date$sf = new Date;
88                        Date$sf.setFullYear(this.selYear$sf.selectedIndex+parseInt(selYear$sf.options[0].value));
89                        Date$sf.setMonth(this.selMonth$sf.selectedIndex);
90                        Date$sf.setDate( this.selDay$sf.selectedIndex + 1);
91                        if (Date$sf<Date$sd){
92                                if (modif==1){
93                                        selYear$sf.selectedIndex=selYear$sd.selectedIndex;
94                                        selMonth$sf.selectedIndex=selMonth$sd.selectedIndex;
95                                        selDay$sf.selectedIndex=selDay$sd.selectedIndex;
96                                        cal$sf.select((Date$sd.getMonth()+1) + '/' + (Date$sd.getDate()) + '/' + (Date$sd.getFullYear()));
97                                        cal$sf.setMonth(Date$sd.getMonth());
98                                        cal$sf.setYear(Date$sd.getFullYear());
99                                        cal$sf.render();
100                                }
101                                else{
102                                        selYear$sd.selectedIndex=selYear$sf.selectedIndex;
103                                        selMonth$sd.selectedIndex=selMonth$sf.selectedIndex;
104                                        selDay$sd.selectedIndex=selDay$sf.selectedIndex;
105                                        cal$sd.select((Date$sf.getMonth()+1) + '/' + (Date$sf.getDate()) + '/' + (Date$sf.getFullYear()));
106                                        cal$sd.setMonth(Date$sf.getMonth());
107                                        cal$sd.setYear(Date$sf.getFullYear());
108                                        cal$sd.render();
109                                }
110                        }
111                }
112                ";
113}
114function Wcalendar_js_set_change_date($s,$sdverif=NULL,$sfverif=NULL,$modif=""){
115        return "
116                function setDate$s() {
117                        var date$s = cal$s.getSelectedDates()[0];
118                        selYear$s.selectedIndex=date$s.getFullYear()-parseInt(selYear$s.options[0].value);
119                        selMonth$s.selectedIndex=date$s.getMonth();
120                        selDay$s.selectedIndex=date$s.getDate()-1;
121                        cal$s.hide();
122                        " .
123                        ($sdverif!=NULL?"verifie_date$sdverif$sfverif($modif);":"") ."
124                }
125
126                function changeDate$s() {
127                        var month = this.selMonth$s.selectedIndex;
128                        var day = this.selDay$s.selectedIndex + 1;
129                        var year = this.selYear$s.selectedIndex+parseInt(selYear$s.options[0].value);
130                        cal$s.reset();
131                        cal$s.clear();
132                        cal$s.select((month+1) + '/' + day + '/' + year);
133                        cal$s.setMonth(month);
134                        cal$s.setYear(year);
135                        cal$s.render();
136                        " .
137                        ($sdverif!=NULL?"verifie_date$sdverif$sfverif($modif);":"") ."
138                }
139                ";
140}
141function WCalendar_header_prive($flux) {
142        global $WCalendar_independants,$WCalendar_lies,$WCalendar_statiques;
143        global $spip_lang_right;
144        if (count($WCalendar_independants)+count($WCalendar_lies)){
145                // Remplace les entités litérales
146                $trans_tbl = get_html_translation_table (HTML_ENTITIES);
147                $trans_tbl = array_flip ($trans_tbl);
148               
149                // les includes JS statiques
150                $flux .= "<script src = '"._DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/SPIP.js' ></script>\n";
151                $flux .= "<script src = '"._DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/dom.js' ></script>\n";
152                $flux .= "<script src = '"._DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/event.js' ></script>\n";
153                $flux .= "<script src = '"._DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/calendar.js' ></script>\n";
154                $flux .= "<script src = '"._DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/calendar_custom.js' ></script>\n";
155                $flux .= '<link rel="stylesheet" href="' ._DIR_PLUGIN_WIDGET_CALENDAR . '/img_pack/calendar.css" type="text/css" />'. "\n";
156
157                // les noms de mois et de jour selon les fichiers de langue :
158                $months_long = "";
159                $months_short = "";
160                for ($j=1;$j<=12;$j++){
161                        $nom = entites_html(ucfirst(strtr(_T("spip:date_mois_$j"),$trans_tbl)));
162                        $months_long .= ",'".unicode2charset(charset2unicode($nom,''))."'";
163                        $months_short .= ",'".unicode2charset(charset2unicode(preg_replace("/^((&#x?[0-9]{2,5};|.){0,3}).*$/i","\\1",$nom),''))."'";
164                }
165                $months_long = substr($months_long,1);
166                $months_short = substr($months_short,1);
167
168                $days_long = "";
169                $days_medium = "";
170                $days_short = "";
171                $days_1char = "";
172                for ($j=1;$j<=7;$j++){
173                        $nom = entites_html(ucfirst(strtr(_T("spip:date_jour_$j"),$trans_tbl)));
174                        $days_long .= ",'".$nom."'";
175                        $days_medium .= ",'".preg_replace("/^((&#x?[0-9]{2,5};|.){0,3}).*$/i","\\1",$nom)."'";
176                        $days_short .= ",'".preg_replace("/^((&#x?[0-9]{2,5};|.){0,2}).*$/i","\\1",$nom)."'";
177                        $days_1char .= ",'".preg_replace("/^((&#x?[0-9]{2,5};|.){0,1}).*$/i","\\1",$nom)."'";
178                }
179                $days_long = substr($days_long,1);
180                $days_medium = substr($days_medium,1);
181                $days_short = substr($days_short,1);
182                $days_1char = substr($days_1char,1);
183                $start_weekday = 1;
184                $img_arrow_left = _DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/callt.gif";
185                $img_arrow_right = _DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/calrt.gif";
186                $img_close = _DIR_PLUGIN_WIDGET_CALENDAR."/img_pack/calx.gif";
187
188
189        // le JS dynamique d'init
190        $flux .= "<script language='javascript'>";
191
192        // partie fonction de la langue
193        $js = "";
194
195        $js .= "       
196                SPIP.widget.Calendar2up_INT_Cal.prototype.customConfig = function() {
197                        this.Config.Locale.MONTHS_SHORT = [$months_short];
198                        this.Config.Locale.MONTHS_LONG = [$months_long];
199                        this.Config.Locale.WEEKDAYS_1CHAR = [$days_1char];
200                        this.Config.Locale.WEEKDAYS_SHORT = [$days_short];
201                        this.Config.Locale.WEEKDAYS_MEDIUM = [$days_medium];
202                        this.Config.Locale.WEEKDAYS_LONG = [$days_long];
203               
204                        this.Config.Options.START_WEEKDAY = $start_weekday;
205                        this.Config.Options.NAV_ARROW_LEFT = '$img_arrow_left';
206                        this.Config.Options.NAV_ARROW_RIGHT = '$img_arrow_right';
207                        this.Config.Options.IMG_CLOSE = '$img_close';
208                        this.Config.Options.IMG_CLOSE_CLASS = 'close-icon-$spip_lang_right';
209                }
210                ";
211
212        $js .= "       
213                SPIP.widget.Calendar2up_INT_Cal_multi.prototype.customConfig = function() {
214                        this.Config.Locale.MONTHS_SHORT = [$months_short];
215                        this.Config.Locale.MONTHS_LONG = [$months_long];
216                        this.Config.Locale.WEEKDAYS_1CHAR = [$days_1char];
217                        this.Config.Locale.WEEKDAYS_SHORT = [$days_short];
218                        this.Config.Locale.WEEKDAYS_MEDIUM = [$days_medium];
219                        this.Config.Locale.WEEKDAYS_LONG = [$days_long];
220               
221                        this.Config.Options.START_WEEKDAY = $start_weekday;
222                        this.Config.Options.NAV_ARROW_LEFT = '$img_arrow_left';
223                        this.Config.Options.NAV_ARROW_RIGHT = '$img_arrow_right';
224                        this.Config.Options.MULTI_SELECT = true;
225                }
226                ";
227       
228                // construire les variables et fonctions de mise a jour
229
230                $vars = "";
231                $js_a= "";     
232                $js_b= "";     
233                $js_c= "";     
234                $liste_suffixes = array();
235                foreach ($WCalendar_statiques as  $infos){
236                        $s = $infos['suffixe'];
237                        $t = $infos['titre'];
238                        list($v,$a,$b,$c) = WCalendar_statique_jsinit($t, $s);
239                        $vars .= $v; $js_a .= $a; $js_b .= $b;$js_c .= $c;
240                }
241                foreach ($WCalendar_independants as  $infos){
242                        $s = $infos['suffixe'];
243                        $t = $infos['titre'];
244                        list($v,$a,$b,$c) = WCalendar_jsinit($t, $s);
245                        $vars .= $v; $js_a .= $a; $js_b .= $b;$js_c .= $c;
246                }
247                foreach ($WCalendar_lies as  $infos){
248                        $s = $infos['suffixe1'];
249                        $t = $infos['titre1'];
250                        list($v,$a,$b,$c) = WCalendar_jsinit($t, $s);
251                        $vars .= $v; $js_a .= $a; $js_b .= $b;$js_c .= $c;
252
253                        $s = $infos['suffixe2'];
254                        $t = $infos['titre2'];
255                        list($v,$a,$b,$c) = WCalendar_jsinit($t, $s);
256                        $vars .= $v; $js_a .= $a; $js_b .= $b;$js_c .= $c;
257                }
258                global $init_functions;
259                $js .= "
260                $vars
261                function hideall(){
262                        $js_a
263                }
264                function init() {
265                        $init_functions
266                        $js_b
267                }
268               
269                $js_c
270                ";
271                foreach ($WCalendar_independants as  $infos){
272                        $s = $infos['suffixe'];
273                        $js .= Wcalendar_js_set_change_date($s);
274                }
275
276                foreach ($WCalendar_lies as  $infos){
277                        $sd = $infos['suffixe1'];
278                        $sf = $infos['suffixe2'];
279                        $js .= WCalendar_js_verifie_lies($sd,$sf);
280                        $js .= Wcalendar_js_set_change_date($sd,$sd,$sf,1);
281                        $js .= Wcalendar_js_set_change_date($sf,$sd,$sf,2);
282                }
283               
284                $js .= "
285        </script>";
286                $flux .= $js;
287        }
288        return $flux;
289}
290
291?>
Note: See TracBrowser for help on using the repository browser.