Пример #1
0
$urlok=preg_replace('/&$/','',$urlok);  // Remove last &
$urlko=preg_replace('/&$/','',$urlko);  // Remove last &


/*
 * Actions
 */
if (GETPOST("action") == 'dopayment')
{
    $PRICE=price2num(GETPOST("newamount"),'MT');
    $email=GETPOST("email");

	$mesg='';
	if (empty($PRICE) || ! is_numeric($PRICE)) $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Amount"));
	elseif (empty($email))          $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("YourEMail"));
	elseif (! isValidEMail($email)) $mesg=$langs->trans("ErrorBadEMail",$email);
	elseif (empty($FULLTAG))        $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("PaymentCode"));

	if (empty($mesg))
	{
		dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG);

		print_paybox_redirect($PRICE, $conf->monnaie, $email, $urlok, $urlko, $FULLTAG);

		session_destroy();
		exit;
	}
}


Пример #2
0
	/**
	 *    \brief      Ajoute destinataires dans table des cibles
	 *    \param      mailing_id    Id of emailing
	 *    \param      filterarray   Requete sql de selection des destinataires
	 *    \return     int           < 0 si erreur, nb ajout si ok
	 */
	function add_to_target($mailing_id,$filtersarray=array())
	{
		global $conf,$langs,$_FILES;

		require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php");

		// For compatibility with Unix, MS-Dos or Macintosh
		ini_set('auto_detect_line_endings', true);

		$cibles = array();

		$upload_dir=$conf->mailing->dir_temp;

		if (create_exdir($upload_dir) >= 0)
		{
			$resupload = dol_move_uploaded_file($_FILES['username']['tmp_name'], $upload_dir . "/" . $_FILES['username']['name'], 1, 0, $_FILES['username']['error']);
			if (is_numeric($resupload) && $resupload > 0)
			{
				$cpt=0;

				//$mesg = '<div class="ok">'.$langs->trans("FileTransferComplete").'</div>';
				//print_r($_FILES);
				$file=$upload_dir . "/" . $_FILES['username']['name'];
				$handle = @fopen($file, "r");
				if ($handle)
				{
					$i = 0;
		            $j = 0;

            		$old = '';
					while (!feof($handle))
					{
						$cpt++;
				        $buffer = trim(fgets($handle));
			        	$tab=explode(';',$buffer,4);
				        $email=$tab[0];
				        $name=$tab[1];
				        $firstname=$tab[2];
				        $other=$tab[3];
				        if (! empty($buffer))
				        {
			        		//print 'xx'.dol_strlen($buffer).empty($buffer)."<br>\n";
				        	$id=$cpt;
					        if (isValidEMail($email))
					        {
		   						if ($old <> $email)
								{
									$cibles[$j] = array(
					                    			'email' => $email,
					                    			'name' => $name,
					                    			'firstname' => $firstname,
													'other' => $other,
                                                    'source_url' => '',
                                                    'source_id' => '',
                                                    'source_type' => 'file'
									);
									$old = $email;
									$j++;
								}
					        }
					        else
					        {
					        	$i++;
					        	$langs->load("errors");
					        	$this->error = $langs->trans("ErrorFoundBadEmailInFile",$i,$cpt,$email);
					        }
				        }
				    }
				    fclose($handle);

				    if ($i > 0)
				    {
				    	return -$i;
				    }
				}
				else
				{
					$this->error = $langs->trans("ErrorFaildToOpenFile");
					return -1;
				}

				dol_syslog(get_class($this)."::add_to_target mailing ".$cpt." targets found");
			}
			else
			{
				$langs->load("errors");
				if ($resupload < 0)	// Unknown error
				{
					$this->error = '<div class="error">'.$langs->trans("ErrorFileNotUploaded").'</div>';
				}
				else if (preg_match('/ErrorFileIsInfectedWithAVirus/',$resupload))	// Files infected by a virus
				{
					$this->error = '<div class="error">'.$langs->trans("ErrorFileIsInfectedWithAVirus").'</div>';
				}
				else	// Known error
				{
					$this->error = '<div class="error">'.$langs->trans($resupload).'</div>';
				}
			}
		}

		ini_set('auto_detect_line_endings', false);

		return parent::add_to_target($mailing_id, $cibles);
	}
Пример #3
0
 /**
  *	Update a member in database (standard information and password)
  *	@param		user			User making update
  *	@param		notrigger		1=disable trigger UPDATE (when called by create)
  *	@param		nosyncuser		0=Synchronize linked user (standard info), 1=Do not synchronize linked user
  *	@param		nosyncuserpass	0=Synchronize linked user (password), 1=Do not synchronize linked user
  * 	@return		int				<0 si KO, >0 si OK
  */
 function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0)
 {
     global $conf, $langs;
     $nbrowsaffected = 0;
     $error = 0;
     dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncuser="******", nosyncuserpass="******", email=" . $this->email);
     // Clean parameters
     if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) {
         $this->nom = ucwords(trim($this->nom));
     }
     if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) {
         $this->prenom = ucwords(trim($this->prenom));
     }
     // Check parameters
     if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorBadEMail", $this->email);
         return -1;
     }
     $this->db->begin();
     $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent SET";
     $sql .= " civilite = " . ($this->civilite_id ? "'" . $this->civilite_id . "'" : "null");
     $sql .= ", prenom = " . ($this->prenom ? "'" . $this->db->escape($this->prenom) . "'" : "null");
     $sql .= ", nom=" . ($this->nom ? "'" . $this->db->escape($this->nom) . "'" : "null");
     $sql .= ", login="******"'" . $this->db->escape($this->login) . "'" : "null");
     $sql .= ", societe=" . ($this->societe ? "'" . $this->db->escape($this->societe) . "'" : "null");
     $sql .= ", fk_soc=" . ($this->fk_soc > 0 ? "'" . $this->fk_soc . "'" : "null");
     $sql .= ", adresse=" . ($this->adresse ? "'" . $this->db->escape($this->adresse) . "'" : "null");
     $sql .= ", cp=" . ($this->cp ? "'" . $this->db->escape($this->cp) . "'" : "null");
     $sql .= ", ville=" . ($this->ville ? "'" . $this->db->escape($this->ville) . "'" : "null");
     $sql .= ", pays=" . ($this->pays_id > 0 ? "'" . $this->pays_id . "'" : "null");
     $sql .= ", fk_departement=" . ($this->fk_departement > 0 ? "'" . $this->fk_departement . "'" : "null");
     $sql .= ", email=" . "'" . $this->email . "'";
     $sql .= ", phone=" . ($this->phone ? "'" . $this->db->escape($this->phone) . "'" : "null");
     $sql .= ", phone_perso=" . ($this->phone_perso ? "'" . $this->db->escape($this->phone_perso) . "'" : "null");
     $sql .= ", phone_mobile=" . ($this->phone_mobile ? "'" . $this->db->escape($this->phone_mobile) . "'" : "null");
     $sql .= ", note=" . ($this->note ? "'" . $this->db->escape($this->note) . "'" : "null");
     $sql .= ", photo=" . ($this->photo ? "'" . $this->photo . "'" : "null");
     $sql .= ", public=" . "'" . $this->public . "'";
     $sql .= ", statut=" . $this->statut;
     $sql .= ", fk_adherent_type=" . $this->typeid;
     $sql .= ", morphy=" . "'" . $this->morphy . "'";
     $sql .= ", naiss=" . ($this->naiss ? "'" . $this->db->idate($this->naiss) . "'" : "null");
     if ($this->datefin) {
         $sql .= ", datefin='" . $this->db->idate($this->datefin) . "'";
     }
     // Ne doit etre modifie que par effacement cotisation
     if ($this->datevalid) {
         $sql .= ", datevalid='" . $this->db->idate($this->datevalid) . "'";
     }
     // Ne doit etre modifie que par validation adherent
     $sql .= ", fk_user_mod=" . ($user->id > 0 ? $user->id : 'null');
     // Can be null because member can be create by a guest
     $sql .= " WHERE rowid = " . $this->id;
     dol_syslog(get_class($this) . "::update update member sql=" . $sql);
     $resql = $this->db->query($sql);
     if ($resql) {
         $nbrowsaffected += $this->db->affected_rows($resql);
         $result = $this->insertExtraFields();
         if ($result < 0) {
             $error++;
         }
         // 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 link to user
         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 ($this->user_id > 0 && !$nosyncuser) {
                 require_once DOL_DOCUMENT_ROOT . "/user/class/user.class.php";
                 dol_syslog(get_class($this) . "::update update linked user");
                 // This member is linked with a user, so we also update users informations
                 // if this is an update.
                 $luser = new User($this->db);
                 $result = $luser->fetch($this->user_id);
                 if ($result >= 0) {
                     $luser->civilite_id = $this->civilite_id;
                     $luser->prenom = $this->prenom;
                     $luser->nom = $this->nom;
                     $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++;
                 }
             }
             if (!$error && !$notrigger) {
                 $this->use_webcal = $conf->global->PHPWEBCALENDAR_MEMBERSTATUS == 'always' ? 1 : 0;
                 // 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) {
             $this->db->commit();
             return $nbrowsaffected;
         } else {
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->db->rollback();
         $this->error = $this->db->lasterror();
         dol_syslog(get_class($this) . "::Update " . $this->error, LOG_ERR);
         return -2;
     }
 }
