source: branches/rsr.v5.1.dev/web/app/out/dist/utils.php @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 5.4 KB
Line 
1<?php
2
3  function url_amps($url)
4  { return str_replace("&", "&amp;", $url);
5  }
6
7  function navig($current, $total, $max, $base_url, $start_param, $legende = null)
8  { $navig = "";
9    if($total > $max)
10    { if(isset($legende))
11          { $navig .=
12             $legende." ".($current + 1)." &agrave; "
13            .(($current + $max) > $total ? $total : $current + $max)
14                ." sur ".$total." - aller &agrave; la ";
15          }
16          $get_params = array();
17      if(($q = strpos($base_url, "?")) !== false)
18          { $v_query = explode("&", substr($base_url, $q + 1));
19        $base_url = substr($base_url, 0, $q);
20        foreach($v_query as $query)
21        { if($query)
22                  { $v = explode("=", $query);
23            $get_params[$v[0]] = $v[1];
24          }
25        }
26          }
27      if(isset($get_params[$start_param])) unset($get_params[$start_param]);
28      $base_url .= "?";
29      foreach($get_params as $key => $value) $base_url .= $key."=".$value."&";
30          $nb_pages = ceil($total / $max);
31          $navig .=
32           "page : "
33          ."<select onchange=\"document.location=this.options[this.selectedIndex].value;\">\n";
34      $np = 1;
35      $ni = 0;
36      while($ni < $total)
37          { $navig .=
38         "  <option value=\"".$base_url.$start_param."=".$ni."\"".($current >= $ni && $current <= $ni ? " SELECTED" : "").">"
39                .$np
40                ."</option>\n";
41        $np++;
42        $ni += $max;
43          }
44      $navig .=
45           "</select>\n";
46      if($current >= $max)
47          { $navig .=
48          "&nbsp;&nbsp;<a href=\"".$base_url.$start_param."=".($current - $max)."\">&lt;&lt;</a>\n";
49          }
50      if($current < $total - $max)
51          { $navig .=
52          "&nbsp;&nbsp;<a href=\"".$base_url.$start_param."=".($current + $max)."\">&gt;&gt;</a>\n";
53          }
54        }
55    return $navig;
56  }
57
58  function order_link($env, $text, $order_by, $base_url)
59  { $get_params = array();
60    if(($q = strpos($base_url, "?")) !== false)
61        { $v_query = explode("&", substr($base_url, $q + 1));
62      $base_url = substr($base_url, 0, $q);
63      foreach($v_query as $query)
64      { if($query)
65            { $v = explode("=", $query);
66          $get_params[$v[0]] = $v[1];
67        }
68      }
69    }
70    if(isset($get_params[$env->param("order_by")])) unset($get_params[$env->param("order_by")]);
71    if(isset($get_params[$env->param("order")])) unset($get_params[$env->param("order")]);
72    $base_url .= "?";
73    foreach($get_params as $key => $value) $base_url .= $key."=".$value."&";
74    if(substr($base_url, -1) === "&") $base_url = substr($base_url, 0, -1);
75    $order_params = "";
76    $order_img = "";
77        if($order_by === $env->order_by)
78    { if($env->order === "ASC")
79      { $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=DESC";
80        $order_img = "<img src=\"icons/asc.gif\" >";
81          }
82      elseif($env->order === "DESC")
83          { $order_img = "<img src=\"icons/desc.gif\" >";
84          }
85        }
86        else
87        { $order_params = $env->param("order_by")."=".$order_by."&".$env->param("order")."=ASC";
88        }
89    return "<a href=\"".$base_url.($order_params ? "&".$order_params : "")."\">".$text."</a>&nbsp;".$order_img;
90  }
91
92  function is_date($date)
93  { return ereg("^[0-9][0-9][0-9][0-9]-[0-9]{1,2}-[0-9]{1,2}$", $date);
94  }
95
96  function is_num($num)
97  { $num = str_replace(array(",", " "), array(".", ""), $num);
98    $v_num = explode(".", $num);
99    if(count($v_num) > 2) return false;
100    $OK = true;
101        for($n = 0; $n < count($v_num) && $OK; $n++) $OK = ereg("^[0-9]+$", $v_num[$n]);
102    return $OK ? $num : false;
103  }
104
105  function date_texte($moment)
106  { $moment = explode("-", $moment);
107    return jour_semaine($moment[0], $moment[1], $moment[2])." ".(0 + $moment[0])." ".mois(0 + $moment[1])." ".$moment[2];
108  }
109
110  function jour_semaine($jour, $mois, $annee)
111  { switch(date("N", mktime(1, 0, 0, 0 + $mois, 0 + $jour, 0 + $annee)))
112    { case 1: return "lundi";
113      case 2: return "mardi";
114      case 3: return "mercredi";
115      case 4: return "jeudi";
116      case 5: return "vendredi";
117      case 6: return "samedi";
118      case 7: return "dimanche";
119        }
120  }
121
122  function mois($mois)
123  { switch($mois)
124    { case 1:  return "janvier";
125      case 2:  return "fevrier";
126      case 3:  return "mars";
127      case 4:  return "avril";
128      case 5:  return "mai";
129      case 6:  return "juin";
130      case 7:  return "juillet";
131      case 8:  return "ao&ucirc;t";
132      case 9:  return "septembre";
133      case 10: return "octobre";
134      case 11: return "novembre";
135      case 12: return "decembre";
136        }
137        return "?";
138  }
139
140  function resume($content, $n)
141  { if($n)
142    { $v_content = explode(" ", $content);
143      if(count($v_content) > $n)
144      { $_content = "";
145        for($i = 0; $i <= $n; $i++) $_content .= $v_content[$i]." ";
146                return $_content." (...)";
147          }
148    }
149    return $content;
150  }
151
152  function js_str($content)
153  { return str_replace
154    ( array("\"", "\r", "\n"),
155      array("\\\"", "\\r", "\\n"),
156      $content
157        );
158  }
159
160  function js_str_nocrlf($content)
161  { return str_replace
162    ( array("\"", "\r", "\n"),
163      array("\\\"", " ", " "),
164      $content
165        );
166  }
167
168  function img_size($file, $max_width, $max_height)
169  { $img_infos = @getimagesize($file);
170    $img_size = array();
171    if($img_infos)
172    { if($img_infos[0] > $max_width || $img_infos[1] > $max_height)
173      { $r = $max_width / $img_infos[0];
174        if($r * $img_infos[1] > $max_height) $r = $max_height / $img_infos[1];
175        return array
176        ( "width" => floor($r * $img_infos[0]),
177          "height" => floor($r * $img_infos[1]) 
178        );
179      }
180      return array
181      ( "width" => $img_infos[0],
182        "height" => $img_infos[1] 
183      );
184    }
185    return false;
186  }
187
188?>
Note: See TracBrowser for help on using the repository browser.