Exemple #1
0
	/**
	 *      Update parameters of third party
	 *
	 *      @param	int		$id              			id societe
	 *      @param  User	$user            			Utilisateur qui demande la mise a jour
	 *      @param  int		$call_trigger    			0=non, 1=oui
	 * 		@param	int		$allowmodcodeclient			Inclut modif code client et code compta
	 * 		@param	int		$allowmodcodefournisseur	Inclut modif code fournisseur et code compta fournisseur
	 * 		@param	string	$action						'create' or 'update'
	 *      @return int  			           			<0 if KO, >=0 if OK
	 */
	function update($user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update') {
		global $langs, $conf;
		require_once(DOL_DOCUMENT_ROOT . "/core/lib/functions2.lib.php");

		$error = 0;

		// For triggers
		//if ($call_trigger) $this->oldobject = dol_clone($this);
		// Check parameters
		if (!empty($conf->global->SOCIETE_MAIL_REQUIRED) && !isValidEMail($this->email)) {
			$langs->load("errors");
			$this->error = $langs->trans("ErrorBadEMail", $this->email);
			return -1;
		}

		// Check name is required and codes are ok or unique.
		// If error, this->errors[] is filled
		$result = $this->verify();

		if ($result >= 0) {
			dol_syslog(get_class($this) . "::Update verify ok");

			unset($this->nom); //TODO supprimer
			unset($this->departement); //TODO supprimer
			unset($this->country_code); // TODO supprimer
			parent::update($user);
			dol_syslog(get_class($this) . "::Update json=" . json_encode($this));

			//TODO - faire la suite...
			return 1;

			if ($resql) {
				unset($this->country_code);
				unset($this->country);
				unset($this->state_code);
				unset($this->state);

				// Si le fournisseur est classe on l'ajoute
				$this->AddFournisseurInCategory($this->fournisseur_categorie);

				// Actions on extra fields (by external module or standard code)
				include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php');
				$hookmanager = new HookManager($this->db);
				$hookmanager->initHooks(array('thirdparty_extrafields'));
				$parameters = array('socid' => $this->id);
				$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
				if (empty($reshook)) {
					$result = $this->insertExtraFields();
					if ($result < 0) {
						$error++;
					}
				} else if ($reshook < 0)
					$error++;

				if (!$error && $call_trigger) {
					// Appel des triggers
					include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
					$interface = new Interfaces($this->db);
					$result = $interface->run_triggers('COMPANY_MODIFY', $this, $user, $langs, $conf);
					if ($result < 0) {
						$error++;
						$this->errors = $interface->errors;
					}
					// Fin appel triggers
				}

				if (!$error) {
					dol_syslog(get_class($this) . "::Update success");
					return 1;
				} else {
					return -1;
				}
			} else {
				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
					// Doublon
					$this->error = $langs->trans("ErrorDuplicateField");
					$result = -1;
				} else {

					$this->error = $langs->trans("Error sql=" . $sql);
					dol_syslog(get_class($this) . "::Update fails update sql=" . $sql, LOG_ERR);
					$result = -2;
				}
				return $result;
			}
		} else {
			dol_syslog(get_class($this) . "::Update fails verify " . join(',', $this->errors), LOG_WARNING);
			return -3;
		}
	}
