English version  | Version française

Notice: Undefined index: HTTP_REFERER in /home/_or/olivier/pub/www.samalyse.com/prepend.php on line 202

<< Back

<?php

require_once 'Controller/CoreController.php';

/**
 * Handle the edition of the current user's profile
 *
 * @package     Coequipier
 * @subpackage  Controller
 * @author      Olivier Guilyardi <olivier@samalyse.com>
 * @uses        Profile
 * @uses        Geo
 */
class ProfileEdition extends CoreController
{
  var 
$gender '';
  var 
$region '';
  var 
$department '';
  var 
$regionsTree = array();
  var 
$regionsList = array();
  var 
$departmentsList = array();
  var 
$city '';
  var 
$birthDate = array ('year' => '''month' => '''day' => '');
  var 
$situation '';
  var 
$style = array();
  var 
$appearance '';
  var 
$origin = array();
  var 
$hobbies '';
  var 
$hobbiesStatus '';
  var 
$description '';
  var 
$descriptionStatus '';
  var 
$pictureStatus '';
  var 
$picture;
  var 
$process 0;
  var 
$error;
  var 
$_isPictureUploaded false;
  var 
$_pictureExtension '';  
 
  function 
process ()
  {
    
$this->authenticate ();
    require_once 
'Model/Profile.php';
    
$profile = &new Profile ();
    
$picturesFolders Coequipier::option ('pictures_folders');
    if (
$this->process) {
      if (!
$this->error  $this->_check())
      {
        
$profile->load ($this);
        
$previousPicture '';
        if (
$this->_isPictureUploaded)
        {
          
$previousPicture $this->getExistingPendingPicture ();
          
$profile->pictureBasename $this->authUsername '.' .  $this->_pictureExtension;
          
$pendingFile $_SERVER['DOCUMENT_ROOT'] .  
                         
$picturesFolders['pending'] . '/' 
                         
$profile->pictureBasename;
          
move_uploaded_file ($_FILES['picture']['tmp_name'], $pendingFile);
          
chmod ($pendingFile0644);
          
$profile->pictureStatus 'pending'
          
$newPicture true;
        }
        else
        {
          
$newPicture false;
          unset (
$profile->pictureStatus);
        }
        
$profile->username $this->authUsername;
        
$profile->birthDate $this->dateImplode ($this->birthDate);
        
$profile->update ();
        
$newDescription $profile->hasNewDescription ();
        
$newHobbies $profile->hasNewHobbies ();
        
        if (
$newPicture or $newDescription or $newHobbies)
        {
          
$subject  "Modération requise";
          
$content  "L'utilisateur {$this->authUsername} a modifié son profil. Le(s) élément(s) ";
          
$content .= "suivant(s) doivent être validé(s) avant d'être mis en ligne :\n";
          
$content .= $newPicture "- nouvelle photo\n" '';
          
$content .= $newDescription "- nouvelle description personelle\n" '';
          
$content .= $newHobbies "- nouveaux loisirs\n" '';
          
$this->notifyAdmin ($subject$content);
          
          if (
$previousPicture and $previousPicture != $profile->pictureBasename)
          {
            
$previousFile $_SERVER['DOCUMENT_ROOT'] .  
                            
$picturesFolders['pending'] . '/' 
                            
$previousPicture;
            
unlink ($previousFile);
          }
        }
        
        
$profile->reset ();
        
$this->hobbiesStatus '';
        
$this->descriptionStatus '';
      }
    }
   
    
$profile->username $this->authUsername;
    
$profile->find ();
    
$profile->fetch ();
    
$profile->fetchTextData ();
    
$profile->copyInto ($this);
    switch (
$profile->pictureStatus)
    {
      case 
'none' 
        
$this->picture '';
        break;
      case 
'pending' 
        
$this->picture $picturesFolders['pending'] . '/' $profile->pictureBasename;
        break;
      case 
'validated' 
        
$this->picture $picturesFolders['validated'] . '/' $profile->pictureBasename;
        break;
    }
    
$this->birthDate $this->dateExplode ($profile->birthDate);
    require_once 
'Model/Geo.php';
    
$geo = new Geo ();
    
$this->regionsTree $geo->tree;
    
$this->regionsList $geo->regions;
    
$this->departmentsList $geo->departments;
    
$this->region $geo->departmentToRegion ($this->department);
    
asort ($this->departmentsList);
    
asort ($this->regionsList);
    
    
$this->showTemplate('monprofil.tpl.php');
  }

  function 
_check ()
  {
    
$required = array ('gender''department''city');
    foreach (
$required as $key
      if (empty (
$this->$key)) 
        return 
'Les champs sexe, ville  et département doivent être remplis.';
    
    if (empty (
$this->birthDate['year']) or empty ($this->birthDate['month']) 
        or empty (
$this->birthDate['day'])) 
      return 
'La date de naissance doit être remplie.';

    if (!
checkdate ($this->birthDate['month'], $this->birthDate['day'], $this->birthDate['year']))
      return 
"Date de naissance non valide";

    if (isset (
$_FILES['picture']) and $_FILES['picture']['error'] != UPLOAD_ERR_NO_FILE
    {
      if (
$test $this->checkPicture($_FILES['picture'], $this->_pictureExtension))
        return 
$test;

      
$this->_isPictureUploaded true;
    }
    
    return 
'';
  }

  function 
getExistingPendingPicture ()
  {
    
$profile = new Profile ();
    
$profile->username $this->authUsername;
    
$profile->find ();
    
$profile->fetch ();
    if (
$profile->pictureStatus == 'pending')
      return 
$profile->pictureBasename;

    return 
'';
  }
}

/* vim600: set tabstop=2 shiftwidth=2: */
?>

Notice: Undefined index: HTTP_REFERER in /home/_or/olivier/pub/www.samalyse.com/prepend.php on line 208

<< Back

Icon
Faites-nous part de votre projet
Progress bar