Example #1
0
 /**
  *	Constructor
  *
  *  @param		DoliDB		$db      Database handler
  */
 function ExtraFields($db)
 {
     global $conf;
     $this->db = $db;
     $this->error = array();
     parent::__construct($db);
     return 1;
 }
Example #2
0
	/**
	 *    Constructor de la classe
	 *
	 *    @param   DoliDb  $db     Database handler
	 */

	function __construct($db) {
		$this->db = $db;

		parent::__construct($db);

		$fk_extrafields = new ExtraFields($db);
		$this->fk_extrafields = $fk_extrafields->load("extrafields:" . get_class($this), true); // load and cache

		$this->couchAdmin = new couchAdmin($this->couchdb);

		return 0;
	}
 function __construct($db)
 {
     global $couch;
     parent::__construct($db);
     try {
         $this->global = $couch->getDoc("const");
     } catch (Exception $e) {
         dol_print_error('', "Error : no const document in database" . $e->getMessage());
     }
     $fk_extrafields = new ExtraFields($db);
     $this->fk_extrafields = $fk_extrafields->load("extrafields:DolibarrModules", true);
     // load and cache
 }
Example #4
0
 /**
  *  Constructor
  *
  *  @param      DoliDb		$db      Database handler
  */
 function __construct($db)
 {
     global $conf;
     parent::__construct($db);
     $tabMenu = array();
     $topmenu = $this->getView("list", array(), true);
     $submenu = $this->getView("submenu", array(), true);
     $this->topmenu = $topmenu->rows;
     // Construct submenu
     foreach ($submenu->rows as $key => $aRow) {
         $this->submenu[$aRow->key[0]][] = $aRow->value;
     }
     return 1;
 }
Example #5
0
	/**
	 *    Delete a third party from database and all its dependencies (contacts, rib...)
	 *
	 *    @param	int		$id     Id of third party to delete
	 *    @return	int				<0 if KO, 0 if nothing done, >0 if OK
	 */
	function delete($id) {
		global $user, $langs, $conf;
		require_once(DOL_DOCUMENT_ROOT . "/core/lib/files.lib.php");

		dol_syslog(get_class($this) . "::delete", LOG_DEBUG);
		$error = 0;

		// Test if child exists
		//$objectisused = $this->isObjectUsed($this->rowid); // TODO A reactivier
		if (empty($objectisused)) {


			require_once(DOL_DOCUMENT_ROOT . "/categories/class/categorie.class.php");
			$static_cat = new Categorie($this->db);
			$toute_categs = array();

			// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
			if ($this->client || $this->prospect) {
				$toute_categs ['societe'] = $static_cat->containing($this->id, 2);
			}
			if ($this->fournisseur) {
				$toute_categs ['fournisseur'] = $static_cat->containing($this->id, 1);
			}

			// Remove each "Categorie"
			foreach ($toute_categs as $type => $categs_type) {
				foreach ($categs_type as $cat) {
					$cat->del_type($this, $type);
				}
			}

			return parent::delete();

			// TODO Supprimer les contacts
			// Remove contacts
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "socpeople";
				$sql.= " WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error .= $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
				}
			}

			// Update link in member table
			if (!$error) {
				$sql = "UPDATE " . MAIN_DB_PREFIX . "adherent";
				$sql.= " SET fk_soc = NULL WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error .= $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -1 " . $this->error, LOG_ERR);
				}
			}

			// Remove ban
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib";
				$sql.= " WHERE fk_soc = " . $id;
				dol_syslog(get_class($this) . "::Delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error = $this->db->lasterror();
					dol_syslog(get_class($this) . "::Delete erreur -2 " . $this->error, LOG_ERR);
				}
			}

			// Removed extrafields
			//$result=$this->deleteExtraFields($this);
			//if ($result < 0) $error++;

			if (!$error) {
				// Additionnal action by hooks
				include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php');
				$hookmanager = new HookManager($this->db);
				$hookmanager->initHooks(array('thirdparty_extrafields'));
				$parameters = array();
				$action = 'delete';
				$reshook = $hookmanager->executeHooks('deleteThirdparty', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
				if (!empty($hookmanager->error)) {
					$error++;
					$this->error = $hookmanager->error;
				}
			}

			// Remove third party
			if (!$error) {
				$sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe";
				$sql.= " WHERE rowid = " . $id;
				dol_syslog(get_class($this) . "::delete sql=" . $sql, LOG_DEBUG);
				if (!$this->db->query($sql)) {
					$error++;
					$this->error = $this->db->lasterror();
					dol_syslog(get_class($this) . "::delete erreur -3 " . $this->error, LOG_ERR);
				}
			}

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

			if (!$error) {
				$this->db->commit();

				// Delete directory
				$docdir = $conf->societe->multidir_output[$this->entity] . "/" . $id;
				if (file_exists($docdir)) {
					dol_delete_dir_recursive($docdir);
				}

				return 1;
			} else {
				$this->db->rollback();
				return -1;
			}
		}
	}
Example #6
0
 /**
  *    Constructor de la classe
  *
  *    @param   DoliDb  $db     Database handler
  */
 function __construct($db)
 {
     $this->db = $db;
     parent::__construct($db);
 }
Example #7
0
	/**
	 * 	Charge un objet group avec toutes ces caracteristiques (excpet ->members array)
	 *
	 * 	@param      int		$id     id du groupe a charger
	 * 	@return		int				<0 if KO, >0 if OK
	 */
	function load($id, $loaddb = false) {
		global $conf;

		parent::load($id);

		if ($loaddb) {
			$database = new UserDatabase($this->db);
			try {
				$result = $database->couchdb->listDatabases();
			} catch (Exception $exc) {
				print $exc->getMessage();
			}

			foreach ($result as $aRow) {
				if ($aRow[0] != "_") { // Not _users and _replicator
					try {
						$database->fetch($aRow);
						$info = $database->values;
						$secu = $database->couchAdmin->getSecurity();

						foreach ($secu as $key => $type) {
							if (in_array($this->values->name, $type->roles)) {
								if ($key == "admins")
									$info->Administrator = true;

								$this->databases[] = $info;
							}
						}
					} catch (Exception $exc) {
						print $exc->getMessage();
					}
				}
			}
		}

		return 1;
	}
Example #8
0
    /**
     *    Constructor de la classe
     *
     *    @param   DoliDb  $db     Database handler
     */

    function __construct($db) {
        $this->db = $db;

        parent::__construct($db);

        $fk_extrafields = new ExtraFields($db);
        try {
            $this->fk_extrafields = $fk_extrafields->load("extrafields:" . get_class($this), true); // load and cache
        } catch (Exception $e) {
            
        }

        $this->couchAdmin = new couchAdmin($this->couchdb);
        $this->useDatabase("_users");


        // Preference utilisateur
        $this->liste_limit = 0;
        $this->clicktodial_loaded = 0;

        $this->all_permissions_are_loaded = 0;
        $this->admin = 0;

        $this->conf = (object) array();
        $this->rights = (object) array();
        $this->rights->user = (object) array();
        $this->rights->user->user = (object) array();
        $this->rights->user->self = (object) array();
    }
Example #9
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;
     }
 }