autoup.php 10.6 KB
Newer Older
Ayolo's avatar
Ayolo committed
1 2 3
<?php
$topdir="../";
require_once("include/sas.inc.php");
mbriand's avatar
mbriand committed
4
require_once($topdir. "include/entities/asso.inc.php");
5 6
require_once($topdir . "include/taiste.inc.php");

Ayolo's avatar
Ayolo committed
7 8
$site = new sas();

Feu's avatar
Feu committed
9
if ( $_REQUEST["act"] == "Info" )
Ayolo's avatar
Ayolo committed
10 11 12 13 14
{
  echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  echo "<!DOCTYPE UBPTExchange>\n";
  echo "<info>\n";
  echo "  <name>Stock à Souvenirs (v2)</name>\n";
15
  echo "  <url>http://ae.utbm.fr". $GLOBALS["wwwtopdir"]."sas2/</url>\n";
Ayolo's avatar
Ayolo committed
16 17 18 19 20 21 22 23 24 25 26
  echo "  <message>(none)</message>\n";
  echo "  <domains>\n";
  echo "    <domain>utbm.fr</domain>\n";
  echo "    <domain>assidu-utbm.fr</domain>\n";
  echo "    <domain>id</domain>\n";
  echo "    <domain>autre</domain>\n";
  echo "  </domains>\n";
  echo "</info>\n";
  exit();
} else if ( $_REQUEST["act"] == "Connect" ) {

Feu's avatar
Feu committed
27 28
  echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  echo "<!DOCTYPE UBPTExchange>\n";
Ayolo's avatar
Ayolo committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
  echo "<session>\n";

  $CVersion = explode(".",$_REQUEST["ClientVersion"]);
  if ( ( $CVersion[1] < 6 ) )
    echo "  <update/>\n";
  else
  {
    switch ($_REQUEST["Domain"])
    {
      case 0 :
        $site->user->load_by_email($_REQUEST["UserName"]."@utbm.fr");
      break;
      case 1 :
        $site->user->load_by_email($_REQUEST["UserName"]."@assidu-utbm.fr");
      break;
      case 2 :
        $site->user->load_by_id($_REQUEST["UserName"]);
      break;
      case 3 :
        $site->user->load_by_email($_REQUEST["UserName"]);
      break;
      default :
        $site->user->load_by_email($_REQUEST["UserName"]."@utbm.fr");
      break;
    }

    if ( $site->user->id != -1 && $site->user->hash == "valid" && $site->user->is_password($_POST["PassWord"]) )
mbriand's avatar
mbriand committed
56
    {
Ayolo's avatar
Ayolo committed
57
      echo "  <sessionid>".$site->connect_user()."</sessionid>\n";
mbriand's avatar
mbriand committed
58 59
      echo "  <userid>".$site->user->id."</userid>\n";
    }
Ayolo's avatar
Ayolo committed
60 61 62 63 64 65 66 67 68 69 70 71
    else
      echo "  <error/>\n";
  }

  echo "</session>\n";

  exit();

}

$site->load_session($_REQUEST["SessionId"]);

Feu's avatar
Feu committed
72 73 74 75 76 77 78
if ( $_REQUEST["act"] != "DownloadPhoto" )
{
  echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  echo "<!DOCTYPE UBPTExchange>\n";
}