Пример #4
0
$urlko = preg_replace('/&$/', '', $urlko);
// Remove last &
// Check security token
$valid = true;
/*
 * Actions
 */
if (GETPOST("action") == 'dopayment') {
    $PRICE = price2num(GETPOST("newamount"), 'MT');
    $email = GETPOST("email");
    $mesg = '';
    if (empty($PRICE) || !is_numeric($PRICE)) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount"));
    } elseif (empty($email)) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("YourEMail"));
    } elseif (!isValidEMail($email)) {
        $mesg = $langs->trans("ErrorBadEMail", $email);
    } elseif (empty($FULLTAG)) {
        $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentCode"));
    } elseif (dol_strlen($urlok) > 150) {
        $mesg = 'Error urlok too long ' . $urlok;
    } elseif (dol_strlen($urlko) > 150) {
        $mesg = 'Error urlko too long ' . $urlko;
    }
    if (empty($mesg)) {
        dol_syslog("newpayment.php call paybox api and do redirect", LOG_DEBUG);
        print_paybox_redirect($PRICE, $conf->currency, $email, $urlok, $urlko, $FULLTAG);
        session_destroy();
        exit;
    }
}
Пример #5
0
    /**
     *  Create or Update an user into database
     *
     *  @param	User	$user        	Objet user qui demande la creation
     *  @param  int		$notrigger		1 ne declenche pas les triggers, 0 sinon
     *  @return int			         	<0 si KO, id compte cree si OK
     */
    function update($user, $notrigger = 0, $action) {
        global $conf, $langs;
        global $mysoc;

        // Clean parameters
        $this->values->name = trim($this->values->name);

        dol_syslog(get_class($this) . "::create login="******", user="******"errors");
            $this->error = $langs->trans("ErrorBadEMail", $this->values->Email);
            return -1;
        }

        $this->values->CreateDate = dol_now();
        trim($this->values->pass);

        $error = 0;

        try {
            $result = $this->couchAdmin->getUser($this->values->name);
        } catch (Exception $e) {
            
        }

        if (isset($result->name) && $action == 'add') {
            $this->error = 'ErrorLoginAlreadyExists';
            dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING);
            return -6;
        } else {
            if ($action == 'add') {
                $this->values->Status = "DISABLE";

                try {
                    $this->couchAdmin->createUser($this->values->name, $this->values->pass);
                } catch (Exception $e) {
                    $this->error = $e->getMessage();
                    dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR);
                    dol_print_error("", $this->error);
                    exit;
                    return -4;
                }
            }
        }

        try {
            $user_tmp = $this->couchAdmin->getUser($this->values->name);

            $this->values->salt = $user_tmp->salt;
            $this->values->password_sha = $user_tmp->password_sha;
            $this->values->type = $user_tmp->type;
            $this->values->roles = $user_tmp->roles;
            $this->values->_id = $user_tmp->_id;
            $this->values->_rev = $user_tmp->_rev;
            $this->values->Status = $user_tmp->Status;

            $caneditpassword = ((($user->login == $this->values->name) && $user->rights->user->self->password)
                    || (($user->login != $this->values->name) && $user->rights->user->user->password)) || $user->admin;

            if ($caneditpassword && !empty($this->values->pass)) { // Case we can edit only password
                $this->values->password_sha = sha1($this->values->pass . $this->values->salt, false);
            }

            unset($this->values->pass);

            $this->couchdb->clean($this->values);

            //print_r($this->values);exit;
            $result = $this->couchdb->storeDoc($this->values); // Save all specific parameters
        } catch (Exception $e) {
            $this->error = $e->getMessage();
            dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR);
            dol_print_error("", $this->error);
            exit;
            return -3;
        }


        if ($result) {
            $this->id = $this->values->name;

            if (!$notrigger) {
                // Appel des triggers
                include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
                $interface = new Interfaces($this->db);
                $result = $interface->run_triggers('USER_CREATE', $this, $user, $langs, $conf);
                if ($result < 0) {
                    $error++;
                    $this->errors = $interface->errors;
                }
                // Fin appel triggers
            }
        } else {
            $this->error = $this->db->lasterror();
            dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR);
            return -2;
        }

        return $this->id;
    }
Пример #6
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
  * 	@param	string	$action				Current action for hookmanager
  * 	@return	int							<0 if KO, >0 if OK
  */
 function update($user, $notrigger = 0, $nosyncuser = 0, $nosyncuserpass = 0, $nosyncthirdparty = 0, $action = 'update')
 {
     global $conf, $langs, $hookmanager;
     $nbrowsaffected = 0;
     $error = 0;
     dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncuser="******", nosyncuserpass="******" nosyncthirdparty=" . $nosyncthirdparty . ", email=" . $this->email);
     // Clean parameters
     $this->lastname = trim($this->lastname) ? trim($this->lastname) : trim($this->lastname);
     $this->firstname = trim($this->firstname) ? trim($this->firstname) : trim($this->firstname);
     $this->address = $this->address ? $this->address : $this->address;
     $this->zip = $this->zip ? $this->zip : $this->zip;
     $this->town = $this->town ? $this->town : $this->town;
     $this->country_id = $this->country_id > 0 ? $this->country_id : $this->country_id;
     $this->state_id = $this->state_id > 0 ? $this->state_id : $this->state_id;
     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;
     }
     $this->db->begin();
     $sql = "UPDATE " . MAIN_DB_PREFIX . "adherent SET";
     $sql .= " civility = " . (!is_null($this->civility_id) ? "'" . $this->civility_id . "'" : "null");
     $sql .= ", firstname = " . ($this->firstname ? "'" . $this->db->escape($this->firstname) . "'" : "null");
     $sql .= ", lastname=" . ($this->lastname ? "'" . $this->db->escape($this->lastname) . "'" : "null");
     $sql .= ", login="******"'" . $this->db->escape($this->login) . "'" : "null");
     $sql .= ", societe=" . ($this->societe ? "'" . $this->db->escape($this->societe) . "'" : "null");
     $sql .= ", fk_soc=" . ($this->fk_soc > 0 ? "'" . $this->fk_soc . "'" : "null");
     $sql .= ", address=" . ($this->address ? "'" . $this->db->escape($this->address) . "'" : "null");
     $sql .= ", zip=" . ($this->zip ? "'" . $this->db->escape($this->zip) . "'" : "null");
     $sql .= ", town=" . ($this->town ? "'" . $this->db->escape($this->town) . "'" : "null");
     $sql .= ", country=" . ($this->country_id > 0 ? "'" . $this->country_id . "'" : "null");
     $sql .= ", state_id=" . ($this->state_id > 0 ? "'" . $this->state_id . "'" : "null");
     $sql .= ", email='" . $this->email . "'";
     $sql .= ", skype='" . $this->skype . "'";
     $sql .= ", phone=" . ($this->phone ? "'" . $this->db->escape($this->phone) . "'" : "null");
     $sql .= ", phone_perso=" . ($this->phone_perso ? "'" . $this->db->escape($this->phone_perso) . "'" : "null");
     $sql .= ", phone_mobile=" . ($this->phone_mobile ? "'" . $this->db->escape($this->phone_mobile) . "'" : "null");
     $sql .= ", note_private=" . ($this->note_private ? "'" . $this->db->escape($this->note_private) . "'" : "null");
     $sql .= ", note_public=" . ($this->note_private ? "'" . $this->db->escape($this->note_public) . "'" : "null");
     $sql .= ", photo=" . ($this->photo ? "'" . $this->photo . "'" : "null");
     $sql .= ", public='" . $this->public . "'";
     $sql .= ", statut=" . $this->statut;
     $sql .= ", fk_adherent_type=" . $this->typeid;
     $sql .= ", morphy='" . $this->morphy . "'";
     $sql .= ", birth=" . ($this->birth ? "'" . $this->db->idate($this->birth) . "'" : "null");
     if ($this->datefin) {
         $sql .= ", datefin='" . $this->db->idate($this->datefin) . "'";
     }
     // Ne doit etre modifie que par effacement cotisation
     if ($this->datevalid) {
         $sql .= ", datevalid='" . $this->db->idate($this->datevalid) . "'";
     }
     // Ne doit etre modifie que par validation adherent
     $sql .= ", fk_user_mod=" . ($user->id > 0 ? $user->id : 'null');
     // Can be null because member can be create by a guest
     $sql .= " WHERE rowid = " . $this->id;
     dol_syslog(get_class($this) . "::update update member", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         unset($this->country_code);
         unset($this->country);
         unset($this->state_code);
         unset($this->state);
         $nbrowsaffected += $this->db->affected_rows($resql);
         $action = 'update';
         // Actions on extra fields (by external module)
         // TODO le hook fait double emploi avec le trigger !!
         $hookmanager->initHooks(array('memberdao'));
         $parameters = array('id' => $this->id);
         $action = '';
         $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $this, $action);
         // Note that $action and $object may have been modified by some hooks
         if (empty($reshook)) {
             if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
                 $result = $this->insertExtraFields();
                 if ($result < 0) {
                     $error++;
                 }
             }
         } else {
             if ($reshook < 0) {
                 $error++;
             }
         }
         // 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", 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", LOG_DEBUG);
                 $resql = $this->db->query($sql);
                 if (!$resql) {
                     $this->error = $this->db->error();
                     $this->db->rollback();
                     return -5;
                 }
             }
         }
         if (!$error && $nbrowsaffected) {
             // 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) {
                     //var_dump($this->user_login);exit;
                     //var_dump($this->login);exit;
                     $luser->login = $this->login;
                     $luser->civility_id = $this->civility_id;
                     $luser->firstname = $this->firstname;
                     $luser->lastname = $this->lastname;
                     $luser->pass = $this->pass;
                     $luser->societe_id = $this->societe;
                     $luser->email = $this->email;
                     $luser->skype = $this->skype;
                     $luser->office_phone = $this->phone;
                     $luser->user_mobile = $this->phone_mobile;
                     $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->skype = $this->skype;
                     $lthirdparty->phone = $this->phone;
                     $lthirdparty->state_id = $this->state_id;
                     $lthirdparty->country_id = $this->country_id;
                     $lthirdparty->country_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) {
                 // Call trigger
                 $result = $this->call_trigger('MEMBER_MODIFY', $user);
                 if ($result < 0) {
                     $error++;
                 }
                 // End call triggers
             }
         }
         if (!$error) {
             $this->db->commit();
             return $nbrowsaffected;
         } else {
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->db->rollback();
         $this->error = $this->db->lasterror();
         return -2;
     }
 }