Exemple #2
0
 /**
  * 	Update a member in database (standard information and password)
  *
  * 	@param	User	$user				User making update
  * 	@param	int		$notrigger			1=disable trigger UPDATE (when called by create)
  * 	@param	int		$nosyncuser			0=Synchronize linked user (standard info), 1=Do not synchronize linked user
  * 	@param	int		$nosyncuserpass		0=Synchronize linked user (password), 1=Do not synchronize linked user
  * 	@param	int		$nosyncthirdparty	0=Synchronize linked thirdparty (standard info), 1=Do not synchronize linked thirdparty
  * 	@return	int							<0 if KO, >0 if OK
  */
 function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0)
 {
     global $conf, $langs;
     $nbrowsaffected = 0;
     $error = 0;
     dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncuser="******", nosyncuserpass="******", email=" . $this->email);
     // Clean parameters
     $this->Lastname = trim($this->Lastname);
     $this->Firstname = trim($this->Firstname);
     $this->address = $this->address ? $this->address : $this->adresse;
     $this->zip = $this->zip ? $this->zip : $this->cp;
     $this->town = $this->town ? $this->town : $this->ville;
     $this->country_id = $this->country_id > 0 ? $this->country_id : $this->fk_pays;
     $this->state_id = $this->state_id > 0 ? $this->state_id : $this->fk_departement;
     if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) {
         $this->Lastname = ucwords(trim($this->Lastname));
     }
     if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) {
         $this->Firstname = ucwords(trim($this->Firstname));
     }
     // Check parameters
     if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorBadEMail", $this->email);
         return -1;
     }
     $result = parent::update($user);
     // save
     dol_syslog(get_class($this) . "::update update member sql=" . $sql);
     if ($result) {
         unset($this->country_code);
         unset($this->country);
         unset($this->state_code);
         unset($this->state);
         // Update password
         if (!$error && $this->pass) {
             dol_syslog(get_class($this) . "::update update password");
             if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
                 // Si mot de passe saisi et different de celui en base
                 $result = $this->setPassword($user, $this->pass, 0, $notrigger, $nosyncuserpass);
                 if (!$nbrowsaffected) {
                     $nbrowsaffected++;
                 }
             }
         }
         // Remove links to user and replace with new one
         /* if (! $error)
         			  {
         			  dol_syslog(get_class($this)."::update update link to user");
         			  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id;
         			  dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
         			  $resql = $this->db->query($sql);
         			  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
         			  // If there is a user linked to this member
         			  if ($this->user_id > 0)
         			  {
         			  $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id;
         			  dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG);
         			  $resql = $this->db->query($sql);
         			  if (! $resql) { $this->error=$this->db->error(); $this->db->rollback(); return -5; }
         			  }
         			  }
         
         			  if (! $error && $nbrowsaffected)	// If something has change in main data
         			  {
         			  // Update information on linked user if it is an update
         			  if ($this->user_id > 0 && ! $nosyncuser)
         			  {
         			  require_once(DOL_DOCUMENT_ROOT."/user/class/user.class.php");
         
         			  dol_syslog(get_class($this)."::update update linked user");
         
         			  $luser=new User($this->db);
         			  $result=$luser->fetch($this->user_id);
         
         			  if ($result >= 0)
         			  {
         			  $luser->civilite_id=$this->civilite_id;
         			  $luser->firstname=$this->firstname;
         			  $luser->lastname=$this->lastname;
         			  $luser->prenom=$this->firstname;    // deprecated
         			  $luser->nom=$this->lastname;        // deprecated
         			  $luser->login=$this->user_login;
         			  $luser->pass=$this->pass;
         			  $luser->societe_id=$this->societe;
         
         			  $luser->email=$this->email;
         			  $luser->office_phone=$this->phone;
         			  $luser->user_mobile=$this->phone_mobile;
         
         			  $luser->note=$this->note;
         
         			  $luser->fk_member=$this->id;
         
         			  $result=$luser->update($user,0,1,1);	// Use nosync to 1 to avoid cyclic updates
         			  if ($result < 0)
         			  {
         			  $this->error=$luser->error;
         			  dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
         			  $error++;
         			  }
         			  }
         			  else
         			  {
         			  $this->error=$luser->error;
         			  $error++;
         			  }
         			  }
         
         			  // Update information on linked thirdparty if it is an update
         			  if ($this->fk_soc > 0 && ! $nosyncthirdparty)
         			  {
         			  require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
         
         			  dol_syslog(get_class($this)."::update update linked thirdparty");
         
         			  // This member is linked with a thirdparty, so we also update thirdparty informations
         			  // if this is an update.
         			  $lthirdparty=new Societe($this->db);
         			  $result=$lthirdparty->fetch($this->fk_soc);
         
         			  if ($result >= 0)
         			  {
         			  $lthirdparty->address=$this->address;
         			  $lthirdparty->zip=$this->zip;
         			  $lthirdparty->town=$this->town;
         			  $lthirdparty->email=$this->email;
         			  $lthirdparty->tel=$this->phone;
         			  $lthirdparty->state_id=$this->state_id;
         			  $lthirdparty->country_id=$this->country_id;
         			  $lthirdparty->pays_id=$this->country_id;
         			  //$lthirdparty->phone_mobile=$this->phone_mobile;
         
         			  $result=$lthirdparty->update($this->fk_soc,$user,0,1,1,'update');	// Use sync to 0 to avoid cyclic updates
         			  if ($result < 0)
         			  {
         			  $this->error=$lthirdparty->error;
         			  dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
         			  $error++;
         			  }
         			  }
         			  else
         			  {
         			  $this->error=$lthirdparty->error;
         			  $error++;
         			  }
         			  } */
         if (!$error && !$notrigger) {
             // Appel des triggers
             include_once DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php";
             $interface = new Interfaces($this->db);
             $result = $interface->run_triggers('MEMBER_MODIFY', $this, $user, $langs, $conf);
             if ($result < 0) {
                 $error++;
                 $this->errors = $interface->errors;
             }
             // Fin appel triggers
         }
     }
     if (!$error) {
         return 1;
     } else {
         return -1;
     }
 }