if ( !$site->user->is_valid() )
Ayolo's avatar
Ayolo committed
79 80 81 82 83 84
{
  echo "<error>SESSION_NECESSAIRE</error>\n";
  exit();
}
elseif ( $_REQUEST["act"] == "FetchContexts" )
{
Feu's avatar
Feu committed
85 86 87 88
  function get_short_semestre ($t)
  {
    $y = date("Y",$t);
    $m = date("m",$t);
89

Feu's avatar
Feu committed
90
    if ( $m >= 2 && $m < 9)
Ayolo's avatar
bleh  
Ayolo committed
91
      return "P".$y;
Feu's avatar
Feu committed
92
    else if ( $m >= 9 )
Ayolo's avatar
bleh  
Ayolo committed
93
      return "A".$y;
Feu's avatar
Feu committed
94
    else
Ayolo's avatar
bleh  
Ayolo committed
95
      return "A".($y-1);
Feu's avatar
Feu committed
96
  }
Ayolo's avatar
Ayolo committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  //
  $grps = $site->user->get_groups_csv();

  $req = new requete($site->db,"SELECT * " .
        "FROM sas_cat_photos " .
        "WHERE " .
        "((droits_acces_catph & 0x1) OR " .
        "((droits_acces_catph & 0x10) AND id_groupe IN ($grps)) OR " .
        "(id_groupe_admin IN ($grps)) OR " .
        "((droits_acces_catph & 0x100) AND id_utilisateur='".$site->user->id."')) " .
        "ORDER BY `id_catph_parent`,`date_debut_catph` DESC,`nom_catph`");


  echo "<contexts>\n";

  require_once($topdir."include/entities/group.inc.php");
  $groups=enumerates_groups($site->db);

Feu's avatar
Feu committed
115 116 117 118
  while ( $row = $req->get_row() )
  {
    if ( $row['date_debut_catph'] )
      $row["nom_catph"] .= " (".get_short_semestre(strtotime($row["date_debut_catph"])).")";
119

Ayolo's avatar
Ayolo committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
    echo "  <context>";
    echo "    <name>".htmlspecialchars($row["nom_catph"])."</name>\n";
    echo "    <id>".$row["id_catph"]."</id>\n";
    echo "    <idparent>".(!$row["id_catph_parent"]?0:$row["id_catph_parent"])."</idparent>\n";
    echo "    <group gid=\"".$row["id_groupe"]."\">".$groups[$row["id_groupe"]]."</group>\n";
    echo "    <rights>".$row["droits_acces_catph"]."</rights>\n";
    echo "  </context>";
  }

  echo "</contexts>\n";

  exit();
}
elseif ( $_REQUEST["act"] == "FetchUserGroups" )
{
  echo "<groups>\n";

Feu's avatar
debug  
Feu committed
137
  $groups=enumerates_groups($site->db);
Ayolo's avatar
Ayolo committed
138

Feu's avatar
debug  
Feu committed
139
  foreach ( $groups as $gid => $Group )
Ayolo's avatar
Ayolo committed
140 141 142 143 144
    echo "  <group gid=\"$gid\">$Group</group>";

  echo "</groups>\n";
  exit();
}
mbriand's avatar
mbriand committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
elseif ( $_REQUEST["act"] == "FetchClubs" )
{
  $asso = new asso($site->db);
  echo "<clubs>\n";

  $clubs=$asso->enumerate();

  foreach ( $clubs as $gid => $club )
    echo "  <club gid=\"$gid\">$club</club>";

  echo "</clubs>\n";
  exit();
}
elseif ( $_REQUEST["act"] == "FetchLicences" )
{
mbriand's avatar
mbriand committed
160
  $licence = new licence($site->db);
mbriand's avatar
mbriand committed
161 162 163 164 165 166 167 168 169 170
  echo "<licences>\n";

  $licences=$licence->enumerate();

  foreach ( $licences as $gid => $licence )
    echo "  <licence gid=\"$gid\">$licence</licence>";

  echo "</licences>\n";
  exit();
}
Ayolo's avatar
Ayolo committed
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
elseif ( $_REQUEST["act"] == "UploadImage" )
{
  require_once($topdir."include/entities/group.inc.php");
  $groups=enumerates_groups($site->db);


  $photo = new photo($site->db,$site->dbrw);
  $cat = new catphoto($site->db,$site->dbrw);

  $cat->load_by_id($_REQUEST["ContextId"]);
  if ( $cat->id < 1 ) {
    echo "<error>8</error>\n";
    exit();
  }

  if ( !$cat->is_right($site->user,DROIT_AJOUTITEM) ) {
    echo "<error>9</error>\n";
    exit();
  }

  if ( is_uploaded_file($_FILES['imageFile']['tmp_name']) && ($_FILES['imageFile']['error'] == UPLOAD_ERR_OK) )
  {
    $photo->herit($cat,false);

    $gids = array_keys($groups, $_REQUEST["Group"]);
    $id_group=$gids[0];

    $photo->set_rights($site->user,$_REQUEST["Rights"] & 0x333,$id_group,$cat->id_groupe_admin,false);

Ayolo's avatar
bleh  
Ayolo committed
200 201
    if(isset($_REQUEST['id_licence']))
    {
mbriand's avatar
mbriand committed
202 203
      require_once('include/licence.inc.php');
      $licence=new licence($site->db);
Ayolo's avatar
bleh  
Ayolo committed
204
      if($licence->load_by_id($_REQUEST['id_licence']))
Ayolo's avatar
bleh  
Ayolo committed
205 206 207 208 209 210 211
        $licence=$licence->id;
      else
        $licence=$site->user->id_licence_default_sas;
    }
    else
      $licence=$site->user->id_licence_default_sas;

mbriand's avatar
mbriand committed
212 213 214 215 216 217 218 219
    $photographer = new utilisateur($site->db);
    if (isset($_REQUEST['PhotographerUserId']))
      $photographer->load_by_id($_REQUEST['PhotographerUserId']);

    $photographer_asso = new asso($site->db);
    if (isset($_REQUEST['AssoId']))
      $photographer_asso->load_by_id($_REQUEST['AssoId']);

Ayolo's avatar
bleh  
Ayolo committed
220 221
    $photo->add_photo ( $_FILES['imageFile']['tmp_name'],
                        $cat->id,
mbriand's avatar
mbriand committed
222 223
                        isset($_REQUEST['Comment']) ? $_REQUEST['Comment'] : "",
                        $photographer->is_valid() ? $photographer->id : NULL,
Ayolo's avatar
bleh  
Ayolo committed
224
                        false,
Ayolo's avatar
bleh  
Ayolo committed
225
                        $cat->meta_id_asso,
Ayolo's avatar
bleh  
Ayolo committed
226
                        NULL,
mbriand's avatar
mbriand committed
227
                        $photographer_asso->is_valid() ? $photographer_asso->id : NULL,
Ayolo's avatar
bleh  
Ayolo committed
228
                        $licence);
Ayolo's avatar
Ayolo committed
229 230 231 232 233 234 235

    echo "<error>0</error>\n";

  }
  else
    echo "<error>1</error>\n";
  exit();
236

Ayolo's avatar
Ayolo committed
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
}
elseif ( $_REQUEST["act"] == "UploadVideoFLV" )
{
/*
 * La conversion de la video se fera coté client (par ubpttr v2.2)
 */
  require_once($topdir."include/entities/group.inc.php");
  $groups=enumerates_groups($site->db);


  $photo = new photo($site->db,$site->dbrw);
  $cat = new catphoto($site->db,$site->dbrw);

  $cat->load_by_id($_REQUEST["ContextId"]);
  if ( $cat->id < 1 ) {
    echo "<error>8</error>\n";
    exit();
  }

  if ( !$cat->is_right($site->user,DROIT_AJOUTITEM) ) {
    echo "<error>9</error>\n";
    exit();
  }

  if ( is_uploaded_file($_FILES['imageFile']['tmp_name']) && ($_FILES['imageFile']['error'] == UPLOAD_ERR_OK) &&
      is_uploaded_file($_FILES['flvFile']['tmp_name']) && ($_FILES['flvFile']['error'] == UPLOAD_ERR_OK) )
  {
    $photo->herit($cat,false);

    $gids = array_keys($groups, $_REQUEST["Group"]);
    $id_group=$gids[0];

    $photo->set_rights($site->user,$_REQUEST["Rights"] & 0x333,$id_group,$cat->id_groupe_admin,false);

mbriand's avatar
mbriand committed
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
    if(isset($_REQUEST['id_licence']))
    {
      require_once('include/licence.inc.php');
      $licence=new licence($site->db);
      if($licence->load_by_id($_REQUEST['id_licence']))
        $licence=$licence->id;
      else
        $licence=$site->user->id_licence_default_sas;
    }
    else
      $licence=$site->user->id_licence_default_sas;

    $photographer = new utilisateur($site->db);
    if (isset($_REQUEST['PhotographerUserId']))
      $photographer->load_by_id($_REQUEST['PhotographerUserId']);

    $photographer_asso = new asso($site->db);
    if (isset($_REQUEST['AssoId']))
      $photographer_asso->load_by_id($_REQUEST['AssoId']);

    $photo->add_videoflv ( $_FILES['imageFile']['tmp_name'],
                            $_FILES['flvFile']['tmp_name'],
                            $cat->id,
                            isset($_REQUEST['Comment']) ? $_REQUEST['Comment'] : "",
                            $photographer->is_valid() ? $photographer->id : NULL,
                            false,
                            $cat->meta_id_asso,
                            NULL,
Bate's avatar
Bate committed
299
                            $photographer_asso->is_valid() ? $photographer_asso->id : NULL,
mbriand's avatar
mbriand committed
300
                            $licence);
Ayolo's avatar
Ayolo committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389

    echo "<error>0</error>\n";

  }
  else
    echo "<error>1</error>\n";
  exit();
}
elseif ( $_REQUEST["act"] == "Fetch" )
{ // L'objectif est de tout lister, mais en reduisant le plus possible la taille du xml produit

  $grps = $site->user->get_groups_csv();

  session_write_close();

  function reformat_date($date)
  {
    if(is_null($date))return"";
    if ($date=="1969-12-31 23:59:59") return"";
    if ($date=="1970-01-01 00:59:59") return"";
    if ($date=="1970-01-01 00:59:59") return"";
    return date("YmdHi",strtotime($date));

  }

  function fetch ( $cat )
  {
    global $site,$grps;
    $req = $cat->get_categories ( $cat->id, $site->user, $grps);
    $scat = new catphoto($site->db);
    while ( $row = $req->get_row() )
    {
      $scat->_load($row);
      echo "<c i=\"".$row["id_catph"]."\" n=\"".str_replace('"',"",$row["nom_catph"])."\" d=\"".reformat_date($row["date_debut_catph"])."\" f=\"".reformat_date($row["date_fin_catph"])."\">\n";
      fetch($scat);
      echo "</c>\n";
    }
    $req = $cat->get_photos ( $cat->id, $site->user, $grps);
    while ( $row = $req->get_row() )
    {
      echo "<i i=\"".$row["id_photo"]."\" d=\"".reformat_date($row["date_prise_vue"])."\" />\n";
    }
  }
  $cat = new catphoto($site->db);
  echo "<c>\n";
  $cat->load_by_id(1);
  fetch($cat);
  echo "</c>\n";
  exit();
}
elseif ( $_REQUEST["act"] == "DownloadPhoto" )
{
  session_write_close();

  $photo = new photo($site->db);
  $photo->load_by_id($_REQUEST["id_photo"]);

  if ( $photo->id < 1 || !$photo->is_right($site->user,DROIT_LECTURE) )
    exit();


  $abs_file = $photo->get_abs_path().$photo->id;

  if ( $_REQUEST["mode"] == "diapo" )
    $abs_file.=".diapo.jpg";
  else
    $abs_file.=".jpg";

  header("Content-type: image/jpeg");
  header("Content-Length: ".filesize($abs_file));
  readfile($abs_file);

  exit();
}
elseif ( $_REQUEST["act"] == "CheckSession" )
{
  echo "<session>\n";
  $CVersion = explode(".",$_REQUEST["ClientVersion"]);
  if ( ( $CVersion[1] < 6 ) )
    echo "  <update/>\n";
  else
    echo "  <sessionid>".$_REQUEST["SessionId"]."</sessionid>\n";
  echo "</session>\n";
  exit();
}
echo "<error>NON_DEFINI</error>\n";


?>