Пример #7
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						'add' or 'update'
     *		@param	int		$nosyncmember				Do not synchronize info of linked member
     *      @return int  			           			<0 if KO, >=0 if OK
     */
    function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
    {
        global $langs,$conf,$hookmanager;
        require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';

		$error=0;

        dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);

        $now=dol_now();

        // Clean parameters
        $this->id			= $id;
        $this->name			= $this->name?trim($this->name):trim($this->nom);
        $this->nom			= $this->name;	// For backward compatibility
	    $this->name_alias = trim($this->name_alias);
        $this->ref_ext		= trim($this->ref_ext);
        $this->address		= $this->address?trim($this->address):trim($this->address);
        $this->zip			= $this->zip?trim($this->zip):trim($this->zip);
        $this->town			= $this->town?trim($this->town):trim($this->town);
        $this->state_id		= trim($this->state_id);
        $this->country_id	= ($this->country_id > 0)?$this->country_id:0;
        $this->phone		= trim($this->phone);
        $this->phone		= preg_replace("/\s/","",$this->phone);
        $this->phone		= preg_replace("/\./","",$this->phone);
        $this->fax			= trim($this->fax);
        $this->fax			= preg_replace("/\s/","",$this->fax);
        $this->fax			= preg_replace("/\./","",$this->fax);
        $this->email		= trim($this->email);
        $this->skype		= trim($this->skype);
        $this->url			= $this->url?clean_url($this->url,0):'';
        $this->idprof1		= trim($this->idprof1);
        $this->idprof2		= trim($this->idprof2);
        $this->idprof3		= trim($this->idprof3);
        $this->idprof4		= trim($this->idprof4);
        $this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
        $this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
        $this->prefix_comm	= trim($this->prefix_comm);

        $this->tva_assuj	= trim($this->tva_assuj);
        $this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
        if (empty($this->status)) $this->status = 0;

		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
		if (empty($this->fk_multicurrency))
		{
			$this->multicurrency_code = '';
			$this->fk_multicurrency = 0;
		}

        // Local taxes
        $this->localtax1_assuj=trim($this->localtax1_assuj);
        $this->localtax2_assuj=trim($this->localtax2_assuj);

        $this->localtax1_value=trim($this->localtax1_value);
        $this->localtax2_value=trim($this->localtax2_value);

        if ($this->capital != '') $this->capital=price2num(trim($this->capital));
        if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef

        $this->effectif_id=trim($this->effectif_id);
        $this->forme_juridique_code=trim($this->forme_juridique_code);

        //Gencod
        $this->barcode=trim($this->barcode);

        // For automatic creation
        if ($this->code_client == -1) $this->get_codeclient($this,0);
        if ($this->code_fournisseur == -1) $this->get_codefournisseur($this,1);

        $this->code_compta=trim($this->code_compta);
        $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);

        // Check parameters
        if (! empty($conf->global->SOCIETE_MAIL_REQUIRED) && ! isValidEMail($this->email))
        {
            $langs->load("errors");
            $this->error = $langs->trans("ErrorBadEMail",$this->email);
            return -1;
        }
        if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
        {
            $langs->load("errors");
            $this->error = $langs->trans("BadValueForParameterClientOrSupplier");
            return -1;
        }

        $customer=false;
        if (! empty($allowmodcodeclient) && ! empty($this->client))
        {
        	// Attention get_codecompta peut modifier le code suivant le module utilise
        	if (empty($this->code_compta))
        	{
        		$ret=$this->get_codecompta('customer');
        		if ($ret < 0) return -1;
        	}

        	$customer=true;
        }

        $supplier=false;
        if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
        {
        	// Attention get_codecompta peut modifier le code suivant le module utilise
        	if (empty($this->code_compta_fournisseur))
        	{
        		$ret=$this->get_codecompta('supplier');
        		if ($ret < 0) return -1;
        	}

        	$supplier=true;
        }

        //Web services
        $this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
        $this->webservices_key = trim($this->webservices_key);

        //Incoterms
        $this->fk_incoterms = (int) $this->fk_incoterms;
		$this->location_incoterms = trim($this->location_incoterms);

        $this->db->begin();

        // Check name is required and codes are ok or unique.
        // If error, this->errors[] is filled
        $result = 0;
        if ($action != 'add') $result = $this->verify();	// We don't check when update called during a create because verify was already done

        if ($result >= 0)
        {
            dol_syslog(get_class($this)."::update verify ok or not done");

            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
            $sql .= "nom = '" . $this->db->escape($this->name) ."'"; // Required
            $sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
            $sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
            $sql .= ",address = '" . $this->db->escape($this->address) ."'";

            $sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
            $sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");

            $sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
            $sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";

            $sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
            $sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
            $sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
            $sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
            $sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");

            $sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
            $sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
            $sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
            $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
            $sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
            $sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";

            $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null");
            $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
            $sql .= ",status = " .$this->status;

            // Local taxes
            $sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->localtax1_assuj."'":"null");
            $sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->localtax2_assuj."'":"null");
            if($this->localtax1_assuj==1)
            {
            	if($this->localtax1_value!='')
            	{
            		$sql .=",localtax1_value =".$this->localtax1_value;
            	}
            	else $sql .=",localtax1_value =0.000";

            }
            else $sql .=",localtax1_value =0.000";

            if($this->localtax2_assuj==1)
            {
            	if($this->localtax2_value!='')
            	{
            		$sql .=",localtax2_value =".$this->localtax2_value;
            	}
            	else $sql .=",localtax2_value =0.000";

            }
            else $sql .=",localtax2_value =0.000";

            $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);

            $sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");

            $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");

            $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");

            $sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");

            $sql .= ",client = " . (! empty($this->client)?$this->client:0);
            $sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
            $sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
            $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
            $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");

            $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
            $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");

			//Incoterms
			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");

            if ($customer)
            {
                $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
                $sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
            }

            if ($supplier)
            {
                $sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
                $sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
            }
            $sql .= ", fk_user_modif = ".(! empty($user->id)?"'".$user->id."'":"null");
			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
			$sql .= ', multicurrency_code = "'.$this->db->escape($this->multicurrency_code).'"';
            $sql .= " WHERE rowid = '" . $id ."'";


            dol_syslog(get_class($this)."::Update", LOG_DEBUG);
            $resql=$this->db->query($sql);
            if ($resql)
            {
            	unset($this->country_code);		// We clean this because it may have been changed after an update of country_id
            	unset($this->country);
            	unset($this->state_code);
            	unset($this->state);

            	$nbrowsaffected = $this->db->affected_rows($resql);

            	if (! $error && $nbrowsaffected)
            	{
            		// Update information on linked member if it is an update
	            	if (! $nosyncmember && ! empty($conf->adherent->enabled))
	            	{
		            	require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';

		            	dol_syslog(get_class($this)."::update update linked member");

		            	$lmember=new Adherent($this->db);
		            	$result=$lmember->fetch(0, 0, $this->id);

		            	if ($result > 0)
		            	{
		            		$lmember->societe=$this->name;
		            		//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
		            		//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
		            		$lmember->address=$this->address;
		            		$lmember->email=$this->email;
                    		$lmember->skype=$this->skype;
		            		$lmember->phone=$this->phone;

		            		$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
		            		if ($result < 0)
		            		{
		            			$this->error=$lmember->error;
		            			dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
		            			$error++;
		            		}
		            	}
		            	else if ($result < 0)
		            	{
		            		$this->error=$lmember->error;
		            		$error++;
		            	}
	            	}
            	}

            	$action='update';

                // Actions on extra fields (by external module or standard code)
                // TODO le hook fait double emploi avec le trigger !!
                $hookmanager->initHooks(array('thirdpartydao'));
                $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))
                {
                	if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
                	{
                		$result=$this->insertExtraFields();
                		if ($result < 0)
                		{
                			$error++;
                		}
                	}
                }
                else if ($reshook < 0) $error++;

                if (! $error && $call_trigger)
                {
                    // Call trigger
                    $result=$this->call_trigger('COMPANY_MODIFY',$user);
                    if ($result < 0) $error++;
                    // End call triggers
                }

                if (! $error)
                {
                    dol_syslog(get_class($this)."::Update success");
                    $this->db->commit();
                    return 1;
                }
                else
				{
                    $this->db->rollback();
                    return -1;
                }
            }
            else
			{
                if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
                {
                    // Doublon
                    $this->error = $langs->trans("ErrorDuplicateField");
                    $result =  -1;
                }
                else
                {
                    $result =  -2;
                }
                $this->db->rollback();
                return $result;
            }
        }
        else
       {
            $this->db->rollback();
            dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
            return -3;
        }
    }
