source: trunk/spip/esqueleto-redcta/plugins/widget_calendar/inc/calendar_init.php @ 30

Last change on this file since 30 was 30, checked in by sebas, 17 years ago

nueva importacion del codigo del esqueleto de redcta con los plugins

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