示例#1
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;
     }
 }
示例#2
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;
     }
 }
    /**
     *      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;
        }
    }
示例#4
0
    /**
     * testAdherentUpdate
     *
     * @param	Adherent	$localobject	Member instance
     * @return	Adherent
     *
     * @depends	testAdherentFetch
     * The depends says test is run only if previous is ok
     */
    public function testAdherentUpdate($localobject)
    {
    	global $conf,$user,$langs,$db;
		$conf=$this->savconf;
		$user=$this->savuser;
		$langs=$this->savlangs;
		$db=$this->savdb;

		$localobject->login='******';
		$localobject->societe='New company';
		$localobject->note='New note after update';
		//$localobject->note_public='New note public after update';
		$localobject->lastname='New name';
		$localobject->firstname='New firstname';
		$localobject->address='New address';
		$localobject->zip='New zip';
		$localobject->town='New town';
		$localobject->country_id=2;
		$localobject->statut=0;
		$localobject->phone='New tel pro';
		$localobject->phone_perso='New tel perso';
		$localobject->phone_mobile='New tel mobile';
		$localobject->email='*****@*****.**';
		$result=$localobject->update($user);
		print __METHOD__." id=".$localobject->id." result=".$result."\n";
		$this->assertLessThan($result, 0);
		$result=$localobject->update_note($localobject->note);
		print __METHOD__." id=".$localobject->id." result=".$result."\n";
		$this->assertLessThan($result, 0);
		//$result=$localobject->update_note_public($localobject->note_public);
		//print __METHOD__." id=".$localobject->id." result=".$result."\n";
		//$this->assertLessThan($result, 0);

		$newobject=new Adherent($this->savdb);
		$result=$newobject->fetch($localobject->id);
		print __METHOD__." id=".$localobject->id." result=".$result."\n";
		$this->assertLessThan($result, 0);

		$this->assertEquals($localobject->login, $newobject->login);
		$this->assertEquals($localobject->societe, $newobject->societe);
		$this->assertEquals($localobject->note, $newobject->note);
		//$this->assertEquals($localobject->note_public, $newobject->note_public);
		$this->assertEquals($localobject->lastname, $newobject->lastname);
		$this->assertEquals($localobject->firstname, $newobject->firstname);
		$this->assertEquals($localobject->address, $newobject->address);
		$this->assertEquals($localobject->zip, $newobject->zip);
		$this->assertEquals($localobject->town, $newobject->town);
		$this->assertEquals($localobject->country_id, $newobject->country_id);
		$this->assertEquals('BE', $newobject->country_code);
		$this->assertEquals($localobject->statut, $newobject->statut);
		$this->assertEquals($localobject->phone, $newobject->phone);
		$this->assertEquals($localobject->phone_perso, $newobject->phone_perso);
		$this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile);
		$this->assertEquals($localobject->email, $newobject->email);

    	return $localobject;
    }