Пример #8
0
    /**
     *      Update parameters of third party
     *      @param      id              			id societe
     *      @param      user            			Utilisateur qui demande la mise a jour
     *      @param      call_trigger    			0=non, 1=oui
     *		@param		allowmodcodeclient			Inclut modif code client et code compta
     *		@param		allowmodcodefournisseur		Inclut modif code fournisseur et code compta fournisseur
     *      @return     int             			<0 if KO, >=0 if OK
     */
    function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0)
    {
        require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");

        global $langs,$conf;

        dol_syslog("Societe::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);

        // For triggers
        if ($call_trigger)
        {
        	$objectstatic=new Societe($this->db);
        	$objectstatic->fetch($id);
        	$this->oldobject = $objectstatic;
        }

        $now=dol_now();

        // Clean parameters
        $this->id=$id;
        $this->name=$this->name?trim($this->name):trim($this->nom);
        $this->nom=trim($this->nom);    // TODO obsolete
        $this->address=$this->address?trim($this->address):trim($this->adresse);
        $this->adresse=$this->address;  // TODO obsolete
        $this->zip=$this->zip?trim($this->zip):trim($this->cp);
        $this->cp=$this->zip;           // TODO obsolete
        $this->town=$this->town?trim($this->town):trim($this->ville);
        $this->ville=$this->town;       // TODO obsolete
        $this->departement_id=trim($this->departement_id);
        $this->pays_id=trim($this->pays_id);
        $this->tel=trim($this->tel);
        $this->fax=trim($this->fax);
        $this->tel = preg_replace("/\s/","",$this->tel);
        $this->tel = preg_replace("/\./","",$this->tel);
        $this->fax = preg_replace("/\s/","",$this->fax);
        $this->fax = preg_replace("/\./","",$this->fax);
        $this->email=trim($this->email);
        $this->url=$this->url?clean_url($this->url,0):'';
        $this->siren=trim($this->siren);
        $this->siret=trim($this->siret);
        $this->ape=trim($this->ape);
        $this->idprof4=trim($this->idprof4);
        $this->prefix_comm=trim($this->prefix_comm);

        $this->tva_assuj=trim($this->tva_assuj);
        $this->tva_intra=dol_sanitizeFileName($this->tva_intra,'');
        if (empty($this->status)) $this->status = 0;

        // Local taxes
        $this->localtax1_assuj=trim($this->localtax1_assuj);
        $this->localtax2_assuj=trim($this->localtax2_assuj);

        $this->capital=price2num(trim($this->capital),'MT');
        if (empty($this->capital)) $this->capital = 0;

        $this->effectif_id=trim($this->effectif_id);
        $this->forme_juridique_code=trim($this->forme_juridique_code);

        //Gencod
        $this->gencod=trim($this->gencod);

        // For automatic creation
        if ($this->code_client == -1) $this->get_codeclient($this->prefix_comm,0);
        if ($this->code_fournisseur == -1) $this->get_codefournisseur($this->prefix_comm,1);

        $this->code_compta=trim($this->code_compta);
        $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);

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

        $this->db->begin();

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

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

            $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
            $sql.= " SET nom = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire
            $sql.= ",datea = '".$this->db->idate($now)."'";
            $sql.= ",address = '" . $this->db->escape($this->address) ."'";

            $sql.= ",cp = ".($this->zip?"'".$this->zip."'":"null");
            $sql.= ",ville = ".($this->town?"'".$this->db->escape($this->town)."'":"null");

            $sql .= ",fk_departement = '" . ($this->departement_id?$this->departement_id:'0') ."'";
            $sql .= ",fk_pays = '" . ($this->pays_id?$this->pays_id:'0') ."'";

            $sql .= ",tel = ".($this->tel?"'".$this->db->escape($this->tel)."'":"null");
            $sql .= ",fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null");
            $sql .= ",email = ".($this->email?"'".$this->db->escape($this->email)."'":"null");
            $sql .= ",url = ".($this->url?"'".$this->db->escape($this->url)."'":"null");

            $sql .= ",siren   = '". $this->db->escape($this->siren)   ."'";
            $sql .= ",siret   = '". $this->db->escape($this->siret)   ."'";
            $sql .= ",ape     = '". $this->db->escape($this->ape)     ."'";
            $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";

            $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->tva_assuj."'":"null");
            $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
            $sql .= ",status = " .$this->status;

            // Local taxes
            $sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->localtax1_assuj."'":"null");
            $sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->localtax2_assuj."'":"null");

            $sql .= ",capital = ".$this->capital;

            $sql .= ",prefix_comm = ".($this->prefix_comm?"'".$this->db->escape($this->prefix_comm)."'":"null");

            $sql .= ",fk_effectif = ".($this->effectif_id?"'".$this->effectif_id."'":"null");

            $sql .= ",fk_typent = ".($this->typent_id?"'".$this->typent_id."'":"0");

            $sql .= ",fk_forme_juridique = ".($this->forme_juridique_code?"'".$this->forme_juridique_code."'":"null");

            $sql .= ",client = " . ($this->client?$this->client:0);
            $sql .= ",fournisseur = " . ($this->fournisseur?$this->fournisseur:0);
            $sql .= ",gencod = ".($this->gencod?"'".$this->gencod."'":"null");
            $sql .= ",default_lang = ".($this->default_lang?"'".$this->default_lang."'":"null");
            $sql .= ",logo = ".($this->logo?"'".$this->logo."'":"null");

            if ($allowmodcodeclient)
            {
                //$this->check_codeclient();

                $sql .= ", code_client = ".($this->code_client?"'".$this->db->escape($this->code_client)."'":"null");

                // Attention get_codecompta peut modifier le code suivant le module utilise
                if (empty($this->code_compta)) $this->get_codecompta('customer');

                $sql .= ", code_compta = ".($this->code_compta?"'".$this->db->escape($this->code_compta)."'":"null");
            }

            if ($allowmodcodefournisseur)
            {
                //$this->check_codefournisseur();

                $sql .= ", code_fournisseur = ".($this->code_fournisseur?"'".$this->db->escape($this->code_fournisseur)."'":"null");

                // Attention get_codecompta peut modifier le code suivant le module utilise
                if (empty($this->code_compta_fournisseur)) $this->get_codecompta('supplier');

                $sql .= ", code_compta_fournisseur = ".($this->code_compta_fournisseur?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
            }
            $sql .= ", fk_user_modif = ".($user->id > 0 ? "'".$user->id."'":"null");
            $sql .= " WHERE rowid = '" . $id ."'";


            dol_syslog(get_class($this)."::Update sql=".$sql);
            $resql=$this->db->query($sql);
            if ($resql)
            {
                // Si le fournisseur est classe on l'ajoute
                $this->AddFournisseurInCategory($this->fournisseur_categorie);

                $result=$this->insertExtraFields();
                if ($result < 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");
                    $this->db->commit();
                    return 1;
                }
                else
                {
                    $this->db->rollback();
                    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;
                }
                $this->db->rollback();
                return $result;
            }
        }
        else
        {
            $this->db->rollback();
            dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
            return -3;
        }
    }
