gateway.php 9.82 KB
Newer Older
ayolo's avatar
bleh  
ayolo committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
/* Copyright 2009
 *
 * Ce fichier est adapté du site de l'association des étudiants de
 * l'UTBM, http://ae.utbm.fr.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License a
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

$topdir = "./";
require_once($topdir. "include/site.inc.php");
$site = new site();

if ( isset($_REQUEST['topdir']) && ($_REQUEST['topdir']=="./" || $_REQUEST['topdir'] =="../" || $_REQUEST['topdir'] =="./../") )
  $wwwtopdir = $_REQUEST['topdir'];

ayolo's avatar
bleh  
ayolo committed
30
if ( $_REQUEST['module']=="userfield" )
ayolo's avatar
bleh  
ayolo committed
31
{
ayolo's avatar
bleh  
ayolo committed
32 33
  if ( !$site->user->is_valid() )
    exit();
ayolo's avatar
bleh  
ayolo committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

  $pattern = mysql_real_escape_string($_REQUEST["pattern"]);

  $pattern = ereg_replace("(e|é|è|ê|ë|É|È|Ê|Ë)","(e|é|è|ê|ë|É|È|Ê|Ë)",$pattern);
  $pattern = ereg_replace("(a|à|â|ä|À|Â|Ä)","(a|à|â|ä|À|Â|Ä)",$pattern);
  $pattern = ereg_replace("(i|ï|î|Ï|Î)","(i|ï|î|Ï|Î)",$pattern);
  $pattern = ereg_replace("(c|ç|Ç)","(c|ç|Ç)",$pattern);
  $pattern = ereg_replace("(o|O|ò|Ò|ô|Ô)","(o|O|ò|Ò|ô|Ô)",$pattern);
  $pattern = ereg_replace("(u|ù|ü|û|Ü|Û|Ù)","(u|ù|ü|û|Ü|Û|Ù)",$pattern);
  $pattern = ereg_replace("(n|ñ|Ñ)","(n|ñ|Ñ)",$pattern);

  $req = new requete($site->db,
    "SELECT `id_utilisateur`,CONCAT(`prenom_utl`,' ',`nom_utl`) " .
    "FROM `utilisateurs` " .
    "WHERE CONCAT(`prenom_utl`,' ',`nom_utl`) REGEXP '^".$pattern."' " .
    "UNION SELECT `id_utilisateur`,CONCAT(`nom_utl`,' ',`prenom_utl`) " .
    "FROM `utilisateurs` " .
    "WHERE CONCAT(`nom_utl`,' ',`prenom_utl`) REGEXP '^".$pattern."' " .
ayolo's avatar
bleh  
ayolo committed
52
    "ORDER BY 2 LIMIT 10");
ayolo's avatar
bleh  
ayolo committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

  if ( !$req || $req->errno != 0) // Si l'expression régulière envoyée par l'utilisateur est invalide, on évite l'erreur mysql
  {
    echo "<ul>\n";
    echo "<li>Recherche invalide.</li>\n";
    echo "</ul>\n";
    echo "<div class=\"clearboth\"></div>";
    exit();
  }


  echo "<ul>\n";

  while ( list($id,$email) = $req->get_row() )
  {
    echo "<li><div class=\"imguser\"><img src=\"";

ayolo's avatar
bleh  
ayolo committed
70 71 72 73
    if (file_exists($topdir."var/img/profil/".$id.".jpg"))
      echo $wwwtopdir."var/img/profil/".$id.".jpg";
    elseif (file_exists($topdir."var/img/profl/".$id.".jpg"))
      echo $wwwtopdir."var/img/profil/".$id.".jpg";
ayolo's avatar
bleh  
ayolo committed
74
    else
ayolo's avatar
bleh  
ayolo committed
75
      echo $wwwtopdir."images/icons/48/na.png";
ayolo's avatar
bleh  
ayolo committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    echo "\" /></div><a href=\"#\" onclick=\"userselect_set_user('$wwwtopdir','".$_REQUEST["ref"]."',$id,'".addslashes(htmlspecialchars($email))."'); return false;\">".htmlspecialchars($email)."</a></li>\n";
  }
  echo "</ul>\n";
  echo "<div class=\"clearboth\"></div>";
  exit();
}
elseif ( $_REQUEST['module']=="userinfo" )
{
  if ( !$site->user->is_valid() && !count($_SESSION["Comptoirs"])) exit();

  $user = new utilisateur($site->db,$site->dbrw);
  $user->load_by_id($_REQUEST["id_utilisateur"]);
  if ( $user->id < 0 )
    $user = &$site->user;

ayolo's avatar
bleh  
ayolo committed
92 93
  if (file_exists($topdir."var/img/profil/".$user->id.".jpg"))
    echo "<img src=\"".$wwwtopdir."var/img/profil/".$user->id.".jpg\" alt=\"\" />\n";
ayolo's avatar
bleh  
ayolo committed
94
  else
ayolo's avatar
bleh  
ayolo committed
95
    echo "<img src=\"".$wwwtopdir."images/icons/48/na.png"."\" alt=\"\" />\n";
ayolo's avatar
bleh  
ayolo committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310

  echo "<p class=\"nomprenom\">". $user->prenom . " " . $user->nom . "</p>";
  if ( $user->surnom )
    echo "<p class=\"surnom\">'' ". $user->surnom . " ''</p>";
  echo "<div class=\"clearboth\"></div>";
  exit();
}
elseif ( $_REQUEST['module']=="entinfo" )
{
  $class = $_REQUEST['class'];

  if ( class_exists($class) )
    $std = new $class($site->db);

  elseif ( isset($GLOBALS["entitiescatalog"][$class][5]) && $GLOBALS["entitiescatalog"][$class][5] )
  {
    include($topdir."include/entities/".$GLOBALS["entitiescatalog"][$class][5]);
    if ( class_exists($class) )
      $std = new $class($site->db);
  }

  $std->load_by_id($_REQUEST['id']);

  if ( !$std->is_valid() )
  {
    echo "?";
    exit();
  }

  if ( !$std->allow_user_consult($site->user) )
    exit();

  if ( $std->can_preview() )
    echo "<p class=\"stdpreview\"><img src=\"".$wwwtopdir.$std->get_preview()."\" alt=\"".htmlentities($std->get_display_name(),ENT_COMPAT,"UTF-8")."\" /></p>";

  echo "<p class=\"stdinfo\">".$std->get_html_extended_info()."</p>";
  echo "<div class=\"clearboth\"></div>";
  exit();

}
elseif ( $_REQUEST['module']=="entdesc" )
{
  $class = $_REQUEST['class'];

  if ( class_exists($class) )
    $std = new $class($site->db);

  elseif ( isset($GLOBALS["entitiescatalog"][$class][5]) && $GLOBALS["entitiescatalog"][$class][5] )
  {
    include($topdir."include/entities/".$GLOBALS["entitiescatalog"][$class][5]);
    if ( class_exists($class) )
      $std = new $class($site->db);
  }

  $std->load_by_id($_REQUEST['id']);

  if ( !$std->is_valid() )
  {
    echo "?";
    exit();
  }

  if ( !$std->allow_user_consult($site->user) )
    exit();

  echo htmlentities($std->get_description(),ENT_NOQUOTES,"UTF-8");

  exit();
}
elseif ( $_REQUEST['module']=="fsfield" )
{
  $class = $_REQUEST['class'];
  $field = $_REQUEST['field'];


  if ( !ereg("^([a-z0-9]*)$",$class) )
    exit();

  $std = null;

  if ( class_exists($class) )
    $std = new $class($site->db);

  elseif ( isset($GLOBALS["entitiescatalog"][$class][5]) && $GLOBALS["entitiescatalog"][$class][5] )
  {
    include($topdir."include/entities/".$GLOBALS["entitiescatalog"][$class][5]);
    if ( class_exists($class) )
      $std = new $class($site->db);
  }

  if ( is_null($std) )
    exit();

  if ( !$std->can_fsearch() )
    exit();

  if ( !$std->allow_user_consult($site->user) )
    exit();

  if ( $_REQUEST['pattern'] != "" )
  {
    $conds=array();
    if(isset($_REQUEST['conds']) && !empty($_REQUEST['conds']) && is_array($_REQUEST['conds']))
      $conds=$_REQUEST['conds'];
    $res = $std->fsearch ( $_REQUEST['pattern'], 6 , $conds);
    if ( !is_null($res) )
    {
      $buffer = "<ul class=\"fsfield_list\">";
      foreach ( $res as $id => $name )
      {
        $buffer .= "<li>";

        $std->id = $id;
        if ( $std->can_preview() )
        {
          $img = $std->get_preview();
          if ( !is_null($img) )
            $buffer .= "<div class=\"imguser\"><img src=\"".$wwwtopdir.$img."\" /></div>";
        }

        $buffer .= "<a href=\"#\" onclick=\"fsfield_sel('$wwwtopdir','$field',$id,'".addslashes(htmlspecialchars($name))."','".$GLOBALS["entitiescatalog"][$class][2]."'); return false;\">";
        $buffer .= htmlspecialchars($name);
        $buffer .= "</a>";
        $buffer .= "</li>";
      }
      $buffer .=  "</ul>";
      $buffer .=  "<div class=\"clearboth\"></div>";
    }
    else
      $buffer="<p class=\"error\">Requête invalide</p>";
  }
  else
    $buffer="";

  echo "if ( ".$_REQUEST['sequence']." > fsfield_current_sequence['".$field."'] )\n{\n";
  echo "  fsfield_current_sequence['".$field."']=".$_REQUEST['sequence'].";\n";
  echo "  var content = document.getElementById('".$field."_result');\n";
  echo "  content.style.zIndex = 100000;\n";
  echo "  content.style.display = 'block';\n";
  echo "  content.innerHTML ='".addslashes($buffer)."';\n";
  echo "}\n";

  exit();
}
elseif ( $_REQUEST['module']=="exfield" )
{
  $class = $_REQUEST['class'];
  $field = $_REQUEST['field'];
  $eclass = $_REQUEST['eclass'];

  if ( !ereg("^([a-z0-9]*)$",$class) || !ereg("^([a-z0-9]*)$",$class) )
    exit();

  $std = null;

  if ( class_exists($eclass) )
    $std = new $eclass($site->db);

  elseif ( isset($GLOBALS["entitiescatalog"][$eclass][5]) && $GLOBALS["entitiescatalog"][$eclass][5] )
  {
    include($topdir."include/entities/".$GLOBALS["entitiescatalog"][$eclass][5]);
    if ( class_exists($eclass) )
      $std = new $eclass($site->db);
  }

  if ( is_null($std) )
    exit();

  if ( $_REQUEST['eid'] == "root" )
  {
    $std = $std->get_root_element();
    if ( is_null($std) )
      exit();
  }
  else
    $std->load_by_id($_REQUEST['eid']);

  if ( !$std->is_valid() )
    exit();

  if ( !$std->allow_user_consult($site->user) )
    exit();

  $childs = $std->get_childs($site->user);

  if ( is_null($childs) || count($childs) == 0 )
    exit();

  foreach ( $childs as $child )
  {
    $name = $child->get_display_name();

    echo "<li>";

    echo "<a href=\"#\" onclick=\"";
    if ( get_class($child) == $class )
      echo "exfield_select('$wwwtopdir','$field','$class','".$child->id."','".addslashes(htmlspecialchars($name))."','".$GLOBALS["entitiescatalog"][$class][2]."');";
    else
      echo "exfield_explore('$wwwtopdir','$field','$class','".get_class($child)."','".$child->id."');";
    echo "return false;\">";

    echo "<img src=\"".$wwwtopdir."images/icons/16/".$GLOBALS["entitiescatalog"][get_class($child)][2]."\" alt=\"\" />";
    echo htmlspecialchars($name);
    echo "</a>";

    echo "<ul id=\"".$field."_".get_class($child)."_".$child->id."\"></ul>";

    echo "</li>";
  }


  exit();
}
elseif( $_REQUEST['module']=="tinycal" )
{
ayolo's avatar
bleh  
ayolo committed
311
  require_once($topdir. "include/cts/calendar.inc.php");
ayolo's avatar
bleh  
ayolo committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
  $cal = new tinycalendar($site->db);
  $cal->set_target($_REQUEST['target']);
  $cal->set_type($_REQUEST['type']);
  $cal->set_ext_topdir($_REQUEST['topdir']);
  echo $cal->html_render();
  exit();
}

if ( $_REQUEST['class'] == "calendar" )
{
  if(isset($_REQUEST['subclass']) && !empty($_REQUEST['subclass']))
    $subclass=$_REQUEST['subclass'];
  else
    $subclass='';
  if(isset($_REQUEST['id_box']) && !empty($_REQUEST['id_box']))
    $cts = new calendar($site->db,null,$subclass,$_REQUEST['id_box']);
  else
    $cts = new calendar($site->db);
}
else
  $cts = new contents();

echo $cts->html_render();
?>