Пример #9
0
 /**
  *  	Update a user into databse (and also password if this->pass is defined)
  *		@param		user				User qui fait la mise a jour
  *    	@param      notrigger			1 ne declenche pas les triggers, 0 sinon
  *		@param		nosyncmember		0=Synchronize linked member (standard info), 1=Do not synchronize linked member
  *		@param		nosyncmemberpass	0=Synchronize linked member (password), 1=Do not synchronize linked member
  *    	@return     int         		<0 si KO, >=0 si OK
  */
 function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0)
 {
     global $conf, $langs;
     $nbrowsaffected = 0;
     $error = 0;
     dol_syslog("User::update notrigger=" . $notrigger . ", nosyncmember=" . $nosyncmember . ", nosyncmemberpass="******"errors");
         $this->error = $langs->trans("ErrorBadEMail", $this->email);
         return -1;
     }
     $this->db->begin();
     // Mise a jour autres infos
     $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET";
     $sql .= " name = '" . $this->db->escape($this->nom) . "'";
     $sql .= ", firstname = '" . $this->db->escape($this->prenom) . "'";
     $sql .= ", login = '******'";
     $sql .= ", admin = " . $this->admin;
     $sql .= ", office_phone = '" . $this->db->escape($this->office_phone) . "'";
     $sql .= ", office_fax = '" . $this->db->escape($this->office_fax) . "'";
     $sql .= ", user_mobile = '" . $this->db->escape($this->user_mobile) . "'";
     $sql .= ", email = '" . $this->db->escape($this->email) . "'";
     $sql .= ", signature = '" . addslashes($this->signature) . "'";
     $sql .= ", webcal_login = '******'";
     $sql .= ", phenix_login = '******'";
     $sql .= ", phenix_pass = '******'";
     $sql .= ", note = '" . $this->db->escape($this->note) . "'";
     $sql .= ", photo = " . ($this->photo ? "'" . $this->db->escape($this->photo) . "'" : "null");
     $sql .= ", openid = " . ($this->openid ? "'" . $this->db->escape($this->openid) . "'" : "null");
     $sql .= ", entity = '" . $this->entity . "'";
     $sql .= " WHERE rowid = " . $this->id;
     dol_syslog("User::update sql=" . $sql, LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $nbrowsaffected += $this->db->affected_rows($resql);
         // Update password
         if ($this->pass) {
             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, $nosyncmemberpass);
                 if (!$nbrowsaffected) {
                     $nbrowsaffected++;
                 }
             }
         }
         // If user is linked to a member, remove old link to this member
         if ($this->fk_member > 0) {
             $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member = NULL where fk_member = " . $this->fk_member;
             dol_syslog("User::update sql=" . $sql, LOG_DEBUG);
             $resql = $this->db->query($sql);
             if (!$resql) {
                 $this->error = $this->db->error();
                 $this->db->rollback();
                 return -5;
             }
         }
         // Set link to user
         $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member =" . ($this->fk_member > 0 ? $this->fk_member : 'null') . " where rowid = " . $this->id;
         dol_syslog("User::update sql=" . $sql, LOG_DEBUG);
         $resql = $this->db->query($sql);
         if (!$resql) {
             $this->error = $this->db->error();
             $this->db->rollback();
             return -5;
         }
         if ($nbrowsaffected) {
             if ($this->fk_member > 0 && !$nosyncmember) {
                 require_once DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php";
                 // This user is linked with a member, so we also update members informations
                 // if this is an update.
                 $adh = new Adherent($this->db);
                 $result = $adh->fetch($this->fk_member);
                 if ($result >= 0) {
                     $adh->prenom = $this->prenom;
                     $adh->nom = $this->nom;
                     $adh->login = $this->login;
                     $adh->pass = $this->pass;
                     $adh->societe = empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe;
                     $adh->email = $this->email;
                     $adh->phone = $this->office_phone;
                     $adh->phone_mobile = $this->user_mobile;
                     $adh->note = $this->note;
                     $adh->user_id = $this->id;
                     $adh->user_login = $this->login;
                     //$adh->entity=$this->entity;
                     $result = $adh->update($user, 0, 1);
                     if ($result < 0) {
                         $this->error = $luser->error;
                         dol_syslog("User::update " . $this->error, LOG_ERR);
                         $error++;
                     }
                 } else {
                     $this->error = $adh->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('USER_MODIFY', $this, $user, $langs, $conf);
                 if ($result < 0) {
                     $error++;
                     $this->errors = $interface->errors;
                 }
                 // Fin appel triggers
             }
         }
         if (!$error) {
             $this->db->commit();
         } else {
             $this->db->rollback();
         }
         return $nbrowsaffected;
     } else {
         $this->db->rollback();
         $this->error = $this->db->lasterror();
         dol_syslog("User::update " . $this->error, LOG_ERR);
         return -1;
     }
 }
Пример #10
0
			  $langs->load("errors");
			  $error++; $errors[] = $langs->transcountry('ProfId'.$i, $object->country_id)." ".$langs->trans("ErrorProdIdAlreadyExist", $_POST[$slabel]);
			  $action = ($action=='add'?'create':'edit');
			  }
			  }
			  } */
		}
		if (!$error) {
			if ($action == 'add') {
				if (!empty($conf->global->MAIN_FIRST_TO_UPPER))
					$object->name = ucwords($object->name);

				dol_syslog(get_class($object) . "::create " . $object->name);

				// Check parameters
				if (!empty($conf->global->SOCIETE_MAIL_REQUIRED) && !isValidEMail($object->email)) {
					$langs->load("errors");
					$message = $langs->trans("ErrorBadEMail", $object->email);
					return -1;
				}

				$object->tms = dol_now();

				// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
				if ($object->Accounting->CustomCode == -1)
					$compta->setCode("CustomerCode", $object->get_codeclient($object->prefix_comm, 0));
				if ($object->Accounting->SupplierCode == -1)
					$compta->setCode("SupplierCode", $object->get_codefournisseur($object->prefix_comm, 1));

				if (!$message) {
					try {
    /**
     *    Load data control
     */
    function doActions($socid)
    {
        global $conf, $user, $langs;

        if ($_POST["getcustomercode"])
        {
            // We defined value code_client
            $_POST["code_client"]="Acompleter";
        }

        if ($_POST["getsuppliercode"])
        {
            // We defined value code_fournisseur
            $_POST["code_fournisseur"]="Acompleter";
        }

        // Add new third party
        if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
        && ($_POST["action"] == 'add' || $_POST["action"] == 'update'))
        {
            require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
            $error=0;

            if ($_POST["action"] == 'update')
            {
                // Load properties of company
                $this->object->fetch($socid);
            }

            if ($_REQUEST["private"] == 1)
            {
                $this->object->particulier           = $_REQUEST["private"];

                $this->object->nom                   = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
                $this->object->nom_particulier       = $_POST["nom"];
                $this->object->prenom                = $_POST["prenom"];
                $this->object->civilite_id           = $_POST["civilite_id"];
            }
            else
            {
                $this->object->nom                   = $_POST["nom"];
            }

            $this->object->address                  = $_POST["adresse"];
            $this->object->adresse                  = $_POST["adresse"]; // TODO obsolete
            $this->object->cp                       = $_POST["zipcode"];
            $this->object->ville                    = $_POST["town"];
            $this->object->pays_id                  = $_POST["pays_id"];
            $this->object->departement_id           = $_POST["departement_id"];
            $this->object->tel                      = $_POST["tel"];
            $this->object->fax                      = $_POST["fax"];
            $this->object->email                    = trim($_POST["email"]);
            $this->object->url                      = $_POST["url"];
            $this->object->siren                    = $_POST["idprof1"];
            $this->object->siret                    = $_POST["idprof2"];
            $this->object->ape                      = $_POST["idprof3"];
            $this->object->idprof4                  = $_POST["idprof4"];
            $this->object->prefix_comm              = $_POST["prefix_comm"];
            $this->object->code_client              = $_POST["code_client"];
            $this->object->code_fournisseur         = $_POST["code_fournisseur"];
            $this->object->capital                  = $_POST["capital"];
            $this->object->gencod                   = $_POST["gencod"];
            $this->object->canvas                   = $_REQUEST["canvas"];

            $this->object->tva_assuj                = $_POST["assujtva_value"];

            // Local Taxes
            $this->object->localtax1_assuj          = $_POST["localtax1assuj_value"];
            $this->object->localtax2_assuj          = $_POST["localtax2assuj_value"];
            $this->object->tva_intra                = $_POST["tva_intra"];

            $this->object->forme_juridique_code     = $_POST["forme_juridique_code"];
            $this->object->effectif_id              = $_POST["effectif_id"];
            if ($_REQUEST["private"] == 1)
            {
                $this->object->typent_id            = 8; // TODO predict another method if the field "special" change of rowid
            }
            else
            {
                $this->object->typent_id            = $_POST["typent_id"];
            }
            $this->object->client                   = $_POST["client"];
            $this->object->fournisseur              = $_POST["fournisseur"];
            $this->object->fournisseur_categorie    = $_POST["fournisseur_categorie"];

            $this->object->commercial_id            = $_POST["commercial_id"];
            $this->object->default_lang             = $_POST["default_lang"];

            // Check parameters
            if (empty($_POST["cancel"]))
            {
                if (! empty($this->object->email) && ! isValidEMail($this->object->email))
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorBadEMail",$this->object->email);
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
                if (! empty($this->object->url) && ! isValidUrl($this->object->url))
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorBadUrl",$this->object->url);
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
                if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
            }

            if (! $error)
            {
                if ($_POST["action"] == 'add')
                {
                    $this->db->begin();

                    if (empty($this->object->client))      $this->object->code_client='';
                    if (empty($this->object->fournisseur)) $this->object->code_fournisseur='';

                    $result = $this->object->create($user);
                    if ($result >= 0)
                    {
                        if ($this->object->particulier)
                        {
                            dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
                            $contact=new Contact($this->db);

                            $contact->civilite_id   = $this->object->civilite_id;
                            $contact->name          = $this->object->nom_particulier;
                            $contact->firstname     = $this->object->prenom;
                            $contact->address       = $this->object->address;
                            $contact->cp            = $this->object->cp;
                            $contact->ville         = $this->object->ville;
                            $contact->fk_pays       = $this->object->fk_pays;
                            $contact->socid         = $this->object->id;                // fk_soc
                            $contact->status        = 1;
                            $contact->email         = $this->object->email;
                            $contact->priv          = 0;

                            $result=$contact->create($user);
                        }
                    }
                    else
                    {
                        $this->errors=$this->object->errors;
                    }

                    if ($result >= 0)
                    {
                        $this->db->commit();

                        if ( $this->object->client == 1 )
                        {
                            Header("Location: ".DOL_URL_ROOT."/comm/fiche.php?socid=".$this->object->id);
                            return;
                        }
                        else
                        {
                            if (  $this->object->fournisseur == 1 )
                            {
                                Header("Location: ".DOL_URL_ROOT."/fourn/fiche.php?socid=".$this->object->id);
                                return;
                            }
                            else
                            {
                                Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
                                return;
                            }
                        }
                        exit;
                    }
                    else
                    {
                        $this->db->rollback();

                        $this->errors=$this->object->errors;
                        $_GET["action"]='create';
                    }
                }

                if ($_POST["action"] == 'update')
                {
                    if ($_POST["cancel"])
                    {
                        Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
                        exit;
                    }

                    $oldsoccanvas = new Canvas($this->db);
                    $oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas);
                    $result=$oldsoccanvas->control->object->fetch($socid);

                    // To avoid setting code if third party is not concerned. But if it had values, we keep them.
                    if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client))             $this->object->code_client='';
                    if (empty($this->object->fournisseur)&& empty($oldsoccanvas->control->object->code_fournisseur))    $this->object->code_fournisseur='';                    //var_dump($soccanvas);exit;

                    $result = $this->object->update($socid,$user,1,$oldsoccanvas->control->object->codeclient_modifiable(),$oldsoccanvas->control->object->codefournisseur_modifiable());
                    if ($result >= 0)
                    {
                        Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
                        exit;
                    }
                    else
                    {
                        $this->object->id = $socid;
                        $reload = 0;
                        $this->errors = $this->object->errors;
                        $_GET["action"]="edit";
                    }
                }
            }
        }

        if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes')
        {
            $this->object->fetch($socid);

            $result = $this->object->delete($socid);

            if ($result >= 0)
            {
                Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$this->object->nom."");
                exit;
            }
            else
            {
                $reload = 0;
                $this->errors=$this->object->errors;
                $_GET["action"]='';
            }
        }

        /*
         * Generate document
         */
        if (GETPOST('action') == 'builddoc')    // En get ou en post
        {
            if (is_numeric(GETPOST('model')))
            {
                $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
            }
            else
            {
                require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');

                $this->object->fetch($socid);
                $this->object->fetch_thirdparty();

                // Define output language
                $outputlangs = $langs;
                $newlang='';
                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id') ) $newlang=GETPOST('lang_id');
                if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
                if (! empty($newlang))
                {
                    $outputlangs = new Translate("",$conf);
                    $outputlangs->setDefaultLang($newlang);
                }
                $result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model'), $outputlangs);
                if ($result <= 0)
                {
                    dol_print_error($this->db,$result);
                    exit;
                }
                else
                {
                    Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
                    exit;
                }
            }
        }
    }
Пример #12
0
 if ($morphy != 'mor' && empty($lastname)) {
     $error++;
     $langs->load("errors");
     setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname")), null, 'errors');
 }
 if ($morphy != 'mor' && (!isset($firstname) || $firstname == '')) {
     $error++;
     $langs->load("errors");
     setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Firstname")), null, 'errors');
 }
 if (!($typeid > 0)) {
     // Keep () before !
     $error++;
     setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
 }
 if ($conf->global->ADHERENT_MAIL_REQUIRED && !isValidEMail($email)) {
     $error++;
     $langs->load("errors");
     setEventMessages($langs->trans("ErrorBadEMail", $email), null, 'errors');
 }
 $public = 0;
 if (isset($public)) {
     $public = 1;
 }
 if (!$error) {
     $db->begin();
     // Email a peu pres correct et le login n'existe pas
     $result = $object->create($user);
     if ($result > 0) {
         // Categories association
         $memcats = GETPOST('memcats', 'array');
function _createTiers(&$db, &$user, &$ad)
{
    $societe = new Societe($db);
    $name = trim($ad->firstname . ' ' . $ad->lastname);
    if (!empty($name)) {
        $name .= ' / ' . $ad->societe;
    } else {
        $name = $ad->societe;
    }
    $societe->name = $name;
    $societe->client = 1;
    if (!empty($ad->email) && isValidEMail($ad->email)) {
        $societe->email = $ad->email;
    }
    $societe->address = $ad->address;
    $societe->zip = $ad->zip;
    $societe->town = $ad->town;
    $societe->state_id = $ad->state_id;
    $societe->country_id = $ad->country_id;
    $societe->phone = $ad->phone;
    if ($societe->create($user) > 0) {
        $ad->fk_soc = $societe->id;
        return $societe;
    } else {
        return false;
    }
}
Пример #14
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;
		}
	}
 /**
  *  Ajoute destinataires dans table des cibles
  *
  *  @param	int		$mailing_id    	Id of emailing
  *  @param	array	$filtersarray   Requete sql de selection des destinataires
  *  @return int           			< 0 si erreur, nb ajout si ok
  */
 function add_to_target($mailing_id, $filtersarray = array())
 {
     global $conf, $langs, $_FILES;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
     $tmparray = explode(';', GETPOST('xinputuser'));
     $email = $tmparray[0];
     $lastname = $tmparray[1];
     $firstname = $tmparray[2];
     $other = $tmparray[3];
     $cibles = array();
     if (!empty($email)) {
         if (isValidEMail($email)) {
             $cibles[] = array('email' => $email, 'lastname' => $lastname, 'firstname' => $firstname, 'other' => $other, 'source_url' => '', 'source_id' => '', 'source_type' => 'file');
             return parent::add_to_target($mailing_id, $cibles);
         } else {
             $langs->load("errors");
             $this->error = $langs->trans("ErrorBadEMail", $email);
             return -1;
         }
     } else {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorBadEmail", $email);
         return -1;
     }
 }
 /**
  *	Load data control
  *
  *	@param	int		$action	Action code
  *	@return	void
  */
 function doActions(&$action)
 {
     global $conf, $user, $langs;
     if ($_POST["getcustomercode"]) {
         // We defined value code_client
         $_POST["code_client"] = "Acompleter";
     }
     if ($_POST["getsuppliercode"]) {
         // We defined value code_fournisseur
         $_POST["code_fournisseur"] = "Acompleter";
     }
     // Add new third party
     if (!$_POST["getcustomercode"] && !$_POST["getsuppliercode"] && ($action == 'add' || $action == 'update')) {
         require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
         $error = 0;
         if (GETPOST("private") == 1) {
             $this->object->particulier = GETPOST("private");
             $this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? trim($_POST["firstname"] . ' ' . $_POST["lastname"]) : trim($_POST["lastname"] . ' ' . $_POST["firstname"]);
             $this->object->civility_id = $_POST["civility_id"];
             // Add non official properties
             $this->object->name_bis = $_POST["lastname"];
             $this->object->firstname = $_POST["firstname"];
         } else {
             $this->object->name = $_POST["nom"];
         }
         $this->object->address = $_POST["adresse"];
         $this->object->zip = $_POST["zipcode"];
         $this->object->town = $_POST["town"];
         $this->object->country_id = $_POST["country_id"];
         $this->object->state_id = $_POST["state_id"];
         $this->object->phone = $_POST["tel"];
         $this->object->fax = $_POST["fax"];
         $this->object->email = trim($_POST["email"]);
         $this->object->url = $_POST["url"];
         $this->object->idprof1 = $_POST["idprof1"];
         $this->object->idprof2 = $_POST["idprof2"];
         $this->object->idprof3 = $_POST["idprof3"];
         $this->object->idprof4 = $_POST["idprof4"];
         $this->object->prefix_comm = $_POST["prefix_comm"];
         $this->object->code_client = $_POST["code_client"];
         $this->object->code_fournisseur = $_POST["code_fournisseur"];
         $this->object->capital = $_POST["capital"];
         $this->object->barcode = $_POST["barcode"];
         $this->object->canvas = GETPOST("canvas");
         $this->object->tva_assuj = $_POST["assujtva_value"];
         // Local Taxes
         $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
         $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
         $this->object->tva_intra = $_POST["tva_intra"];
         $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
         $this->object->effectif_id = $_POST["effectif_id"];
         if (GETPOST("private") == 1) {
             $this->object->typent_id = dol_getIdFromCode($db, 'TE_PRIVATE', 'c_typent');
         } else {
             $this->object->typent_id = $_POST["typent_id"];
         }
         $this->object->client = $_POST["client"];
         $this->object->fournisseur = $_POST["fournisseur"];
         $this->object->commercial_id = $_POST["commercial_id"];
         $this->object->default_lang = $_POST["default_lang"];
         // Check parameters
         if (empty($_POST["cancel"])) {
             if (!empty($this->object->email) && !isValidEMail($this->object->email)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadEMail", $this->object->email);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if (!empty($this->object->url) && !isValidUrl($this->object->url)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadUrl", $this->object->url);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if ($this->object->fournisseur && !$conf->fournisseur->enabled) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
                 $action = $action == 'add' ? 'create' : 'edit';
             }
         }
         if (!$error) {
             if ($action == 'add') {
                 $this->db->begin();
                 if (empty($this->object->client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->create($user);
                 if ($result >= 0) {
                     if ($this->object->particulier) {
                         dol_syslog(get_class($this) . "::doActions This thirdparty is a personal people", LOG_DEBUG);
                         $contact = new Contact($this->db);
                         $contact->civility_id = $this->object->civility_id;
                         $contact->name = $this->object->name_bis;
                         $contact->firstname = $this->object->firstname;
                         $contact->address = $this->object->address;
                         $contact->zip = $this->object->zip;
                         $contact->town = $this->object->town;
                         $contact->country_id = $this->object->country_id;
                         $contact->socid = $this->object->id;
                         // fk_soc
                         $contact->status = 1;
                         $contact->email = $this->object->email;
                         $contact->priv = 0;
                         $result = $contact->create($user);
                     }
                 } else {
                     $this->errors = $this->object->errors;
                 }
                 if ($result >= 0) {
                     $this->db->commit();
                     if ($this->object->client == 1) {
                         header("Location: " . DOL_URL_ROOT . "/comm/fiche.php?socid=" . $this->object->id);
                         return;
                     } else {
                         if ($this->object->fournisseur == 1) {
                             header("Location: " . DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $this->object->id);
                             return;
                         } else {
                             header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                             return;
                         }
                     }
                     exit;
                 } else {
                     $this->db->rollback();
                     $this->errors = $this->object->errors;
                     $action = 'create';
                 }
             }
             if ($action == 'update') {
                 if ($_POST["cancel"]) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 }
                 $oldsoccanvas = dol_clone($this->object);
                 // To avoid setting code if third party is not concerned. But if it had values, we keep them.
                 if (empty($this->object->client) && empty($oldsoccanvas->code_client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
                 if ($result >= 0) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 } else {
                     $reload = 0;
                     $this->errors = $this->object->errors;
                     $action = "edit";
                 }
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->delete($this->object->id);
         if ($result >= 0) {
             header("Location: " . DOL_URL_ROOT . "/societe/societe.php?delsoc=" . $this->object->nom . "");
             exit;
         } else {
             $reload = 0;
             $this->errors = $this->object->errors;
             $action = '';
         }
     }
     /*
      * Generate document
      */
     if ($action == 'builddoc') {
         if (is_numeric(GETPOST('model'))) {
             $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
         } else {
             require_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php';
             $this->object->fetch_thirdparty();
             // Define output language
             $outputlangs = $langs;
             $newlang = '';
             if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) {
                 $newlang = GETPOST('lang_id');
             }
             if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
                 $newlang = $this->object->default_lang;
             }
             if (!empty($newlang)) {
                 $outputlangs = new Translate("", $conf);
                 $outputlangs->setDefaultLang($newlang);
             }
             $result = thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model', 'alpha'), $outputlangs);
             if ($result <= 0) {
                 dol_print_error($this->db, $result);
                 exit;
             }
         }
     }
 }
Пример #17
0
 /**
  *  	Update a user into database (and also password if this->pass is defined)
  *
  *		@param	User	$user				User qui fait la mise a jour
  *    	@param  int		$notrigger			1 ne declenche pas les triggers, 0 sinon
  *		@param	int		$nosyncmember		0=Synchronize linked member (standard info), 1=Do not synchronize linked member
  *		@param	int		$nosyncmemberpass	0=Synchronize linked member (password), 1=Do not synchronize linked member
  *    	@return int 		        		<0 si KO, >=0 si OK
  */
 function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0)
 {
     global $conf, $langs, $hookmanager;
     $nbrowsaffected = 0;
     $error = 0;
     dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncmember=" . $nosyncmember . ", nosyncmemberpass="******"errors");
         $this->error = $langs->trans("ErrorBadEMail", $this->email);
         return -1;
     }
     if (empty($this->login)) {
         $langs->load("errors");
         $this->error = $langs->trans("ErrorFieldRequired", $this->login);
         return -1;
     }
     $this->db->begin();
     // Update datas
     $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET";
     $sql .= " lastname = '" . $this->db->escape($this->lastname) . "'";
     $sql .= ", firstname = '" . $this->db->escape($this->firstname) . "'";
     $sql .= ", employee = " . $this->employee;
     $sql .= ", login = '******'";
     $sql .= ", api_key = " . ($this->api_key ? "'" . $this->db->escape($this->api_key) . "'" : "null");
     $sql .= ", gender = " . ($this->gender != -1 ? "'" . $this->db->escape($this->gender) . "'" : "null");
     // 'man' or 'woman'
     $sql .= ", admin = " . $this->admin;
     $sql .= ", address = '" . $this->db->escape($this->address) . "'";
     $sql .= ", zip = '" . $this->db->escape($this->zip) . "'";
     $sql .= ", town = '" . $this->db->escape($this->town) . "'";
     $sql .= ", fk_state = " . (!empty($this->state_id) && $this->state_id > 0 ? "'" . $this->db->escape($this->state_id) . "'" : "null");
     $sql .= ", fk_country = " . (!empty($this->country_id) && $this->country_id > 0 ? "'" . $this->db->escape($this->country_id) . "'" : "null");
     $sql .= ", office_phone = '" . $this->db->escape($this->office_phone) . "'";
     $sql .= ", office_fax = '" . $this->db->escape($this->office_fax) . "'";
     $sql .= ", user_mobile = '" . $this->db->escape($this->user_mobile) . "'";
     $sql .= ", email = '" . $this->db->escape($this->email) . "'";
     $sql .= ", skype = '" . $this->db->escape($this->skype) . "'";
     $sql .= ", job = '" . $this->db->escape($this->job) . "'";
     $sql .= ", signature = '" . $this->db->escape($this->signature) . "'";
     $sql .= ", accountancy_code = '" . $this->db->escape($this->accountancy_code) . "'";
     $sql .= ", color = '" . $this->db->escape($this->color) . "'";
     $sql .= ", note = '" . $this->db->escape($this->note) . "'";
     $sql .= ", photo = " . ($this->photo ? "'" . $this->db->escape($this->photo) . "'" : "null");
     $sql .= ", openid = " . ($this->openid ? "'" . $this->db->escape($this->openid) . "'" : "null");
     $sql .= ", fk_user = "******"'" . $this->db->escape($this->fk_user) . "'" : "null");
     if (isset($this->thm) || $this->thm != '') {
         $sql .= ", thm= " . ($this->thm != '' ? "'" . $this->db->escape($this->thm) . "'" : "null");
     }
     if (isset($this->tjm) || $this->tjm != '') {
         $sql .= ", tjm= " . ($this->tjm != '' ? "'" . $this->db->escape($this->tjm) . "'" : "null");
     }
     if (isset($this->salary) || $this->salary != '') {
         $sql .= ", salary= " . ($this->salary != '' ? "'" . $this->db->escape($this->salary) . "'" : "null");
     }
     if (isset($this->salaryextra) || $this->salaryextra != '') {
         $sql .= ", salaryextra= " . ($this->salaryextra != '' ? "'" . $this->db->escape($this->salaryextra) . "'" : "null");
     }
     $sql .= ", weeklyhours= " . ($this->weeklyhours != '' ? "'" . $this->db->escape($this->weeklyhours) . "'" : "null");
     $sql .= ", entity = '" . $this->db->escape($this->entity) . "'";
     $sql .= " WHERE rowid = " . $this->id;
     dol_syslog(get_class($this) . "::update", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $nbrowsaffected += $this->db->affected_rows($resql);
         // Update password
         if ($this->pass) {
             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, $nosyncmemberpass);
                 if (!$nbrowsaffected) {
                     $nbrowsaffected++;
                 }
             }
         }
         // If user is linked to a member, remove old link to this member
         if ($this->fk_member > 0) {
             $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member = NULL where fk_member = " . $this->fk_member;
             dol_syslog(get_class($this) . "::update", LOG_DEBUG);
             $resql = $this->db->query($sql);
             if (!$resql) {
                 $this->error = $this->db->error();
                 $this->db->rollback();
                 return -5;
             }
         }
         // Set link to user
         $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member =" . ($this->fk_member > 0 ? $this->fk_member : 'null') . " where rowid = " . $this->id;
         dol_syslog(get_class($this) . "::update", LOG_DEBUG);
         $resql = $this->db->query($sql);
         if (!$resql) {
             $this->error = $this->db->error();
             $this->db->rollback();
             return -5;
         }
         if ($nbrowsaffected) {
             if ($this->fk_member > 0 && !$nosyncmember) {
                 require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php';
                 // This user is linked with a member, so we also update members informations
                 // if this is an update.
                 $adh = new Adherent($this->db);
                 $result = $adh->fetch($this->fk_member);
                 if ($result >= 0) {
                     $adh->firstname = $this->firstname;
                     $adh->lastname = $this->lastname;
                     $adh->login = $this->login;
                     $adh->gender = $this->gender;
                     $adh->pass = $this->pass;
                     $adh->societe = empty($adh->societe) && $this->societe_id ? $this->societe_id : $adh->societe;
                     $adh->email = $this->email;
                     $adh->skype = $this->skype;
                     $adh->phone = $this->office_phone;
                     $adh->phone_mobile = $this->user_mobile;
                     $adh->note = $this->note;
                     $adh->user_id = $this->id;
                     $adh->user_login = $this->login;
                     $result = $adh->update($user, 0, 1);
                     if ($result < 0) {
                         $this->error = $luser->error;
                         dol_syslog(get_class($this) . "::update " . $this->error, LOG_ERR);
                         $error++;
                     }
                 } else {
                     $this->error = $adh->error;
                     $error++;
                 }
             }
         }
         $action = 'update';
         // Actions on extra fields (by external module or standard code)
         // FIXME le hook fait double emploi avec le trigger !!
         $hookmanager->initHooks(array('userdao'));
         $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)) {
             if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
                 $result = $this->insertExtraFields();
                 if ($result < 0) {
                     $error++;
                 }
             }
         } else {
             if ($reshook < 0) {
                 $error++;
             }
         }
         if (!$error && !$notrigger) {
             // Call trigger
             $result = $this->call_trigger('USER_MODIFY', $user);
             if ($result < 0) {
                 $error++;
             }
             // End call triggers
         }
         if (!$error) {
             $this->db->commit();
             return $nbrowsaffected;
         } else {
             dol_syslog(get_class($this) . "::update error=" . $this->error, LOG_ERR);
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->error = $this->db->lasterror();
         $this->db->rollback();
         return -2;
     }
 }
Пример #18
0
        // Get extra fields
        foreach($_POST as $key => $value)
        {
            if (preg_match("/^options_/",$key))
            {
                $object->array_options[$key]=$_POST[$key];
            }
        }

        if (GETPOST('deletephoto')) $object->logo = '';
        else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);

        // Check parameters
        if (empty($_POST["cancel"]))
        {
            if (! empty($object->email) && ! isValidEMail($object->email))
            {
                $langs->load("errors");
                $error++; $errors[] = $langs->trans("ErrorBadEMail",$object->email);
                $action = ($action=='add'?'create':'edit');
            }
            if (! empty($object->url) && ! isValidUrl($object->url))
            {
                $langs->load("errors");
                $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->url);
                $action = ($action=='add'?'create':'edit');
            }
            if ($object->fournisseur && ! $conf->fournisseur->enabled)
            {
                $langs->load("errors");
                $error++; $errors[] = $langs->trans("ErrorSupplierModuleNotEnabled");
Пример #19
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;
     }
 }