--- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_adherent.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_adherent.class.php @@ -10 +10 @@ - * Copyright (C) 2015-2023 Frédéric France + * Copyright (C) 2015-2018 Frédéric France @@ -16,2 +15,0 @@ - * Copyright (C) 2021 Waël Almoman - * Copyright (C) 2021 Philippe Grand @@ -41 +38,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/class/commonpeople.class.php'; @@ -49 +45,0 @@ - use CommonPeople; @@ -67,8 +62,0 @@ - /** - * @var int Does object support extrafields ? 0=No, 1=Yes - */ - public $isextrafieldmanaged = 1; - - /** - * @var string picto - */ @@ -85,3 +73 @@ - /** - * @var string Clear password in memory - */ + //! Clear password in memory @@ -90,3 +76 @@ - /** - * @var string Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0) - */ + //! Clear password in database (defined if DATABASE_PWD_ENCRYPTED=0) @@ -95,3 +79 @@ - /** - * @var string Encrypted password in database (always defined) - */ + //! Encrypted password in database (always defined) @@ -99,12 +80,0 @@ - - /** - * @var string fullname - */ - public $fullname; - - /** - * @var string The civility code, not an integer - */ - public $civility_id; - public $civility_code; - public $civility; @@ -115 +84,0 @@ - * @see $company @@ -125,0 +95,45 @@ + */ + public $fk_soc; + + /** + * @var string Address + */ + public $address; + + /** + * @var string zipcode + */ + public $zip; + + /** + * @var string town + */ + public $town; + + /** + * @var int Id of state + */ + public $state_id; + + /** + * @var string Code of state + */ + public $state_code; + + /** + * @var string Label of state + */ + public $state; + + /** + * @var string email + */ + public $email; + + /** + * @var array array of socialnetworks + */ + public $socialnetworks; + + /** + * @var string skype account @@ -127,13 +141,20 @@ - * @see $socid - */ - public $fk_soc; - - /** - * @var int socid - */ - public $socid; - - /** - * @var array array of socialnetworks - */ - public $socialnetworks; + */ + public $skype; + + /** + * @var string twitter account + * @deprecated + */ + public $twitter; + + /** + * @var string facebook account + * @deprecated + */ + public $facebook; + + /** + * @var string linkedin account + * @deprecated + */ + public $linkedin; @@ -152,5 +172,0 @@ - * @var string Professional Phone number - */ - public $phone_pro; - - /** @@ -171,3 +186,0 @@ - /** - * @var string mor or phy - */ @@ -176,3 +188,0 @@ - /** - * @var int Info can be public - */ @@ -181,9 +191,3 @@ - /** - * Default language code of member (en_US, ...) - * @var string - */ - public $default_lang; - - /** - * @var string photo of member - */ + // -1:brouillon, 0:resilie, >=1:valide,paye + // def in common object + //public $status; @@ -208,3 +211,0 @@ - /** - * @var string gender - */ @@ -225,3 +225,0 @@ - /** - * @var int need_subscription - */ @@ -230,3 +227,0 @@ - /** - * @var int user_id - */ @@ -235,3 +229,0 @@ - /** - * @var string user_login - */ @@ -242,3 +234,3 @@ - - // Fields loaded by fetch_subscriptions() from member table - + // From member table + + // Fields loaded by fetch_subscriptions() @@ -247,4 +238,0 @@ - public $first_subscription_date_start; - - public $first_subscription_date_end; - @@ -264,20 +252,10 @@ - * @var string ip - */ - public $ip; - - // Fields loaded by fetchPartnerships() from partnership table - - public $partnerships = array(); - - /** - * @var Facture To store the created invoice into subscriptionComplementaryActions() - */ - public $invoice; - - - /** - * @var array fields - */ - public $fields = array( - 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10), - 'ref' => array('type' => 'varchar(30)', 'label' => 'Ref', 'default' => 1, 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 12, 'index' => 1), + * @var Adherent To contains a clone of this when we need to save old properties of object + */ + public $oldcopy; + + /** + * @var int Entity + */ + public $entity; + + public $fields = array('rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10), @@ -287,3 +265,4 @@ - 'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'showoncombobox'=>1), - 'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => 1, 'position' => 35, 'showoncombobox'=>1), - 'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => 1, 'position' => 40), + 'lastname' => array('type' => 'varchar(50)', 'label' => 'Lastname', 'enabled' => 1, 'visible' => -1, 'position' => 30), + 'firstname' => array('type' => 'varchar(50)', 'label' => 'Firstname', 'enabled' => 1, 'visible' => -1, 'position' => 35), + 'login' => array('type' => 'varchar(50)', 'label' => 'Login', 'enabled' => 1, 'visible' => -1, 'position' => 40), + 'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 250), @@ -292,4 +271,4 @@ - 'morphy' => array('type' => 'varchar(3)', 'label' => 'MemberNature', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 55), - 'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 60), - 'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => 1, 'position' => 65, 'showoncombobox'=>2), - 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => 1, 'position' => 70), + 'fk_adherent_type' => array('type' => 'integer', 'label' => 'Fk adherent type', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 55), + 'morphy' => array('type' => 'varchar(3)', 'label' => 'MorPhy', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 60), + 'societe' => array('type' => 'varchar(128)', 'label' => 'Societe', 'enabled' => 1, 'visible' => -1, 'position' => 65), + 'fk_soc' => array('type' => 'integer:Societe:societe/class/societe.class.php', 'label' => 'ThirdParty', 'enabled' => 1, 'visible' => -1, 'position' => 70), @@ -300 +279,3 @@ - 'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => 1, 'position' => 95), + 'country' => array('type' => 'integer:Ccountry:core/class/ccountry.class.php', 'label' => 'Country', 'enabled' => 1, 'visible' => -1, 'position' => 95), + 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => -1, 'position' => 100), + 'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 105), @@ -304,5 +285 @@ - 'email' => array('type' => 'varchar(255)', 'label' => 'Email', 'enabled' => 1, 'visible' => 1, 'position' => 126), - 'url' =>array('type'=>'varchar(255)', 'label'=>'Url', 'enabled'=>1, 'visible'=>-1, 'position'=>127), - 'socialnetworks' => array('type' => 'text', 'label' => 'Socialnetworks', 'enabled' => 1, 'visible' => -1, 'position' => 128), - 'birth' => array('type' => 'date', 'label' => 'DateOfBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130), - 'gender' => array('type' => 'varchar(10)', 'label' => 'Gender', 'enabled' => 1, 'visible' => -1, 'position' => 132), + 'birth' => array('type' => 'date', 'label' => 'DateToBirth', 'enabled' => 1, 'visible' => -1, 'position' => 130), @@ -311,4 +288,3 @@ - 'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => 1, 'position' => 150), - 'default_lang' =>array('type'=>'varchar(6)', 'label'=>'Default lang', 'enabled'=>1, 'visible'=>-1, 'position'=> 153), - 'note_public' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155), - 'note_private' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160), + 'datefin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => 1, 'visible' => -1, 'position' => 150), + 'note_private' => array('type' => 'text', 'label' => 'NotePublic', 'enabled' => 1, 'visible' => 0, 'position' => 155), + 'note_public' => array('type' => 'text', 'label' => 'NotePrivate', 'enabled' => 1, 'visible' => 0, 'position' => 160), @@ -322 +298,2 @@ - 'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 500, 'arrayofkeyval' => array(-1 => 'Draft', 1 => 'Validated', 0 => 'MemberStatusResiliatedShort', -2 => 'MemberStatusExcludedShort')), + 'statut' => array('type' => 'smallint(6)', 'label' => 'Statut', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500, + 'arrayofkeyval' => array(0 => 'Draft', 1 => 'Validated', -1 => 'MemberStatusResiliatedShort')), @@ -324,19 +301 @@ - 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805) - ); - - /** - * Draft status - */ - const STATUS_DRAFT = -1; - /** - * Validated status - */ - const STATUS_VALIDATED = 1; - /** - * Resiliated - */ - const STATUS_RESILIATED = 0; - /** - * Excluded - */ - const STATUS_EXCLUDED = -2; + 'import_key' => array('type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'visible' => -2, 'position' => 805)); @@ -353,2 +312 @@ - $this->statut = self::STATUS_DRAFT; - $this->status = self::STATUS_DRAFT; + $this->statut = -1; @@ -377,3 +335 @@ - * @deprecated since V18 - * @see sendEmail() - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -384,24 +339,0 @@ - dol_syslog('Warning using deprecated Adherent::send_an_email', LOG_WARNING); - - return $this->sendEmail($text, $subject, $filename_list, $mimetype_list, $mimefilename_list, $addr_cc, $addr_bcc, $deliveryreceipt, $msgishtml, $errors_to, $moreinheader); - } - - /** - * Function sending an email to the current member with the text supplied in parameter. - * - * @param string $text Content of message (not html entities encoded) - * @param string $subject Subject of message - * @param array $filename_list Array of attached files - * @param array $mimetype_list Array of mime types of attached files - * @param array $mimefilename_list Array of public names of attached files - * @param string $addr_cc Email cc - * @param string $addr_bcc Email bcc - * @param int $deliveryreceipt Ask a delivery receipt - * @param int $msgishtml 1=String IS already html, 0=String IS NOT html, -1=Unknown need autodetection - * @param string $errors_to erros to - * @param string $moreinheader Add more html headers - * @since V18 - * @return int Return integer <0 if KO, >0 if OK - */ - public function sendEmail($text, $subject, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = -1, $errors_to = '', $moreinheader = '') - { @@ -413,6 +345,4 @@ - if (dol_textishtml($text, 0)) { - $msgishtml = 1; - } - } - - dol_syslog('sendEmail msgishtml='.$msgishtml); + if (dol_textishtml($text, 0)) $msgishtml = 1; + } + + dol_syslog('send_an_email msgishtml='.$msgishtml); @@ -422,3 +352 @@ - if ($msgishtml) { - $texttosend = dol_htmlentitiesbr($texttosend); - } + if ($msgishtml) $texttosend = dol_htmlentitiesbr($texttosend); @@ -428,3 +356 @@ - if (getDolGlobalString('ADHERENT_MAIL_FROM')) { - $from = getDolGlobalString('ADHERENT_MAIL_FROM'); - } + if (!empty($conf->global->ADHERENT_MAIL_FROM)) $from = $conf->global->ADHERENT_MAIL_FROM; @@ -459,3 +385 @@ - if (dol_textishtml($text, 1)) { - $msgishtml = 1; - } + if (dol_textishtml($text, 1)) $msgishtml = 1; @@ -464,3 +388 @@ - if ($this->civility_id) { - $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n"; - } + if ($this->civility_id) $infos .= $langs->transnoentities("UserTitle").": ".$this->getCivilityLabel()."\n"; @@ -468 +389,0 @@ - $infos .= $langs->transnoentities("ref").": ".$this->ref."\n"; @@ -480 +401 @@ - if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { + if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) { @@ -489,5 +410 @@ - $substitutionarray = array( - '__ID__' => $this->id, - '__REF__' => $this->ref, - '__MEMBER_ID__' => $this->id, - '__CIVILITY__' => $this->getCivilityLabel(), + $substitutionarray = array('__ID__' => $this->id, '__MEMBER_ID__' => $this->id, '__CIVILITY__' => $this->getCivilityLabel(), @@ -499,2 +416 @@ - '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''), - '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''), + '__ZIP__' => $msgishtml ? dol_htmlentitiesbr($this->zip) : ($this->zip ? $this->zip : ''), '__TOWN__' => $msgishtml ? dol_htmlentitiesbr($this->town) : ($this->town ? $this->town : ''), @@ -502,2 +418 @@ - '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''), - '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''), + '__EMAIL__' => $msgishtml ? dol_htmlentitiesbr($this->email) : ($this->email ? $this->email : ''), '__BIRTH__' => $msgishtml ? dol_htmlentitiesbr($birthday) : ($birthday ? $birthday : ''), @@ -509,3 +424 @@ - '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : ''), - '__TYPE__' => $msgishtml ? dol_htmlentitiesbr($this->type) : ($this->type ? $this->type : '') - ); + '__PHONEMOBILE__' => $msgishtml ? dol_htmlentitiesbr($this->phone_mobile) : ($this->phone_mobile ? $this->phone_mobile : '')); @@ -523 +435,0 @@ - * @param int $addbadge Add badge (1=Full label, 2=First letters only) @@ -526 +438 @@ - public function getmorphylib($morphy = '', $addbadge = 0) + public function getmorphylib($morphy = '') @@ -529,2 +440,0 @@ - - // Clean var @@ -534,34 +444,7 @@ - - if ($addbadge) { - $s = ''; - $labeltoshowm = $langs->trans("Moral"); - $labeltoshowp = $langs->trans("Physical"); - if ($morphy == 'phy') { - $labeltoshow = $labeltoshowp; - if ($addbadge == 2) { - $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp)); - if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowm))) { - $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowp, 2)); - } - } - $s .= ''.$labeltoshow.''; - } - if ($morphy == 'mor') { - $labeltoshow = $labeltoshowm; - if ($addbadge == 2) { - $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm)); - if ($labeltoshow == dol_strtoupper(dolGetFirstLetters($labeltoshowp))) { - $labeltoshow = dol_strtoupper(dolGetFirstLetters($labeltoshowm, 2)); - } - } - $s .= ''.$labeltoshow.''; - } - } else { - if ($morphy == 'phy') { - $s = $langs->trans("Physical"); - } elseif ($morphy == 'mor') { - $s = $langs->trans("Moral"); - } - } - - return $s; + if ($morphy == 'phy') { + return $langs->trans("Physical"); + } + if ($morphy == 'mor') { + return $langs->trans("Moral"); + } + return $morphy; @@ -575 +458 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -579 +462 @@ - global $conf, $langs, $mysoc; + global $conf, $langs; @@ -589 +472 @@ - if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEMail($this->email)) { + if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) { @@ -594,4 +477,2 @@ - if (!$this->datec) { - $this->datec = $now; - } - if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { + if (!$this->datec) $this->datec = $now; + if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) { @@ -608 +489 @@ - $sql .= " (ref, datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key, ip)"; + $sql .= " (datec,login,fk_user_author,fk_user_mod,fk_user_valid,morphy,fk_adherent_type,entity,import_key)"; @@ -610,2 +491 @@ - $sql .= " '(PROV)'"; - $sql .= ", '".$this->db->idate($this->datec)."'"; + $sql .= " '".$this->db->idate($this->datec)."'"; @@ -615 +495 @@ - $sql .= ", ".((int) $this->typeid); + $sql .= ", ".$this->typeid; @@ -618 +497,0 @@ - $sql .= ", ".(!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null"); @@ -627,16 +506 @@ - if (getDolGlobalString('MEMBER_CODEMEMBER_ADDON') == '') { - // keep old numbering - $this->ref = (string) $id; - } else { - // auto code - $modfile = dol_buildpath('core/modules/member/'.getDolGlobalString('MEMBER_CODEMEMBER_ADDON').'.php', 0); - try { - require_once $modfile; - $modname = getDolGlobalString('MEMBER_CODEMEMBER_ADDON'); - $modCodeMember = new $modname(); - $this->ref = $modCodeMember->getNextValue($mysoc, $this); - } catch (Exception $e) { - dol_syslog($e->getMessage(), LOG_ERR); - $error++; - } - } + $this->ref = (string) $id; @@ -655,2 +519,2 @@ - $sql .= " fk_member = ".((int) $this->id); - $sql .= " WHERE rowid = ".((int) $this->user_id); + $sql .= " fk_member = ".$this->id; + $sql .= " WHERE rowid = ".$this->user_id; @@ -706 +570 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -710,3 +574 @@ - global $langs, $hookmanager; - - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + global $conf, $langs, $hookmanager; @@ -717 +579,2 @@ - dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=".$this->email); + dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncuser=".$nosyncuser.", nosyncuserpass=".$nosyncuserpass." nosyncthirdparty=".$nosyncthirdparty.", email=". + $this->email); @@ -727,0 +591,2 @@ + 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)); @@ -730,2 +595 @@ - $this->url = $this->url ? clean_url($this->url, 0) : ''; - $this->setUpperOrLowerCase(); + @@ -733 +597 @@ - if (getDolGlobalString('ADHERENT_MAIL_REQUIRED') && !isValidEMail($this->email)) { + if (!empty($conf->global->ADHERENT_MAIL_REQUIRED) && !isValidEMail($this->email)) { @@ -742,2 +606 @@ - $sql .= " ref = '".$this->db->escape($this->ref)."'"; - $sql .= ", civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null"); + $sql .= " civility = ".($this->civility_id ? "'".$this->db->escape($this->civility_id)."'" : "null"); @@ -749,3 +612 @@ - if ($this->socid) { - $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); // Must be modified only when creating from a third-party - } + $sql .= ", fk_soc = ".($this->socid > 0 ? $this->db->escape($this->socid) : "null"); @@ -758,2 +619 @@ - $sql .= ", url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null"); - $sql .= ", socialnetworks = ".($this->socialnetworks ? "'".$this->db->escape(json_encode($this->socialnetworks))."'" : "null"); + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; @@ -768 +627,0 @@ - $sql .= ", default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null"); @@ -772,7 +631,3 @@ - - if ($this->datefin) { - $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription - } - if ($this->datevalid) { - $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member - } + if ($this->socid) $sql .= ", fk_soc = '".$this->db->escape($this->socid)."'"; // Must be modified only when creating from a third-party + if ($this->datefin) $sql .= ", datefin = '".$this->db->idate($this->datefin)."'"; // Must be modified only when deleting a subscription + if ($this->datevalid) $sql .= ", datevalid = '".$this->db->idate($this->datevalid)."'"; // Must be modified only when validating a member @@ -780 +635 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -786 +641 @@ - $sql2 .= " WHERE rowid = ".((int) $this->typeid); + $sql2 .= " WHERE rowid = ".$this->typeid; @@ -808 +663,2 @@ - if (!$error) { + if (!$error) + { @@ -819 +675 @@ - $isencrypted = !getDolGlobalString('DATABASE_PWD_ENCRYPTED') ? 0 : 1; + $isencrypted = empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1; @@ -823,3 +679 @@ - if (!$nbrowsaffected) { - $nbrowsaffected++; - } + if (!$nbrowsaffected) $nbrowsaffected++; @@ -832 +686 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id); + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; @@ -842 +696 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id)." WHERE rowid = ".((int) $this->user_id); + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id." WHERE rowid = ".$this->user_id; @@ -853 +707,2 @@ - if (!$error && $nbrowsaffected) { // If something has change in main data + if (!$error && $nbrowsaffected) // If something has change in main data + { @@ -868,5 +723,2 @@ - if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) { - $luser->login = $this->login; - } - - $luser->ref = $this->ref; + if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $luser->login = $this->login; + @@ -892,2 +743,0 @@ - - $luser->lang = $this->default_lang; @@ -930 +779,0 @@ - $lthirdparty->default_lang = $this->default_lang; @@ -977 +826 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -987 +836 @@ - $sql .= " WHERE fk_adherent = ".((int) $this->id); + $sql .= " WHERE fk_adherent=".$this->id; @@ -1000 +849 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -1023 +872 @@ - * Fonction to delete a member and its data + * Fonction qui supprime l'adherent et les donnees associees @@ -1026 +875 @@ - * @param User $user User object + * @param User $user User object @@ -1028 +877 @@ - * @return int Return integer <0 if KO, 0=nothing to do, >0 if OK + * @return int <0 if KO, 0=nothing to do, >0 if OK @@ -1031,0 +881,2 @@ + global $conf, $langs; + @@ -1037,3 +888 @@ - if (empty($rowid)) { - $rowid = $this->id; - } + if (empty($rowid)) $rowid = $this->id; @@ -1046,3 +895 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) $error++; @@ -1053 +900 @@ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".((int) $rowid); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_member WHERE fk_member = ".$rowid; @@ -1064 +911 @@ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".((int) $rowid); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE fk_adherent = ".$rowid; @@ -1096 +943 @@ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".((int) $rowid); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent WHERE rowid = ".$rowid; @@ -1152,0 +1000 @@ + //if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) @@ -1158 +1006 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -1181 +1029 @@ - if (is_int($result) && $result < 0) { + if ($result < 0) { @@ -1230 +1078 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".((int) $this->id); + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL WHERE fk_member = ".$this->id; @@ -1241,2 +1089,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".((int) $this->id); - $sql .= " WHERE rowid = ".((int) $userid); + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = ".$this->id; + $sql .= " WHERE rowid = ".$userid; @@ -1273 +1121 @@ - $sql .= " WHERE fk_soc = ".((int) $thirdpartyid); + $sql .= " WHERE fk_soc = '".$thirdpartyid."'"; @@ -1281 +1129 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -1363 +1211 @@ - public function fetch($rowid, $ref = '', $fk_soc = 0, $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true) + public function fetch($rowid, $ref = '', $fk_soc = '', $ref_ext = '', $fetch_optionals = true, $fetch_subscriptions = true) @@ -1367,2 +1215 @@ - $sql = "SELECT d.rowid, d.ref, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname,"; - $sql .= " d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,"; + $sql = "SELECT d.rowid, d.ref_ext, d.civility as civility_code, d.gender, d.firstname, d.lastname, d.societe as company, d.fk_soc, d.statut, d.public, d.address, d.zip, d.town, d.note_private,"; @@ -1370 +1217 @@ - $sql .= " d.email, d.url, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,"; + $sql .= " d.email, d.socialnetworks, d.phone, d.phone_perso, d.phone_mobile, d.login, d.pass, d.pass_crypted,"; @@ -1374 +1221 @@ - $sql .= " d.datefin as datefin, d.default_lang,"; + $sql .= " d.datefin as datefin,"; @@ -1389,3 +1236,3 @@ - if ($rowid) { - $sql .= " AND d.rowid=".((int) $rowid); - } elseif ($ref || $fk_soc) { + if ($rowid) + $sql .= " AND d.rowid=".$rowid; + elseif ($ref || $fk_soc) { @@ -1393,5 +1240,4 @@ - if ($ref) { - $sql .= " AND d.ref='".$this->db->escape($ref)."'"; - } elseif ($fk_soc > 0) { - $sql .= " AND d.fk_soc=".((int) $fk_soc); - } + if ($ref) + $sql .= " AND d.rowid='".$this->db->escape($ref)."'"; + elseif ($fk_soc > 0) + $sql .= " AND d.fk_soc=".$fk_soc; @@ -1408,0 +1255 @@ + $this->ref = $obj->rowid; @@ -1410 +1256,0 @@ - $this->ref = $obj->ref; @@ -1415 +1261 @@ - $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != "Civility".$obj->civility_code ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : ''; + $this->civility = $obj->civility_code ? ($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code) : ''; @@ -1439 +1285 @@ - if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) { + if ($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) @@ -1441 +1287 @@ - } else { + else @@ -1443 +1288,0 @@ - } @@ -1449,3 +1294,2 @@ - $this->url = $obj->url; - - $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks, true) : array()); + + $this->socialnetworks = (array) json_decode($obj->socialnetworks, true); @@ -1455 +1298,0 @@ - $this->status = $obj->statut; @@ -1467,2 +1309,0 @@ - $this->default_lang = $obj->default_lang; - @@ -1482 +1323 @@ - // Retrieve all extrafield + // Retreive all extrafield @@ -1506,6 +1347,5 @@ - * Function to get member subscriptions data: - * subscriptions, - * first_subscription_date, first_subscription_date_start, first_subscription_date_end, first_subscription_amount - * last_subscription_date, last_subscription_date_start, last_subscription_date_end, last_subscription_amount - * - * @return int Return integer <0 if KO, >0 if OK + * Function to get member subscriptions data + * first_subscription_date, first_subscription_date_start, first_subscription_date_end, first_subscription_amount + * last_subscription_date, last_subscription_date_start, last_subscription_date_end, last_subscription_amount + * + * @return int <0 si KO, >0 si OK @@ -1520 +1360 @@ - $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note as note_public, c.fk_bank,"; + $sql = "SELECT c.rowid, c.fk_adherent, c.fk_type, c.subscription, c.note, c.fk_bank,"; @@ -1526 +1366 @@ - $sql .= " WHERE c.fk_adherent = ".((int) $this->id); + $sql .= " WHERE c.fk_adherent = ".$this->id; @@ -1543 +1383 @@ - $this->last_subscription_date_start = $this->db->jdate($obj->dateh); + $this->last_subscription_date_start = $this->db->jdate($obj->datef); @@ -1552,2 +1392 @@ - $subscription->note = $obj->note_public; - $subscription->note_public = $obj->note_public; + $subscription->note = $obj->note; @@ -1573,19 +1411,0 @@ - * Function to get partnerships array - * - * @param string $mode 'member' or 'thirdparty' - * @return int Return integer <0 if KO, >0 if OK - */ - public function fetchPartnerships($mode) - { - global $langs; - - require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php'; - - - $this->partnerships[] = array(); - - return 1; - } - - - /** @@ -1596,3 +1416,3 @@ - * @param int $accountid Id bank account. NOT USED. - * @param string $operation Code of payment mode (if Id bank account provided). Example: 'CB', ... NOT USED. - * @param string $label Label operation (if Id bank account provided). + * @param int $accountid Id bank account + * @param string $operation Type of payment (if Id bank account provided). Example: 'CB', ... + * @param string $label Label operation (if Id bank account provided) @@ -1603 +1422,0 @@ - * @param int $fk_type Member type id @@ -1606 +1425 @@ - public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0, $fk_type = null) + public function subscription($date, $amount, $accountid = 0, $operation = '', $label = '', $num_chq = '', $emetteur_nom = '', $emetteur_banque = '', $datesubend = 0) @@ -1615,3 +1434 @@ - if (!$amount) { - $amount = 0; - } + if (!$amount) $amount = 0; @@ -1637 +1453,0 @@ - $subscription->fk_type = $fk_type; @@ -1660 +1476,2 @@ - $this->setErrorsFromObject($subscription); + $this->error = $subscription->error; + $this->errors = $subscription->errors; @@ -1681,6 +1498,4 @@ - * @param int $autocreatethirdparty Auto create new thirdparty if member not yet linked to a thirdparty and we request an option that generate invoice. - * @param string $ext_payment_id External id of payment (for example Stripe charge id) - * @param string $ext_payment_site Name of external paymentmode (for example 'stripe') - * @return int Return integer <0 if KO, >0 if OK - */ - public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom = '', $emetteur_banque = '', $autocreatethirdparty = 0, $ext_payment_id = '', $ext_payment_site = '') + * @param string $autocreatethirdparty Auto create new thirdparty if member not yet linked to a thirdparty and we request an option that generate invoice. + * @return int <0 if KO, >0 if OK + */ + public function subscriptionComplementaryActions($subscriptionid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom = '', $emetteur_banque = '', $autocreatethirdparty = 0) @@ -1711,2 +1526,2 @@ - $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".((int) $insertid); - $sql .= " WHERE rowid=".((int) $subscriptionid); + $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET fk_bank=".$insertid; + $sql .= " WHERE rowid=".$subscriptionid; @@ -1723 +1538,2 @@ - $this->setErrorsFromObject($acct); + $this->error = $acct->error; + $this->errors = $acct->errors; @@ -1727 +1543,2 @@ - $this->setErrorsFromObject($acct); + $this->error = $acct->error; + $this->errors = $acct->errors; @@ -1740 +1557,2 @@ - if (!($this->fk_soc > 0)) { // If not yet linked to a company + if (!($this->fk_soc > 0)) // If not yet linked to a company + { @@ -1748,3 +1566 @@ - if (!empty($fullname)) { - $companyalias = $fullname; - } + if (!empty($fullname)) $companyalias = $fullname; @@ -1753,3 +1569 @@ - if (!empty($this->company)) { - $companyalias = $this->company; - } + if (!empty($this->company)) $companyalias = $this->company; @@ -1797,2 +1611 @@ - //$invoice->date = $datesubscription; - $invoice->date = dol_now(); + $invoice->date = $datesubscription; @@ -1819,3 +1632 @@ - if (getDolGlobalString('ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS') && (isModEnabled("product") || isModEnabled("service"))) { - $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS; - } + if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled))) $idprodsubscription = $conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS; @@ -1824 +1635 @@ - if (getDolGlobalString('ADHERENT_VAT_FOR_SUBSCRIPTIONS') == 'defaultforfoundationcountry') { + if (isset($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) && $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS == 'defaultforfoundationcountry') { @@ -1862 +1672,0 @@ - $paiement->paiementcode = $operation; @@ -1866,2 +1675,0 @@ - $paiement->ext_payment_id = $ext_payment_id; - $paiement->ext_payment_site = $ext_payment_site; @@ -1872 +1680 @@ - if (!($paiement_id > 0)) { + if (!$paiement_id > 0) { @@ -1891,2 +1699,2 @@ - $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.((int) $bank_line_id); - $sql .= ' WHERE rowid='.((int) $subscriptionid); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'subscription SET fk_bank='.$bank_line_id; + $sql .= ' WHERE rowid='.$subscriptionid; @@ -1902 +1710 @@ - $invoice->setPaid($user); + $invoice->set_paid($user); @@ -1911,6 +1719,2 @@ - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && !empty($lang_id)) { - $newlang = $lang_id; - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $customer->default_lang; - } + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && !empty($lang_id)) $newlang = $lang_id; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $customer->default_lang; @@ -1922,3 +1726,3 @@ - //if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) - - $invoice->generateDocument($invoice->model_pdf, $outputlangs); + //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + + $invoice->generateDocument($invoice->modelpdf, $outputlangs); @@ -1940 +1744 @@ - * @return int Return integer <0 if KO, 0 if nothing done, >0 if OK + * @return int <0 if KO, 0 if nothing done, >0 if OK @@ -1950 +1754 @@ - if ($this->statut == self::STATUS_VALIDATED) { + if ($this->statut == 1) { @@ -1958 +1762 @@ - $sql .= " statut = ".self::STATUS_VALIDATED; + $sql .= " statut = 1"; @@ -1960,2 +1764,2 @@ - $sql .= ", fk_user_valid = ".((int) $user->id); - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= ", fk_user_valid=".$user->id; + $sql .= " WHERE rowid = ".$this->id; @@ -1966 +1770 @@ - $this->statut = self::STATUS_VALIDATED; + $this->statut = 1; @@ -1993 +1797 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2002 +1806 @@ - if ($this->statut == self::STATUS_RESILIATED) { + if ($this->statut == 0) { @@ -2010 +1814 @@ - $sql .= " statut = ".self::STATUS_RESILIATED; + $sql .= " statut = 0"; @@ -2012 +1816 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -2016 +1820 @@ - $this->statut = self::STATUS_RESILIATED; + $this->statut = 0; @@ -2036,47 +1839,0 @@ - /** - * Functiun to exlude (set adherent.status to -2) a member - * TODO - * A private note should be added to know why the member has been excluded - * For historical purpose it add an "extra-subscription" type excluded - * - * @param User $user User making change - * @return int Return integer <0 if KO, >0 if OK - */ - public function exclude($user) - { - $error = 0; - - // Check parameters - if ($this->statut == self::STATUS_EXCLUDED) { - dol_syslog(get_class($this)."::resiliate statut of member does not allow this", LOG_WARNING); - return 0; - } - - $this->db->begin(); - - $sql = "UPDATE ".MAIN_DB_PREFIX."adherent SET"; - $sql .= " statut = ".self::STATUS_EXCLUDED; - $sql .= ", fk_user_valid=".$user->id; - $sql .= " WHERE rowid = ".((int) $this->id); - - $result = $this->db->query($sql); - if ($result) { - $this->statut = self::STATUS_EXCLUDED; - - // Call trigger - $result = $this->call_trigger('MEMBER_EXCLUDE', $user); - if ($result < 0) { - $error++; - $this->db->rollback(); - return -1; - } - // End call triggers - - $this->db->commit(); - return 1; - } else { - $this->error = $this->db->error(); - $this->db->rollback(); - return -1; - } - } @@ -2088 +1845 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2093 +1850 @@ - global $langs; + global $conf, $langs; @@ -2101 +1858 @@ - if (getDolGlobalString('ADHERENT_USE_MAILMAN') && isModEnabled('mailmanspip')) { + if (!empty($conf->global->ADHERENT_USE_MAILMAN) && !empty($conf->mailmanspip->enabled)) { @@ -2105,3 +1862 @@ - if (!empty($mailmanspip->error)) { - $this->errors[] = $mailmanspip->error; - } + if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error; @@ -2121 +1876 @@ - if (getDolGlobalString('ADHERENT_USE_SPIP') && isModEnabled('mailmanspip')) { + if (!empty($conf->global->ADHERENT_USE_SPIP) && !empty($conf->mailmanspip->enabled)) { @@ -2140 +1895 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2153 +1908 @@ - if (getDolGlobalString('ADHERENT_USE_MAILMAN')) { + if (!empty($conf->global->ADHERENT_USE_MAILMAN)) { @@ -2156,3 +1911 @@ - if (!empty($mailmanspip->error)) { - $this->errors[] = $mailmanspip->error; - } + if (!empty($mailmanspip->error)) $this->errors[] = $mailmanspip->error; @@ -2172 +1925 @@ - if ($conf->global->ADHERENT_USE_SPIP && isModEnabled('mailmanspip')) { + if ($conf->global->ADHERENT_USE_SPIP && !empty($conf->mailmanspip->enabled)) { @@ -2199,3 +1952 @@ - if (empty($code)) { - return ''; - } + if (empty($code)) return ''; @@ -2203,58 +1953,0 @@ - } - - /** - * getTooltipContentArray - * @param array $params params to construct tooltip data - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $langs; - - $langs->loadLangs(['members', 'companies']); - $nofetch = !empty($params['nofetch']); - - $datas = array(); - - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $langs->load("users"); - return ['optimize' => $langs->trans("ShowUser")]; - } - if (!empty($this->photo)) { - $photo = '
'; - $photo .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photoref photowithmargin photologintooltip', 'small', 0, 1); - $photo .= '
'; - $datas['photo'] = $photo; - } - - $datas['divopen'] = '
'; - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("Member").' '.$this->getLibStatut(4); - if (!empty($this->morphy)) { - $datas['picto'] .= ' ' . $this->getmorphylib('', 1); - } - if (!empty($this->ref)) { - $datas['ref'] = '
'.$langs->trans('Ref').': '.$this->ref; - } - if (!empty($this->login)) { - $datas['login'] = '
'.$langs->trans('Login').': '.$this->login; - } - if (!empty($this->firstname) || !empty($this->lastname)) { - $datas['name'] = '
'.$langs->trans('Name').': '.$this->getFullName($langs); - } - if (!empty($this->company)) { - $datas['company'] = '
'.$langs->trans('Company').': '.$this->company; - } - if (!empty($this->email)) { - $datas['email'] = '
'.$langs->trans("EMail").': '.$this->email; - } - $datas['address'] = '
'.$langs->trans("Address").': '.dol_format_address($this, 1, ' ', $langs); - // show categories for this record only in ajax to not overload lists - if (isModEnabled('categorie') && !$nofetch) { - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - $form = new Form($this->db); - $datas['categories'] = '
' . $form->showCategories($this->id, Categorie::TYPE_MEMBER, 1); - } - $datas['divclose'] = '
'; - - return $datas; @@ -2269 +1962 @@ - * @param string $mode ''=Show firstname+lastname as label (using default order), 'firstname'=Show only firstname, 'lastname'=Show only lastname, 'login'=Show login, 'ref'=Show ref + * @param string $mode ''=Show firstname+lastname as label (using default order), 'firstname'=Show only firstname, 'login'=Show login, 'ref'=Show ref @@ -2273 +1966 @@ - * @param int $addlinktonotes 1=Add link to notes + * @param int $addlinktonotes 1=Add link to notes @@ -2278,5 +1971,3 @@ - global $conf, $langs, $hookmanager; - - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') && $withpictoimg) { - $withpictoimg = 0; - } + global $conf, $langs; + + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) $withpictoimg = 0; @@ -2284,0 +1976 @@ + $label = ''; @@ -2287,17 +1979,15 @@ - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'option' => $option, - 'nofetch' => 1, - ]; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); - } - - $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.((int) $this->id); + + if (!empty($this->photo)) { + $label .= '
'; + $label .= Form::showphoto('memberphoto', $this, 80, 0, 0, 'photowithmargin photologintooltip', 'small', 0, 1); + $label .= '
'; + } + + $label .= '
'; + $label .= ''.$langs->trans("Member").''; + if (!empty($this->ref)) $label .= '
'.$langs->trans('Ref').': '.$this->ref; + if (!empty($this->firstname) || !empty($this->lastname)) $label .= '
'.$langs->trans('Name').': '.$this->getFullName($langs); + if (!empty($this->company)) $label .= '
'.$langs->trans('Company').': '.$this->company; + $label .= '
'; + + $url = DOL_URL_ROOT.'/adherents/card.php?rowid='.$this->id; @@ -2305 +1995 @@ - $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.((int) $this->id); + $url = DOL_URL_ROOT.'/adherents/subscription.php?rowid='.$this->id; @@ -2311,6 +2001,2 @@ - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; @@ -2322 +2008 @@ - if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -2327,2 +2013,2 @@ - $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"'); - $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"'; + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; @@ -2335,3 +2021 @@ - if ($withpictoimg) { - $result .= '
'; - } + if ($withpictoimg) $result .= '
'; @@ -2340,3 +2024 @@ - if (abs($withpictoimg) == 1 || abs($withpictoimg) == 4) { - $morecss .= ' paddingrightonly'; - } + if (abs($withpictoimg) == 1) $paddafterimage = 'style="margin-right: 3px;"'; @@ -2344,4 +2026,5 @@ - if ($withpictoimg > 0) { - $picto = ''.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : $dataparams), 0, 0, $notooltip ? 0 : 1).''; - } else { - // Picto must be a photo + if ($withpictoimg > 0) + $picto = ''. + img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).''; + // Picto must be a photo + else { @@ -2349 +2032 @@ - $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ? 'small' : ''), 'mini', 0, 1); + $picto .= Form::showphoto('memberphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1); @@ -2354,3 +2037,2 @@ - if (($withpictoimg > -2 && $withpictoimg != 2) || $withpictoimg == -4) { - if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $result .= 'statut) || $this->statut) ? '' : ' strikefordisabled'). @@ -2358,2 +2040 @@ - } - if ($mode == 'login') { + if ($mode == 'login') @@ -2361,12 +2042,7 @@ - } elseif ($mode == 'ref') { - $result .= $this->ref; - } else { - $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : ($mode == 'lastname' ? 4 : -1)), $maxlen); - } - if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) { - $result .= ''; - } - } - if ($withpictoimg) { - $result .= '
'; - } + elseif ($mode == 'ref') + $result .= $this->id; + else + $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : -1), $maxlen); + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) $result .= ''; + } + if ($withpictoimg) $result .= '
'; @@ -2385,9 +2061 @@ - global $action; - $hookmanager->initHooks(array($this->element . 'dao')); - $parameters = array('id'=>$this->id, 'getnomurl' => &$result); - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook > 0) { - $result = $hookmanager->resPrint; - } else { - $result .= $hookmanager->resPrint; - } + @@ -2398 +2066 @@ - * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie, exclu) + * Retourne le libelle du statut d'un adherent (brouillon, valide, resilie) @@ -2428 +2096 @@ - if ($status == self::STATUS_DRAFT) { + if ($status == -1) { @@ -2432,2 +2100,2 @@ - } elseif ($status >= self::STATUS_VALIDATED) { - if ($need_subscription === 0) { + } elseif ($status >= 1) { + if ($need_subscription == 0) { @@ -2439,4 +2107,4 @@ - $labelStatus = $langs->trans("WaitingSubscription"); - $labelStatusShort = $langs->trans("WaitingSubscriptionShort"); - } elseif ($date_end_subscription < dol_now()) { // expired - $statusType = 'status8'; + $labelStatus = $langs->trans("MemberStatusActive"); + $labelStatusShort = $langs->trans("MemberStatusActiveShort"); + } elseif ($date_end_subscription < time()) { + $statusType = 'status3'; @@ -2450 +2118 @@ - } elseif ($status == self::STATUS_RESILIATED) { + } elseif ($status == 0) { @@ -2452,6 +2120,2 @@ - $labelStatus = $langs->transnoentitiesnoconv("MemberStatusResiliated"); - $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusResiliatedShort"); - } elseif ($status == self::STATUS_EXCLUDED) { - $statusType = 'status10'; - $labelStatus = $langs->transnoentitiesnoconv("MemberStatusExcluded"); - $labelStatusShort = $langs->transnoentitiesnoconv("MemberStatusExcludedShort"); + $labelStatus = $langs->trans("MemberStatusResiliated"); + $labelStatusShort = $langs->trans("MemberStatusResiliatedShort"); @@ -2468 +2132 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -2502 +2166 @@ - * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK @@ -2509,3 +2173 @@ - if ($user->socid) { - return -1; // protection pour eviter appel par utilisateur externe - } + if ($user->socid) return -1; // protection pour eviter appel par utilisateur externe @@ -2520 +2182 @@ - $sql .= " AND a.statut = ".self::STATUS_VALIDATED; + $sql .= " AND a.statut = 1"; @@ -2524 +2186 @@ - $sql .= " AND a.statut = ".self::STATUS_DRAFT; + $sql .= " AND a.statut = -1"; @@ -2541 +2203 @@ - $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&statut='.self::STATUS_VALIDATED.'&filter=outofdate'; + $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&statut=1&filter=outofdate'; @@ -2544 +2206 @@ - $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&statut='.self::STATUS_DRAFT; + $url = DOL_URL_ROOT.'/adherents/list.php?mainmenu=members&statut=-1'; @@ -2598,3 +2260,3 @@ - if ($this->model_pdf) { - $modele = $this->model_pdf; - } elseif (getDolGlobalString('ADHERENT_ADDON_PDF')) { + if ($this->modelpdf) { + $modele = $this->modelpdf; + } elseif (!empty($conf->global->ADHERENT_ADDON_PDF)) { @@ -2616 +2278 @@ - * @return int + * @return void @@ -2621 +2282,0 @@ - $now = dol_now(); @@ -2625,2 +2285,0 @@ - $this->ref = 'ABC001'; - $this->entity = 1; @@ -2643,6 +2302 @@ - $this->socialnetworks = array( - 'skype' => 'skypepseudo', - 'twitter' => 'twitterpseudo', - 'facebook' => 'facebookpseudo', - 'linkedin' => 'linkedinpseudo', - ); + $this->socialnetworks = array('skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', 'facebook' => 'facebookpseudo', 'linkedin' => 'linkedinpseudo'); @@ -2652,3 +2306,2 @@ - $this->note_public = 'This is a public note'; - $this->note_private = 'This is a private note'; - $this->birth = $now; + $this->note_private = 'No comment'; + $this->birth = time(); @@ -2657,5 +2310,4 @@ - $this->statut = self::STATUS_DRAFT; - - $this->datefin = $now; - $this->datevalid = $now; - $this->default_lang = ''; + $this->statut = 0; + + $this->datefin = time(); + $this->datevalid = time(); @@ -2667 +2319 @@ - $this->first_subscription_date = $now; + $this->first_subscription_date = time(); @@ -2676 +2327,0 @@ - return 1; @@ -2696,9 +2347,3 @@ - if ($mode == 0) { - $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]."," . getDolGlobalString('LDAP_MEMBER_DN'); - } - if ($mode == 1) { - $dn = $conf->global->LDAP_MEMBER_DN; - } - if ($mode == 2) { - $dn = getDolGlobalString('LDAP_KEY_MEMBERS') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS')]; - } + if ($mode == 0) $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS].",".$conf->global->LDAP_MEMBER_DN; + if ($mode == 1) $dn = $conf->global->LDAP_MEMBER_DN; + if ($mode == 2) $dn = $conf->global->LDAP_KEY_MEMBERS."=".$info[$conf->global->LDAP_KEY_MEMBERS]; @@ -2722 +2366,0 @@ - $socialnetworks = getArrayOfSocialNetworks(); @@ -2726 +2370 @@ - $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_OBJECT_CLASS')); + $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_OBJECT_CLASS); @@ -2737,7 +2381,2 @@ - $ldapkey = array( - 'LDAP_MEMBER_FIELD_FULLNAME' => 'fullname', - 'LDAP_MEMBER_FIELD_NAME' => 'lastname', - 'LDAP_MEMBER_FIELD_LOGIN' => 'login', - 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login', - 'LDAP_MEMBER_FIELD_MAIL' => 'email' - ); + $ldapkey = array('LDAP_MEMBER_FIELD_FULLNAME' => 'fullname', 'LDAP_MEMBER_FIELD_NAME' => 'lastname', 'LDAP_MEMBER_FIELD_LOGIN' => 'login', 'LDAP_MEMBER_FIELD_LOGIN_SAMBA' => 'login', + 'LDAP_MEMBER_FIELD_MAIL' => 'email'); @@ -2747,2 +2386,2 @@ - if (!empty($this->$varname) && getDolGlobalString($constname)) { - $info[getDolGlobalString($constname)] = $this->$varname; + if (!empty($this->$varname) && !empty($conf->global->$constname)) { + $info[$conf->global->$constname] = $this->$varname; @@ -2751,60 +2390,25 @@ - if (getDolGlobalString('LDAP_KEY_MEMBERS') && getDolGlobalString('LDAP_KEY_MEMBERS') == getDolGlobalString($constname)) { - if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) { - $keymodified = true; // For check if LDAP key has been modified - } - } - } - } - if ($this->firstname && getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_FIRSTNAME')] = $this->firstname; - } - if ($this->poste && getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_TITLE')] = $this->poste; - } - if ($this->company && getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_COMPANY')] = $this->company; - } - if ($this->address && getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_ADDRESS')] = $this->address; - } - if ($this->zip && getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_ZIP')] = $this->zip; - } - if ($this->town && getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_TOWN')] = $this->town; - } - if ($this->country_code && getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_COUNTRY')] = $this->country_code; - } - foreach ($socialnetworks as $key => $value) { - if ($this->socialnetworks[$value['label']] && getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_'.strtoupper($value['label']))] = $this->socialnetworks[$value['label']]; - } - } - if ($this->phone && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE')] = $this->phone; - } - if ($this->phone_perso && getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PHONE_PERSO')] = $this->phone_perso; - } - if ($this->phone_mobile && getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_MOBILE')] = $this->phone_mobile; - } - if ($this->fax && getDolGlobalString('LDAP_MEMBER_FIELD_FAX')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_FAX')] = $this->fax; - } - if ($this->note_private && getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_private, 2); - } - if ($this->note_public && getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_NOTE_PUBLIC')] = dol_string_nohtmltag($this->note_public, 2); - } - if ($this->birth && getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_BIRTHDATE')] = dol_print_date($this->birth, 'dayhourldap'); - } - if (isset($this->statut) && getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_STATUS')] = $this->statut; - } - if ($this->datefin && getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION')] = dol_print_date($this->datefin, 'dayhourldap'); - } + if (!empty($conf->global->LDAP_KEY_MEMBERS) && $conf->global->LDAP_KEY_MEMBERS == $conf->global->$constname) { + if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) $keymodified = true; // For check if LDAP key has been modified + } + } + } + if ($this->firstname && !empty($conf->global->LDAP_MEMBER_FIELD_FIRSTNAME)) $info[$conf->global->LDAP_MEMBER_FIELD_FIRSTNAME] = $this->firstname; + if ($this->poste && !empty($conf->global->LDAP_MEMBER_FIELD_TITLE)) $info[$conf->global->LDAP_MEMBER_FIELD_TITLE] = $this->poste; + if ($this->company && !empty($conf->global->LDAP_MEMBER_FIELD_COMPANY)) $info[$conf->global->LDAP_MEMBER_FIELD_COMPANY] = $this->company; + if ($this->address && !empty($conf->global->LDAP_MEMBER_FIELD_ADDRESS)) $info[$conf->global->LDAP_MEMBER_FIELD_ADDRESS] = $this->address; + if ($this->zip && !empty($conf->global->LDAP_MEMBER_FIELD_ZIP)) $info[$conf->global->LDAP_MEMBER_FIELD_ZIP] = $this->zip; + if ($this->town && !empty($conf->global->LDAP_MEMBER_FIELD_TOWN)) $info[$conf->global->LDAP_MEMBER_FIELD_TOWN] = $this->town; + if ($this->country_code && !empty($conf->global->LDAP_MEMBER_FIELD_COUNTRY)) $info[$conf->global->LDAP_MEMBER_FIELD_COUNTRY] = $this->country_code; + if ($this->skype && !empty($conf->global->LDAP_MEMBER_FIELD_SKYPE)) $info[$conf->global->LDAP_MEMBER_FIELD_SKYPE] = $this->skype; + if ($this->twitter && !empty($conf->global->LDAP_MEMBER_FIELD_TWITTER)) $info[$conf->global->LDAP_MEMBER_FIELD_TWITTER] = $this->twitter; + if ($this->facebook && !empty($conf->global->LDAP_MEMBER_FIELD_FACEBOOK)) $info[$conf->global->LDAP_MEMBER_FIELD_FACEBOOK] = $this->facebook; + if ($this->linkedin && !empty($conf->global->LDAP_MEMBER_FIELD_LINKEDIN)) $info[$conf->global->LDAP_MEMBER_FIELD_LINKEDIN] = $this->linkedin; + if ($this->phone && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE] = $this->phone; + if ($this->phone_perso && !empty($conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO)) $info[$conf->global->LDAP_MEMBER_FIELD_PHONE_PERSO] = $this->phone_perso; + if ($this->phone_mobile && !empty($conf->global->LDAP_MEMBER_FIELD_MOBILE)) $info[$conf->global->LDAP_MEMBER_FIELD_MOBILE] = $this->phone_mobile; + if ($this->fax && !empty($conf->global->LDAP_MEMBER_FIELD_FAX)) $info[$conf->global->LDAP_MEMBER_FIELD_FAX] = $this->fax; + if ($this->note_private && !empty($conf->global->LDAP_MEMBER_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note_private, 2); + if ($this->note_public && !empty($conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC)) $info[$conf->global->LDAP_MEMBER_FIELD_NOTE_PUBLIC] = dol_string_nohtmltag($this->note_public, 2); + if ($this->birth && !empty($conf->global->LDAP_MEMBER_FIELD_BIRTHDATE)) $info[$conf->global->LDAP_MEMBER_FIELD_BIRTHDATE] = dol_print_date($this->birth, 'dayhourldap'); + if (isset($this->statut) && !empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) $info[$conf->global->LDAP_FIELD_MEMBER_STATUS] = $this->statut; + if ($this->datefin && !empty($conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)) $info[$conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION] = dol_print_date($this->datefin, 'dayhourldap'); @@ -2814,13 +2418,9 @@ - if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass; // this->pass = mot de passe non crypte - } - if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE) - } - } elseif (getDolGlobalString('LDAP_SERVER_PROTOCOLVERSION') !== '3') { - // Set LDAP password if possible - // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password - if (getDolGlobalString('DATABASE_PWD_ENCRYPTED')) { // This should be on on default installation - // Just for the case we use old md5 encryption (deprecated, no more used, kept for compatibility) - if (!getDolGlobalString('MAIN_SECURITY_HASH_ALGO') || getDolGlobalString('MAIN_SECURITY_HASH_ALGO') == 'md5') { - if ($this->pass_indatabase_crypted && getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) { + if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass; // this->pass = mot de passe non crypte + if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass, 4); // Create OpenLDAP MD5 password (TODO add type of encryption) + } // Set LDAP password if possible + elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !== '3') // If ldap key is modified and LDAPv3 we use ldap_rename function for avoid lose encrypt password + { + if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) { + // Just for the default MD5 ! + if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) { + if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) { @@ -2828,2 +2428,2 @@ - // Note: This suppose that "pass_indatabase_crypted" is a md5 (this should not happen anymore)" - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dolGetLdapPasswordHash($this->pass_indatabase_crypted, 'md5frommd5'); + // Note: This suppose that "pass_indatabase_crypted" is a md5 (guaranted by the previous test if "(empty($conf->global->MAIN_SECURITY_HASH_ALGO))" + $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = '{md5}'.base64_encode(hex2bin($this->pass_indatabase_crypted)); @@ -2832,8 +2432,4 @@ - } elseif (!empty($this->pass_indatabase)) { - // Use $this->pass_indatabase value if exists - if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD')] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte - } - if (getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')) { - $info[getDolGlobalString('LDAP_MEMBER_FIELD_PASSWORD_CRYPTED')] = dol_hash($this->pass_indatabase, 'openldap'); // Create OpenLDAP password (see LDAP_PASSWORD_HASH_TYPE) - } + } // Use $this->pass_indatabase value if exists + elseif (!empty($this->pass_indatabase)) { + if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD] = $this->pass_indatabase; // $this->pass_indatabase = mot de passe non crypte + if (!empty($conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED)) $info[$conf->global->LDAP_MEMBER_FIELD_PASSWORD_CRYPTED] = dol_hash($this->pass_indatabase, 4); // md5 for OpenLdap TODO add type of encryption @@ -2844,12 +2440,4 @@ - if ($this->first_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE')] = dol_print_date($this->first_subscription_date, 'dayhourldap'); - } - if (isset($this->first_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT')] = $this->first_subscription_amount; - } - if ($this->last_subscription_date && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE')] = dol_print_date($this->last_subscription_date, 'dayhourldap'); - } - if (isset($this->last_subscription_amount) && getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')) { - $info[getDolGlobalString('LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT')] = $this->last_subscription_amount; - } + if ($this->first_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE] = dol_print_date($this->first_subscription_date, 'dayhourldap'); + if (isset($this->first_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT] = $this->first_subscription_amount; + if ($this->last_subscription_date && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE] = dol_print_date($this->last_subscription_date, 'dayhourldap'); + if (isset($this->last_subscription_amount) && !empty($conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT)) $info[$conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT] = $this->last_subscription_amount; @@ -2874 +2462 @@ - $sql .= ' WHERE a.rowid = '.((int) $id); + $sql .= ' WHERE a.rowid = '.$id; @@ -2881 +2468,0 @@ - @@ -2883,4 +2470,18 @@ - - $this->user_creation_id = $obj->fk_user_author; - $this->user_validation_id = $obj->fk_user_valid; - $this->user_modification_id = $obj->fk_user_mod; + if ($obj->fk_user_author) { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_author); + $this->user_creation = $cuser; + } + + if ($obj->fk_user_valid) { + $vuser = new User($this->db); + $vuser->fetch($obj->fk_user_valid); + $this->user_validation = $vuser; + } + + if ($obj->fk_user_mod) { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_mod); + $this->user_modification = $muser; + } + @@ -2930,2 +2531,2 @@ - * @param int[]|int $categories Category or categories IDs - * @return int Return integer <0 if KO, >0 if OK + * @param int[]|int $categories Category or categories IDs + * @return void @@ -2934,0 +2536,6 @@ + // Handle single category + if (!is_array($categories)) { + $categories = array($categories); + } + + // Get current categories @@ -2936 +2543,25 @@ - return parent::setCategoriesCommon($categories, Categorie::TYPE_MEMBER); + $c = new Categorie($this->db); + $existing = $c->containing($this->id, Categorie::TYPE_MEMBER, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach ($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, Categorie::TYPE_MEMBER); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, Categorie::TYPE_MEMBER); + } + } + + return; @@ -2964,6 +2595,2 @@ - if ($this->statut != self::STATUS_VALIDATED) { - return false; - } - if (!$this->datefin) { - return false; - } + if ($this->statut <= 0) return false; + if (!$this->datefin) return false; @@ -2994 +2621,2 @@ - if (!isModEnabled('adherent')) { // Should not happen. If module disabled, cron job should not be visible. + if (empty($conf->adherent->enabled)) // Should not happen. If module disabled, cron job should not be visible. + { @@ -2999 +2627 @@ - if (!getDolGlobalString('MEMBER_REMINDER_EMAIL')) { + if (empty($conf->global->MEMBER_REMINDER_EMAIL)) { @@ -3013 +2641,2 @@ - foreach ($arraydaysbeforeend as $daysbeforeend) { // Loop on each delay + foreach ($arraydaysbeforeend as $daysbeforeend) // Loop on each delay + { @@ -3017 +2646 @@ - $blockingerrormsg = "Value for delta is not a numeric value"; + $blockingerrormsg = "Value for delta is not a positive or negative numeric"; @@ -3023 +2652 @@ - $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year'], 'tzserver'), $daysbeforeend, 'd'); + $datetosearchfor = dol_time_plus_duree(dol_mktime(0, 0, 0, $tmp['mon'], $tmp['mday'], $tmp['year']), $daysbeforeend, 'd'); @@ -3026,2 +2655 @@ - $sql .= " WHERE entity = ".((int) $conf->entity); // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only; - $sql .= " AND statut = 1"; + $sql .= " WHERE entity = ".$conf->entity; // Do not use getEntity('adherent').")" here, we want the batch to be on its entity only; @@ -3029 +2656,0 @@ - //$sql .= " LIMIT 10000"; @@ -3062,5 +2689,3 @@ - $labeltouse = getDolGlobalString('ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION'); - - if (!empty($labeltouse)) { - $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse); - } + $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_REMIND_EXPIRATION; + + if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($this->db, 'member', $user, $outputlangs, 0, 1, $labeltouse); @@ -3075 +2700 @@ - $from = getDolGlobalString('ADHERENT_MAIL_FROM'); + $from = $conf->global->ADHERENT_MAIL_FROM; @@ -3077 +2701,0 @@ - $cc = getDolGlobalString('ADHERENT_CC_MAIL_FROM'); @@ -3083 +2707 @@ - $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), $cc, '', 0, 1, '', '', $trackid, $moreinheader); + $cmail = new CMailFile($subject, $to, $from, $msg, array(), array(), array(), '', '', 0, 1, '', '', $trackid, $moreinheader); @@ -3087 +2711 @@ - $this->error .= $cmail->error.' '; + $this->error = $cmail->error; @@ -3105 +2729,2 @@ - $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '.CMailFile::getValidAddress($sendto, 4, 0, 1); + $actionmsg2 = $langs->transnoentities('MailSentBy').' '.CMailFile::getValidAddress($from, 4, 0, 1).' '.$langs->transnoentities('To').' '. + CMailFile::getValidAddress($sendto, 4, 0, 1); @@ -3109,3 +2734 @@ - if ($sendtocc) { - $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); - } + if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc').": ".dol_escape_htmltag($sendtocc)); @@ -3131 +2754 @@ - $actioncomm->contact_id = 0; + $actioncomm->contactid = 0; @@ -3152,4 +2775 @@ - //$blockingerrormsg = "Can't find email template with label=".$labeltouse.", to use for the reminding email"; - - $error++; - $this->error .= "Can't find email template with label=".$labeltouse.", to use for the reminding email "; + $blockingerrormsg = "Can't find email template, defined into member module setup, to use for reminding"; @@ -3186 +2806 @@ - if (empty($listofids)) { + if (empty($listofids)) @@ -3188 +2808 @@ - } else { + else @@ -3190 +2809,0 @@ - } @@ -3194,5 +2813,2 @@ - if ($listofids) { - $listofids .= ']'; - } - - $this->output .= ($listofids ? ' ids='.$listofids : ''); + if ($listofids) $listofids .= ']'; + $this->output .= $listofids; @@ -3210 +2826 @@ - if (empty($listofids)) { + if (empty($listofids)) @@ -3212 +2828 @@ - } else { + else @@ -3214 +2829,0 @@ - } @@ -3218,49 +2833,7 @@ - if ($listofids) { - $listofids .= ']'; - } - $this->output .= ($listofids ? ' ids='.$listofids : ''); - } - } - } - - return $nbko; - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - if (property_exists($this, 'photo') || !empty($this->photo)) { - $return.= Form::showphoto('memberphoto', $this, 0, 60, 0, 'photokanban photoref photowithmargin photologintooltip', 'small', 0, 1); - } else { - $return .= img_picto('', 'user'); - } - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'type')) { - $return .= '
'.$this->type.''; - } - if (method_exists($this, 'getmorphylib')) { - $return .= '
'.$this->getmorphylib('', 2).''; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; + if ($listofids) $listofids .= ']'; + $this->output .= $listofids; + } + } + } + + return 0; --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_adherent_type.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_adherent_type.class.php @@ -7 +6,0 @@ - * Copyright (C) 2021 Waël Almoman @@ -50 +49 @@ - public $picto = 'members'; + public $picto = 'group'; @@ -66,20 +65,20 @@ - * @var string Adherent type label - */ - public $label; - - /** - * @var string Adherent type nature - */ - public $morphy; - - public $duration; - - /** - * type expiration - */ - public $duration_value; - - /** - * Expiration unit - */ - public $duration_unit; + * @var string Adherent type label + */ + public $label; + + /** + * @var string Adherent type nature + */ + public $morphy; + + public $duration; + + /* + * type expiration + */ + public $duration_value; + + /** + * Expiration unit + */ + public $duration_unit; @@ -88,0 +88 @@ + * @since 5.0 @@ -92,14 +92 @@ - /** - * @var float|string Amount for subscription (null or '' means not defined) - */ - public $amount; - - /** - * @var int Amount can be choosen by the visitor during subscription (0 or 1) - */ - public $caneditamount; - - /** - * @var string Public note - * @deprecated - */ + /** @var string Public note */ @@ -107,3 +93,0 @@ - - /** @var string Public note */ - public $note_public; @@ -114 +98 @@ - /** @var string Email sent during validation of member */ + /** @var string Email sent during validation */ @@ -116,9 +99,0 @@ - - /** @var string Email sent after recording a new subscription */ - public $mail_subscription = ''; - - /** @var string Email sent after resiliation */ - public $mail_resiliate = ''; - - /** @var string Email sent after exclude */ - public $mail_exclude = ''; @@ -129,17 +104 @@ - /** @var string string other */ - public $other = array(); - - /** - * @var string description - */ - public $description; - - /** - * @var string email - */ - public $email; - - /** - * @var array multilangs - */ - public $multilangs = array(); + public $multilangs = array(); @@ -156,158 +115,175 @@ - $this->status = 1; - } - - /** - * Load array this->multilangs - * - * @return int Return integer <0 if KO, >0 if OK - */ - public function getMultiLangs() - { - global $langs; - - $current_lang = $langs->getDefaultLang(); - - $sql = "SELECT lang, label, description, email"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql .= " WHERE fk_type = ".((int) $this->id); - - $result = $this->db->query($sql); - if ($result) { - while ($obj = $this->db->fetch_object($result)) { - //print 'lang='.$obj->lang.' current='.$current_lang.'
'; - if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales. - $this->label = $obj->label; - $this->description = $obj->description; - $this->email = $obj->email; - } - $this->multilangs["$obj->lang"]["label"] = $obj->label; - $this->multilangs["$obj->lang"]["description"] = $obj->description; - $this->multilangs["$obj->lang"]["email"] = $obj->email; - } - return 1; - } else { - $this->error = "Error: ".$this->db->lasterror()." - ".$sql; - return -1; - } - } - - /** - * Update or add a translation for this member type - * - * @param User $user Object user making update - * @return int Return integer <0 if KO, >0 if OK - */ - public function setMultiLangs($user) - { - global $conf, $langs; - - $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2); - $current_lang = $langs->getDefaultLang(); - - foreach ($langs_available as $key => $value) { - if ($key == $current_lang) { - $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql .= " WHERE fk_type = ".((int) $this->id); - $sql .= " AND lang = '".$this->db->escape($key)."'"; - - $result = $this->db->query($sql); - - if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql2 .= " SET"; - $sql2 .= " label = '".$this->db->escape($this->label)."',"; - $sql2 .= " description = '".$this->db->escape($this->description)."'"; - $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'"; - } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; - $sql2 .= ")"; - $sql2 .= " VALUES(".((int) $this->id).",'".$this->db->escape($key)."','".$this->db->escape($this->label)."',"; - $sql2 .= " '".$this->db->escape($this->description)."'"; - $sql2 .= ")"; - } - dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key); - if (!$this->db->query($sql2)) { - $this->error = $this->db->lasterror(); - return -1; - } - } elseif (isset($this->multilangs[$key])) { - $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql .= " WHERE fk_type = ".((int) $this->id); - $sql .= " AND lang = '".$this->db->escape($key)."'"; - - $result = $this->db->query($sql); - - if ($this->db->num_rows($result)) { // if there is already a description line for this language - $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql2 .= " SET "; - $sql2 .= " label = '".$this->db->escape($this->multilangs["$key"]["label"])."',"; - $sql2 .= " description = '".$this->db->escape($this->multilangs["$key"]["description"])."'"; - $sql2 .= " WHERE fk_type = ".((int) $this->id)." AND lang='".$this->db->escape($key)."'"; - } else { - $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; - $sql2 .= ")"; - $sql2 .= " VALUES(".$this->id.",'".$this->db->escape($key)."','".$this->db->escape($this->multilangs["$key"]["label"])."',"; - $sql2 .= " '".$this->db->escape($this->multilangs["$key"]["description"])."'"; - $sql2 .= ")"; - } - - // We do not save if main fields are empty - if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) { - if (!$this->db->query($sql2)) { - $this->error = $this->db->lasterror(); - return -1; - } - } - } else { - // language is not current language and we didn't provide a multilang description for this language - } - } - - // Call trigger - $result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user); - if ($result < 0) { - $this->error = $this->db->lasterror(); - return -1; - } - // End call triggers - - return 1; - } - - /** - * Delete a language for this member type - * - * @param string $langtodelete Language code to delete - * @param User $user Object user making delete - * @return int Return integer <0 if KO, >0 if OK - */ - public function delMultiLangs($langtodelete, $user) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang"; - $sql .= " WHERE fk_type = ".((int) $this->id)." AND lang = '".$this->db->escape($langtodelete)."'"; - - dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - // Call trigger - $result = $this->call_trigger('MEMBER_TYPE_DEL_MULTILANGS', $user); - if ($result < 0) { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); - return -1; - } - // End call triggers - return 1; - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); - return -1; - } - } - - /** - * Function to create the member type - * - * @param User $user User making creation + $this->statut = 1; + } + + /** + * Load array this->multilangs + * + * @return int <0 if KO, >0 if OK + */ + public function getMultiLangs() + { + global $langs; + + $current_lang = $langs->getDefaultLang(); + + $sql = "SELECT lang, label, description, email"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql .= " WHERE fk_type=".$this->id; + + $result = $this->db->query($sql); + if ($result) { + while ($obj = $this->db->fetch_object($result)) + { + //print 'lang='.$obj->lang.' current='.$current_lang.'
'; + if ($obj->lang == $current_lang) // si on a les traduct. dans la langue courante on les charge en infos principales. + { + $this->label = $obj->label; + $this->description = $obj->description; + $this->email = $obj->email; + } + $this->multilangs["$obj->lang"]["label"] = $obj->label; + $this->multilangs["$obj->lang"]["description"] = $obj->description; + $this->multilangs["$obj->lang"]["email"] = $obj->email; + } + return 1; + } + else + { + $this->error = "Error: ".$this->db->lasterror()." - ".$sql; + return -1; + } + } + + /** + * Update or add a translation for a product + * + * @param User $user Object user making update + * @return int <0 if KO, >0 if OK + */ + public function setMultiLangs($user) + { + global $conf, $langs; + + $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2); + $current_lang = $langs->getDefaultLang(); + + foreach ($langs_available as $key => $value) + { + if ($key == $current_lang) { + $sql = "SELECT rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql .= " WHERE fk_type=".$this->id; + $sql .= " AND lang='".$key."'"; + + $result = $this->db->query($sql); + + if ($this->db->num_rows($result)) // if there is already a description line for this language + { + $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql2 .= " SET "; + $sql2 .= " label='".$this->db->escape($this->label)."',"; + $sql2 .= " description='".$this->db->escape($this->description)."'"; + $sql2 .= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'"; + } + else + { + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; + $sql2 .= ")"; + $sql2 .= " VALUES(".$this->id.",'".$this->db->escape($key)."','".$this->db->escape($this->label)."',"; + $sql2 .= " '".$this->db->escape($this->description)."'"; + $sql2 .= ")"; + } + dol_syslog(get_class($this).'::setMultiLangs key = current_lang = '.$key); + if (!$this->db->query($sql2)) { + $this->error = $this->db->lasterror(); + return -1; + } + } + elseif (isset($this->multilangs[$key])) { + $sql = "SELECT rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql .= " WHERE fk_type=".$this->id; + $sql .= " AND lang='".$key."'"; + + $result = $this->db->query($sql); + + if ($this->db->num_rows($result)) // if there is already a description line for this language + { + $sql2 = "UPDATE ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql2 .= " SET "; + $sql2 .= " label='".$this->db->escape($this->multilangs["$key"]["label"])."',"; + $sql2 .= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'"; + $sql2 .= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($key)."'"; + } + else + { + $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."adherent_type_lang (fk_type, lang, label, description"; + $sql2 .= ")"; + $sql2 .= " VALUES(".$this->id.",'".$this->db->escape($key)."','".$this->db->escape($this->multilangs["$key"]["label"])."',"; + $sql2 .= " '".$this->db->escape($this->multilangs["$key"]["description"])."'"; + $sql2 .= ")"; + } + + // We do not save if main fields are empty + if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) { + if (!$this->db->query($sql2)) { + $this->error = $this->db->lasterror(); + return -1; + } + } + } + else + { + // language is not current language and we didn't provide a multilang description for this language + } + } + + // Call trigger + $result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user); + if ($result < 0) { + $this->error = $this->db->lasterror(); + return -1; + } + // End call triggers + + return 1; + } + + /** + * Delete a language for this product + * + * @param string $langtodelete Language code to delete + * @param User $user Object user making delete + * + * @return int <0 if KO, >0 if OK + */ + public function delMultiLangs($langtodelete, $user) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."adherent_type_lang"; + $sql .= " WHERE fk_type=".$this->id." AND lang='".$this->db->escape($langtodelete)."'"; + + dol_syslog(get_class($this).'::delMultiLangs', LOG_DEBUG); + $result = $this->db->query($sql); + if ($result) { + // Call trigger + $result = $this->call_trigger('ADHERENT_TYPE_DEL_MULTILANGS', $user); + if ($result < 0) { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); + return -1; + } + // End call triggers + return 1; + } + else + { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::delMultiLangs error='.$this->error, LOG_ERR); + return -1; + } + } + + /** + * Fonction qui permet de creer le status de l'adherent + * + * @param User $user User making creation @@ -323 +299 @@ - $this->status = (int) $this->status; + $this->statut = (int) $this->statut; @@ -335 +311 @@ - $sql .= ", ".((int) $conf->entity); + $sql .= ", ".$conf->entity; @@ -340 +316,2 @@ - if ($result) { + if ($result) + { @@ -344 +321,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -349 +327,2 @@ - if (!$notrigger) { + if (!$notrigger) + { @@ -352,3 +331 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -358 +335,2 @@ - if (!$error) { + if (!$error) + { @@ -361 +339,3 @@ - } else { + } + else + { @@ -366 +346,3 @@ - } else { + } + else + { @@ -382 +364 @@ - global $langs, $conf, $hookmanager; + global $langs, $conf, $hookmanager; @@ -387,4 +368,0 @@ - - if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility - $this->note_public = $this->note; - } @@ -396 +374 @@ - $sql .= "statut = ".((int) $this->status).","; + $sql .= "statut = ".$this->statut.","; @@ -400,2 +377,0 @@ - $sql .= "amount = ".((empty($this->amount) && $this->amount == '') ? 'null' : ((float) $this->amount)).","; - $sql .= "caneditamount = ".((int) $this->caneditamount).","; @@ -403,2 +379,2 @@ - $sql .= "note = '".$this->db->escape($this->note_public)."',"; - $sql .= "vote = ".(int) $this->db->escape($this->vote).","; + $sql .= "note = '".$this->db->escape($this->note)."',"; + $sql .= "vote = ".(integer) $this->db->escape($this->vote).","; @@ -406 +382 @@ - $sql .= " WHERE rowid =".((int) $this->id); + $sql .= " WHERE rowid =".$this->id; @@ -409,10 +385,11 @@ - if ($result) { - $this->description = $this->db->escape($this->note_public); - - // Multilangs - if (getDolGlobalInt('MAIN_MULTILANGS')) { - if ($this->setMultiLangs($user) < 0) { - $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql; - return -2; - } - } + if ($result) + { + $this->description = $this->db->escape($this->note); + + // Multilangs + if (!empty($conf->global->MAIN_MULTILANGS)) { + if ($this->setMultiLangs($user) < 0) { + $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql; + return -2; + } + } @@ -423 +400,2 @@ - if (!$error) { + if (!$error) + { @@ -425 +403,2 @@ - if ($result < 0) { + if ($result < 0) + { @@ -430 +409,2 @@ - if (!$error && !$notrigger) { + if (!$error && !$notrigger) + { @@ -433,3 +413 @@ - if ($result < 0) { - $error++; - } + if ($result < 0) { $error++; } @@ -439 +417,2 @@ - if (!$error) { + if (!$error) + { @@ -442 +421,3 @@ - } else { + } + else + { @@ -447 +428,3 @@ - } else { + } + else + { @@ -457,5 +440,6 @@ - * @param User $user User making the deletion - * @return int > 0 if OK, 0 if not found, < 0 if KO - */ - public function delete($user) - { + * @return int > 0 if OK, 0 if not found, < 0 if KO + */ + public function delete() + { + global $user; + @@ -465 +449 @@ - $sql .= " WHERE rowid = ".((int) $this->id); + $sql .= " WHERE rowid = ".$this->id; @@ -468 +452,2 @@ - if ($resql) { + if ($resql) + { @@ -471,5 +456 @@ - if ($result < 0) { - $error++; - $this->db->rollback(); - return -2; - } + if ($result < 0) { $error++; $this->db->rollback(); return -2; } @@ -480 +461,3 @@ - } else { + } + else + { @@ -488 +471 @@ - * Function that retrieves the properties of a membership type + * Function that retrieves the status of the member @@ -491 +474 @@ - * @return int Return integer <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK @@ -495,3 +478,3 @@ - global $langs, $conf; - - $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.caneditamount, d.mail_valid, d.note as note_public, d.vote"; + global $langs, $conf; + + $sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.mail_valid, d.note, d.vote"; @@ -504,2 +487,4 @@ - if ($resql) { - if ($this->db->num_rows($resql)) { + if ($resql) + { + if ($this->db->num_rows($resql)) + { @@ -511,0 +497 @@ + $this->statut = $obj->status; // deprecated @@ -517,2 +502,0 @@ - $this->amount = $obj->amount; - $this->caneditamount = $obj->caneditamount; @@ -520,2 +504 @@ - $this->note = $obj->note_public; // deprecated - $this->note_public = $obj->note_public; + $this->note = $obj->note; @@ -524,7 +507,4 @@ - // multilangs - if (getDolGlobalInt('MAIN_MULTILANGS')) { - $this->getMultiLangs(); - } - - // fetch optionals attributes and labels - $this->fetch_optionals(); + // multilangs + if (!empty($conf->global->MAIN_MULTILANGS)) { + $this->getMultiLangs(); + } @@ -534 +514,3 @@ - } else { + } + else + { @@ -540 +522 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -544,6 +526,5 @@ - * @param int $status Filter on status of type - * @return array List of types of members - */ - public function liste_array($status = -1) - { - // phpcs:enable + * @return array List of types of members + */ + public function liste_array() + { + // phpcs:enable @@ -557,3 +537,0 @@ - if ($status >= 0) { - $sql .= " AND statut = ".((int) $status); - } @@ -562 +540,2 @@ - if ($resql) { + if ($resql) + { @@ -565 +544,2 @@ - if ($nump) { + if ($nump) + { @@ -567 +547,2 @@ - while ($i < $nump) { + while ($i < $nump) + { @@ -574 +555,3 @@ - } else { + } + else + { @@ -581,39 +563,0 @@ - * Return the array of all amounts per membership type id - * - * @param int $status Filter on status of type - * @return array Array of membership type - */ - public function amountByType($status = null) - { - global $conf, $langs; - - $amountbytype = array(); - - $sql = "SELECT rowid, amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type"; - $sql .= " WHERE entity IN (".getEntity('member_type').")"; - if ($status !== null) { - $sql .= " AND statut = ".((int) $status); - } - - $resql = $this->db->query($sql); - if ($resql) { - $nump = $this->db->num_rows($resql); - - if ($nump) { - $i = 0; - while ($i < $nump) { - $obj = $this->db->fetch_object($resql); - - $amountbytype[$obj->rowid] = $obj->amount; - $i++; - } - } - } else { - print $this->db->error(); - } - - return $amountbytype; - } - - /** @@ -622 +566 @@ - * @param string $excludefilter Filter to exclude. This value must not come from a user input. + * @param string $excludefilter Filter to exclude @@ -637,6 +581,4 @@ - $sql .= " AND a.fk_adherent_type = ".((int) $this->id); - if (!empty($excludefilter)) { - $sql .= ' AND ('.$excludefilter.')'; - } - - dol_syslog(get_class($this)."::listMembersForMemberType", LOG_DEBUG); + $sql .= " AND a.fk_adherent_type = ".$this->id; + if (!empty($excludefilter)) $sql .= ' AND ('.$excludefilter.')'; + + dol_syslog(get_class($this)."::listUsersForGroup", LOG_DEBUG); @@ -644,4 +586,8 @@ - if ($resql) { - while ($obj = $this->db->fetch_object($resql)) { - if (!array_key_exists($obj->rowid, $ret)) { - if ($mode < 2) { + if ($resql) + { + while ($obj = $this->db->fetch_object($resql)) + { + if (!array_key_exists($obj->rowid, $ret)) + { + if ($mode < 2) + { @@ -655,2 +600,0 @@ - } else { - $ret[$obj->rowid] = $obj->rowid; @@ -657,0 +602 @@ + else $ret[$obj->rowid] = $obj->rowid; @@ -666 +611,3 @@ - } else { + } + else + { @@ -681,7 +628,3 @@ - if ($morphy == 'phy') { - return $langs->trans("Physical"); - } elseif ($morphy == 'mor') { - return $langs->trans("Moral"); - } else { - return $langs->trans("MorAndPhy"); - } + if ($morphy == 'phy') { return $langs->trans("Physical"); } + elseif ($morphy == 'mor') { return $langs->trans("Moral"); } + else return $langs->trans("MorPhy"); @@ -691,96 +634,27 @@ - /** - * getTooltipContentArray - * @param array $params params to construct tooltip data - * @since v18 - * @return array - */ - public function getTooltipContentArray($params) - { - global $conf, $langs, $user; - - $langs->load('members'); - - $datas = []; - $datas['picto'] = img_picto('', $this->picto).' '.$langs->trans("MemberType").' '.$this->getLibStatut(4); - $datas['label'] = '
'.$langs->trans("Label").': '.$this->label; - if (isset($this->subscription)) { - $datas['subscription'] = '
'.$langs->trans("SubscriptionRequired").': '.yn($this->subscription); - } - if (isset($this->vote)) { - $datas['vote'] = '
'.$langs->trans("VoteAllowed").': '.yn($this->vote); - } - if (isset($this->duration)) { - $datas['duration'] = '
'.$langs->trans("Duration").': '.$this->duration_value; - if ($this->duration_value > 1) { - $dur = array("i"=>$langs->trans("Minutes"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years")); - } elseif ($this->duration_value > 0) { - $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year")); - } - $datas['duration'] .= " " . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) : ''); - } - - return $datas; - } - - /** - * Return clicable name (with picto eventually) - * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $maxlen length max label - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string String with URL - */ - public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) - { - global $langs; - - $result = ''; - $option = ''; - - $classfortooltip = 'classfortooltip'; - $dataparams = ''; - $params = [ - 'id' => $this->id, - 'objecttype' => $this->element, - 'option' => $option, - 'nofetch' => 1, - ]; - if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { - $classfortooltip = 'classforajaxtooltip'; - $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"'; - $label = ''; - } else { - $label = implode($this->getTooltipContentArray($params)); - } - - $url = DOL_URL_ROOT.'/adherents/type.php?rowid='.((int) $this->id); - if ($option != 'nolink') { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - } - $linkstart = ''; - - $linkend = ''; - - $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (' class="'.(($withpicto != 2) ? 'paddingright' : '').'"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= ($maxlen ? dol_trunc($this->label, $maxlen) : $this->label); - } - $result .= $linkend; - - return $result; - } - + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $maxlen length max label + * @param int $notooltip 1=Disable tooltip + * @return string String with URL + */ + public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0) + { + global $langs; + + $result = ''; + $label = $langs->trans("ShowTypeCard", $this->label); + + $linkstart = ''; + $linkend = ''; + + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($this->label, $maxlen) : $this->label); + $result .= $linkend; + + return $result; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -793 +667 @@ - public function getLibStatut($mode = 0) + public function getLibStatut($mode = 0) @@ -798 +671,0 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -806,3 +679,3 @@ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable + public function LibStatut($status, $mode = 0) + { + // phpcs:enable @@ -813,9 +686,8 @@ - if ($status == 0) { - $statusType = 'status5'; - } - - if (empty($this->labelStatus) || empty($this->labelStatusShort)) { - $this->labelStatus[0] = $langs->transnoentitiesnoconv("ActivityCeased"); - $this->labelStatus[1] = $langs->transnoentitiesnoconv("InActivity"); - $this->labelStatusShort[0] = $langs->transnoentitiesnoconv("ActivityCeased"); - $this->labelStatusShort[1] = $langs->transnoentitiesnoconv("InActivity"); + if ($status == 0) $statusType = 'status5'; + + if (empty($this->labelStatus) || empty($this->labelStatusShort)) + { + $this->labelStatus[0] = $langs->trans("ActivityCeased"); + $this->labelStatus[1] = $langs->trans("InActivity"); + $this->labelStatusShort[0] = $langs->trans("ActivityCeased"); + $this->labelStatusShort[1] = $langs->trans("InActivity"); @@ -825,4 +697,4 @@ - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore @@ -840 +712 @@ - // phpcs:enable + // phpcs:enable @@ -843,9 +715,3 @@ - if ($mode == 0) { - $dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]."," . getDolGlobalString('LDAP_MEMBER_TYPE_DN'); - } - if ($mode == 1) { - $dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN'); - } - if ($mode == 2) { - $dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=".$info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]; - } + if ($mode == 0) $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES].",".$conf->global->LDAP_MEMBER_TYPE_DN; + if ($mode == 1) $dn = $conf->global->LDAP_MEMBER_TYPE_DN; + if ($mode == 2) $dn = $conf->global->LDAP_KEY_MEMBERS_TYPES."=".$info[$conf->global->LDAP_KEY_MEMBERS_TYPES]; @@ -856,2 +722,2 @@ - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore @@ -865 +731 @@ - // phpcs:enable + // phpcs:enable @@ -871,5 +737 @@ - $info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS')); - - if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility - $this->note_public = $this->note; - } + $info["objectclass"] = explode(',', $conf->global->LDAP_MEMBER_TYPE_OBJECT_CLASS); @@ -878,7 +740,4 @@ - if ($this->label && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')) { - $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')] = $this->label; - } - if ($this->note_public && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')) { - $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1); - } - if (getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')) { + if ($this->label && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_FULLNAME] = $this->label; + if ($this->note && !empty($conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION)) $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_DESCRIPTION] = dol_string_nohtmltag($this->note, 0, 'UTF-8', 1); + if (!empty($conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS)) + { @@ -886 +745,2 @@ - foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database. + foreach ($this->members as $key=>$val) // This is array of users for group into dolibarr database. + { @@ -892 +752 @@ - $info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : ''); + $info[$conf->global->LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS] = (!empty($valueofldapfield) ? $valueofldapfield : ''); @@ -906 +766 @@ - global $user; + global $conf, $user, $langs; @@ -914 +774 @@ - $this->note_public = 'This is a public note'; + $this->note = 'This is a note'; @@ -917 +776,0 @@ - $this->caneditamount = 0; @@ -920 +779 @@ - $this->status = 1; + $this->statut = 1; @@ -935 +794,4 @@ - if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) { + global $conf; + + if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) + { @@ -948,0 +811,2 @@ + global $conf; + @@ -950 +814,2 @@ - if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) { // Property not yet defined + if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) // Property not yet defined + { @@ -962,73 +827,12 @@ - public function getMailOnResiliate() - { - // NOTE mail_resiliate not defined so never used - if (!empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) { // Property not yet defined - return $this->mail_resiliate; - } - - return ''; - } - - /** - * getMailOnExclude - * - * @return string Return mail model content of type or empty - */ - public function getMailOnExclude() - { - // NOTE mail_exclude not defined so never used - if (!empty($this->mail_exclude) && trim(dol_htmlentitiesbr_decode($this->mail_exclude))) { // Property not yet defined - return $this->mail_exclude; - } - - return ''; - } - - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - global $langs, $user; - - //$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; - - //$return .= ''; - - if ($user->hasRight('adherent', 'configurer')) { - $return .= 'ref).'">'.img_edit().''; - } else { - $return .= ' '; - } - if (property_exists($this, 'vote')) { - $return .= '
'.$langs->trans("VoteAllowed").' : '.yn($this->vote).''; - } - if (property_exists($this, 'amount')) { - if (is_null($this->amount) || $this->amount === '') { - $return .= '
'; - } else { - $return .= '
'.$langs->trans("Amount").''; - $return .= ' : '.price($this->amount).''; - } - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } + public function getMailOnResiliate() + { + global $conf; + + // NOTE mail_resiliate not defined so never used + if (!empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) // Property not yet defined + { + return $this->mail_resiliate; + } + + return ''; + } --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_adherentstats.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_adherentstats.class.php @@ -5 +4,0 @@ - * Copyright (C) 2023 Waël Almoman @@ -36,4 +35,4 @@ - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element; @@ -41,3 +40,3 @@ - public $memberid; - public $socid; - public $userid; + public $memberid; + public $socid; + public $userid; @@ -45,3 +44,3 @@ - public $from; - public $field; - public $where; + public $from; + public $field; + public $where; @@ -55 +54 @@ - * @param int $userid Id user for filter + * @param int $userid Id user for filter @@ -58,0 +58,2 @@ + global $user, $conf; + @@ -60,2 +61,2 @@ - $this->socid = $socid; - $this->userid = $userid; + $this->socid = $socid; + $this->userid = $userid; @@ -70 +71 @@ - $this->where .= " m.statut != -1"; + $this->where .= " m.statut != 0"; @@ -72,3 +73,4 @@ - //if (empty($user->rights->societe->client->voir) && !$user->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .((int) $user->id); - if ($this->memberid) { - $this->where .= " AND m.rowid = ".((int) $this->memberid); + //if (!$user->rights->societe->client->voir && !$user->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($this->memberid) + { + $this->where .= " AND m.rowid = ".$this->memberid; @@ -76 +78 @@ - //if ($this->userid > 0) $this->where .= " AND fk_user_author = ".((int) $this->userid); + //if ($this->userid > 0) $this->where.=' AND fk_user_author = '.$this->userid; @@ -83,3 +85,3 @@ - * @param int $year Year - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month - * @return array Array of nb each month + * @param int $year Year + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @return array Array of nb each month @@ -88,0 +91,2 @@ + global $user; + @@ -91,2 +95,2 @@ - //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); + //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.dateadh,'%Y') = '".$year."'"; @@ -95 +99 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -103 +107 @@ - * @return array Array of nb each year + * @return array Array of nb each year @@ -106,0 +111,2 @@ + global $user; + @@ -109 +115 @@ - //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -112 +118 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -120,3 +126,3 @@ - * @param int $year Year - * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month - * @return array Array of amount each month + * @param int $year Year + * @param int $format 0=Label of abscissa is a translated text, 1=Label of abscissa is month number, 2=Label of abscissa is first letter of month + * @return array Array of amount each month @@ -125,0 +132,2 @@ + global $user; + @@ -128,2 +136,2 @@ - //if (empty($user->rights->societe->client->voir) && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); + //if (!$user->rights->societe->client->voir && !$user->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.dateadh,'%Y') = '".$year."'"; @@ -132 +140 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -140,2 +148,2 @@ - * @param int $year Year - * @return array Array of average each month + * @param int $year Year + * @return array Array of average each month @@ -144,0 +153,2 @@ + global $user; + @@ -147,2 +157,2 @@ - //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql .= " WHERE ".dolSqlDateFilter('p.dateadh', 0, 0, (int) $year, 1); + //if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= " WHERE date_format(p.dateadh,'%Y') = '".$year."'"; @@ -151 +161 @@ - $sql .= $this->db->order('dm', 'DESC'); + $sql .= $this->db->order('dm', 'DESC'); @@ -163,0 +174,2 @@ + global $user; + @@ -166 +178 @@ - //if (empty($user->rights->societe->client->voir) && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + //if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -169 +181 @@ - $sql .= $this->db->order('year', 'DESC'); + $sql .= $this->db->order('year', 'DESC'); @@ -173,155 +184,0 @@ - - /** - * Return count of member by status group by adh type, total and average - * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member type - */ - public function countMembersByTypeAndStatus($numberYears = 0) - { - global $user; - - $now = dol_now(); - $endYear = date('Y'); - $startYear = $endYear - $numberYears; - - $sql = "SELECT t.rowid as fk_adherent_type, t.libelle as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON t.rowid = d.fk_adherent_type AND d.entity IN (" . getEntity('adherent') . ")"; - if ($numberYears) { - $sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'"; - } - $sql .= " WHERE t.entity IN (".getEntity('member_type').")"; - $sql .= " AND t.statut = 1"; - $sql .= " GROUP BY t.rowid, t.libelle"; - - dol_syslog("box_members_by_type::select nb of members per type", LOG_DEBUG); - $result = $this->db->query($sql); - - $MembersCountArray = array(); - - if ($result) { - $num = $this->db->num_rows($result); - $i = 0; - $totalstatus = array( - 'label' => 'Total', - 'members_draft' => 0, - 'members_pending' => 0, - 'members_uptodate' => 0, - 'members_expired' => 0, - 'members_excluded' => 0, - 'members_resiliated' => 0 - ); - while ($i < $num) { - $objp = $this->db->fetch_object($result); - $MembersCountArray[$objp->fk_adherent_type] = array( - 'label' => $objp->label, - 'members_draft' => (int) $objp->members_draft, - 'members_pending' => (int) $objp->members_pending, - 'members_uptodate' => (int) $objp->members_uptodate, - 'members_expired' => (int) $objp->members_expired, - 'members_excluded' => (int) $objp->members_excluded, - 'members_resiliated' => (int) $objp->members_resiliated - ); - $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_adherent_type] as $key=>$nb) { - if ($key != 'label') { - $totalrow += $nb; - $totalstatus[$key] += $nb; - } - } - $MembersCountArray[$objp->fk_adherent_type]['total_adhtype'] = $totalrow; - $i++; - } - $this->db->free($result); - $MembersCountArray['total'] = $totalstatus; - $MembersCountArray['total']['all'] = array_sum($totalstatus); - } - - return $MembersCountArray; - } - - /** - * Return count of member by status group by adh type, total and average - * - * @param int $numberYears Number of years to scan (0 = all) - * @return array Array with total of draft, pending, uptodate, expired, resiliated for each member tag - */ - public function countMembersByTagAndStatus($numberYears = 0) - { - global $user; - - $now = dol_now(); - $endYear = date('Y'); - $startYear = $endYear - $numberYears; - - $sql = "SELECT c.rowid as fk_categorie, c.label as label"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_DRAFT, "'members_draft'", 'NULL').") as members_draft"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin IS NULL AND t.subscription = '1')", "'members_pending'", 'NULL').") as members_pending"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin >= '".$this->db->idate($now)."' OR t.subscription = 0)", "'members_uptodate'", 'NULL').") as members_uptodate"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_VALIDATED." AND (d.datefin < '".$this->db->idate($now)."' AND t.subscription = 1)", "'members_expired'", 'NULL').") as members_expired"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_EXCLUDED, "'members_excluded'", 'NULL').") as members_excluded"; - $sql .= ", COUNT(".$this->db->ifsql("d.statut = ".Adherent::STATUS_RESILIATED, "'members_resiliated'", 'NULL').") as members_resiliated"; - $sql .= " FROM ".MAIN_DB_PREFIX."categorie as c"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_member as ct ON c.rowid = ct.fk_categorie"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d ON d.rowid = ct.fk_member"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as t ON t.rowid = d.fk_adherent_type"; - $sql .= " WHERE c.entity IN (".getEntity('member_type').")"; - $sql .= " AND d.entity IN (" . getEntity('adherent') . ")"; - $sql .= " AND t.entity IN (" . getEntity('adherent') . ")"; - if ($numberYears) { - $sql .= " AND d.datefin > '".$this->db->idate(dol_get_first_day($startYear))."'"; - } - $sql .= " AND c.fk_parent = 0"; - $sql .= " GROUP BY c.rowid, c.label"; - $sql .= " ORDER BY label ASC"; - - dol_syslog("box_members_by_tag::select nb of members per tag", LOG_DEBUG); - $result = $this->db->query($sql); - - if ($result) { - $num = $this->db->num_rows($result); - $i = 0; - $MembersCountArray = []; - $totalstatus = array( - 'label' => 'Total', - 'members_draft' => 0, - 'members_pending' => 0, - 'members_uptodate' => 0, - 'members_expired' => 0, - 'members_excluded' => 0, - 'members_resiliated' => 0 - ); - while ($i < $num) { - $objp = $this->db->fetch_object($result); - $MembersCountArray[$objp->fk_categorie] = array( - 'label' => $objp->label, - 'members_draft' => (int) $objp->members_draft, - 'members_pending' => (int) $objp->members_pending, - 'members_uptodate' => (int) $objp->members_uptodate, - 'members_expired' => (int) $objp->members_expired, - 'members_excluded' => (int) $objp->members_excluded, - 'members_resiliated' => (int) $objp->members_resiliated - ); - $totalrow = 0; - foreach ($MembersCountArray[$objp->fk_categorie] as $key=>$nb) { - if ($key != 'label') { - $totalrow += $nb; - $totalstatus[$key] += $nb; - } - } - $MembersCountArray[$objp->fk_categorie]['total_adhtag'] = $totalrow; - $i++; - } - $this->db->free($result); - $MembersCountArray['total'] = $totalstatus; - $MembersCountArray['total']['all'] = array_sum($totalstatus); - } - return $MembersCountArray; - } --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_api_members.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_api_members.class.php @@ -4,2 +3,0 @@ - * Copyright (C) 2020 Thibault FOUCART - * Copyright (C) 2020 Frédéric France @@ -23 +20,0 @@ -require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; @@ -36,192 +33,76 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'morphy', - 'typeid' - ); - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - } - - /** - * Get properties of a member object - * - * Return an array with member informations - * - * @param int $id ID of member - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $member = new Adherent($this->db); - if ($id == 0) { - $result = $member->initAsSpecimen(); - } else { - $result = $member->fetch($id); - } - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('adherent', $member->id) && $id > 0) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($member); - } - - /** - * Get properties of a member object by linked thirdparty - * - * Return an array with member informations - * - * @param int $thirdparty ID of third party - * - * @return Object Data without useless information - * - * @url GET thirdparty/{thirdparty} - * - * @throws RestException 401 - * @throws RestException 404 - */ - public function getByThirdparty($thirdparty) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $member = new Adherent($this->db); - $result = $member->fetch('', '', $thirdparty); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($member); - } - - /** - * Get properties of a member object by linked thirdparty email - * - * Return an array with member informations - * - * @param string $email Email of third party - * - * @return Object Data without useless information - * - * @url GET thirdparty/email/{email} - * - * @throws RestException 401 - * @throws RestException 404 - */ - public function getByThirdpartyEmail($email) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $thirdparty = new Societe($this->db); - $result = $thirdparty->fetch('', '', '', '', '', '', '', '', '', '', $email); - if (!$result) { - throw new RestException(404, 'thirdparty not found'); - } - - $member = new Adherent($this->db); - $result = $member->fetch('', '', $thirdparty->id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($member); - } - - /** - * Get properties of a member object by linked thirdparty barcode - * - * Return an array with member informations - * - * @param string $barcode Barcode of third party - * - * @return Object Data without useless information - * - * @url GET thirdparty/barcode/{barcode} - * - * @throws RestException 401 - * @throws RestException 404 - */ - public function getByThirdpartyBarcode($barcode) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $thirdparty = new Societe($this->db); - $result = $thirdparty->fetch('', '', '', $barcode); - if (!$result) { - throw new RestException(404, 'thirdparty not found'); - } - - $member = new Adherent($this->db); - $result = $member->fetch('', '', $thirdparty->id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($member); - } - - /** - * List members - * - * Get a list of members - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $typeid ID of the type of member - * @param int $category Use this param to filter list by category - * @param string $sqlfilters Other criteria to filter answers separated by a comma. - * Example: "(t.ref:like:'SO-%') and ((t.date_creation:<:'20160101') or (t.nature:is:NULL))" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of member objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $typeid = '', $category = 0, $sqlfilters = '', $properties = '') - { - global $db, $conf; - - $obj_ret = array(); - - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent AS t LEFT JOIN ".MAIN_DB_PREFIX."adherent_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call - if ($category > 0) { + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'morphy', + 'typeid' + ); + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + } + + /** + * Get properties of a member object + * + * Return an array with member informations + * + * @param int $id ID of member + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (!$result) { + throw new RestException(404, 'member not found'); + } + + if (!DolibarrApi::_checkAccessToResource('adherent', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($member); + } + + /** + * List members + * + * Get a list of members + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $typeid ID of the type of member + * @param int $category Use this param to filter list by category + * @param string $sqlfilters Other criteria to filter answers separated by a comma. + * Example: "(t.ref:like:'SO-%') and ((t.date_creation:<:'20160101') or (t.nature:is:NULL))" + * @return array Array of member objects + * + * @throws RestException + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $typeid = '', $category = 0, $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); + + if (!DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $sql = "SELECT t.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as t"; + if ($category > 0) { @@ -229,304 +110,293 @@ - } - $sql .= ' WHERE t.entity IN ('.getEntity('adherent').')'; - if (!empty($typeid)) { - $sql .= ' AND t.fk_adherent_type='.((int) $typeid); - } - // Select members of given category - if ($category > 0) { - $sql .= " AND c.fk_categorie = ".((int) $category); - $sql .= " AND c.fk_member = t.rowid"; - } - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - if ($result) { - $i = 0; - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $member = new Adherent($this->db); - if ($member->fetch($obj->rowid)) { - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($member), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve member list : '.$this->db->lasterror()); - } - - return $obj_ret; - } - - /** - * Create member object - * - * @param array $request_data Request data - * @return int ID of member - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - $member = new Adherent($this->db); - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $member->context['caller'] = $request_data['caller']; - continue; - } - - $member->$field = $value; - } - if ($member->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, 'Error creating member', array_merge(array($member->error), $member->errors)); - } - return $member->id; - } - - /** - * Update member - * - * @param int $id ID of member to update - * @param array $request_data Datas - * @return Object Updated object - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) { - throw new RestException(401); - } - - $member = new Adherent($this->db); - $result = $member->fetch($id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('member', $member->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $member->context['caller'] = $request_data['caller']; - continue; - } - - // Process the status separately because it must be updated using - // the validate(), resiliate() and exclude() methods of the class Adherent. - if ($field == 'statut') { - if ($value == '0') { - $result = $member->resiliate(DolibarrApiAccess::$user); - if ($result < 0) { - throw new RestException(500, 'Error when resiliating member: '.$member->error); - } - } elseif ($value == '1') { - $result = $member->validate(DolibarrApiAccess::$user); - if ($result < 0) { - throw new RestException(500, 'Error when validating member: '.$member->error); - } - } elseif ($value == '-2') { - $result = $member->exclude(DolibarrApiAccess::$user); - if ($result < 0) { - throw new RestException(500, 'Error when excluding member: '.$member->error); - } - } - } else { - $member->$field = $value; - } - } - - // If there is no error, update() returns the number of affected rows - // so if the update is a no op, the return value is zero. - if ($member->update(DolibarrApiAccess::$user) >= 0) { - return $this->get($id); - } else { - throw new RestException(500, 'Error when updating member: '.$member->error); - } - } - - /** - * Delete member - * - * @param int $id member ID - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'supprimer')) { - throw new RestException(401); - } - $member = new Adherent($this->db); - $result = $member->fetch($id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - if (!DolibarrApi::_checkAccessToResource('member', $member->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - - $res = $member->delete($member->id, DolibarrApiAccess::$user); - if ($res < 0) { - throw new RestException(500, "Can't delete, error occurs"); - } elseif ($res == 0) { - throw new RestException(409, "Can't delete, that product is probably used"); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Member deleted' - ) - ); - } - - /** - * Validate fields before creating an object - * - * @param array|null $data Data to validate - * @return array - * - * @throws RestException - */ - private function _validate($data) - { - $member = array(); - foreach (Members::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $member[$field] = $data[$field]; - } - return $member; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - // Remove the subscriptions because they are handled as a subresource. - unset($object->subscriptions); - unset($object->fk_incoterms); - unset($object->label_incoterms); - unset($object->location_incoterms); - unset($object->fk_delivery_address); - unset($object->shipping_method_id); - - unset($object->total_ht); - unset($object->total_ttc); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - - return $object; - } - - /** - * List subscriptions of a member - * - * Get a list of subscriptions - * - * @param int $id ID of member - * @return array Array of subscription objects - * - * @throws RestException - * - * @url GET {id}/subscriptions - */ - public function getSubscriptions($id) - { - $obj_ret = array(); - - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) { - throw new RestException(401); - } - - $member = new Adherent($this->db); - $result = $member->fetch($id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - $obj_ret = array(); - foreach ($member->subscriptions as $subscription) { - $obj_ret[] = $this->_cleanObjectDatas($subscription); - } - return $obj_ret; - } - - /** - * Add a subscription for a member - * - * @param int $id ID of member - * @param string $start_date Start date {@from body} {@type timestamp} - * @param string $end_date End date {@from body} {@type timestamp} - * @param float $amount Amount (may be 0) {@from body} - * @param string $label Label {@from body} - * @return int ID of subscription - * - * @url POST {id}/subscriptions - */ - public function createSubscription($id, $start_date, $end_date, $amount, $label = '') - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) { - throw new RestException(401); - } - - $member = new Adherent($this->db); - $result = $member->fetch($id); - if (!$result) { - throw new RestException(404, 'member not found'); - } - - return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date); - } - - /** - * Get categories for a member - * - * @param int $id ID of member - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * - * @return mixed - * - * @url GET {id}/categories - */ + } + $sql .= ' WHERE t.entity IN ('.getEntity('adherent').')'; + if (!empty($typeid)) + { + $sql .= ' AND t.fk_adherent_type='.$typeid; + } + // Select members of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_member = t.rowid "; + } + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $member = new Adherent($this->db); + if ($member->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($member); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve member list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No member found'); + } + + return $obj_ret; + } + + /** + * Create member object + * + * @param array $request_data Request data + * @return int ID of member + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + $member = new Adherent($this->db); + foreach ($request_data as $field => $value) { + $member->$field = $value; + } + if ($member->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error creating member', array_merge(array($member->error), $member->errors)); + } + return $member->id; + } + + /** + * Update member + * + * @param int $id ID of member to update + * @param array $request_data Datas + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (!$result) { + throw new RestException(404, 'member not found'); + } + + if (!DolibarrApi::_checkAccessToResource('member', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + // Process the status separately because it must be updated using + // the validate() and resiliate() methods of the class Adherent. + if ($field == 'statut') { + if ($value == '0') { + $result = $member->resiliate(DolibarrApiAccess::$user); + if ($result < 0) { + throw new RestException(500, 'Error when resiliating member: '.$member->error); + } + } elseif ($value == '1') { + $result = $member->validate(DolibarrApiAccess::$user); + if ($result < 0) { + throw new RestException(500, 'Error when validating member: '.$member->error); + } + } + } else { + $member->$field = $value; + } + } + + // If there is no error, update() returns the number of affected rows + // so if the update is a no op, the return value is zero. + if ($member->update(DolibarrApiAccess::$user) >= 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $member->error); + } + } + + /** + * Delete member + * + * @param int $id member ID + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->adherent->supprimer) { + throw new RestException(401); + } + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (!$result) { + throw new RestException(404, 'member not found'); + } + + if (!DolibarrApi::_checkAccessToResource('member', $member->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if (!$member->delete($member->id, DolibarrApiAccess::$user)) { + throw new RestException(401, 'error when deleting member'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'member deleted' + ) + ); + } + + /** + * Validate fields before creating an object + * + * @param array|null $data Data to validate + * @return array + * + * @throws RestException + */ + private function _validate($data) + { + $member = array(); + foreach (Members::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $member[$field] = $data[$field]; + } + return $member; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + protected function _cleanObjectDatas($object) + { + // phpcs:enable + $object = parent::_cleanObjectDatas($object); + + // Remove the subscriptions because they are handled as a subresource. + unset($object->subscriptions); + unset($object->fk_incoterms); + unset($object->label_incoterms); + unset($object->location_incoterms); + unset($object->fk_delivery_address); + unset($object->shipping_method_id); + + unset($object->total_ht); + unset($object->total_ttc); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + + return $object; + } + + /** + * List subscriptions of a member + * + * Get a list of subscriptions + * + * @param int $id ID of member + * @return array Array of subscription objects + * + * @throws RestException + * + * @url GET {id}/subscriptions + */ + public function getSubscriptions($id) + { + $obj_ret = array(); + + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->lire) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (!$result) { + throw new RestException(404, 'member not found'); + } + + $obj_ret = array(); + foreach ($member->subscriptions as $subscription) { + $obj_ret[] = $this->_cleanObjectDatas($subscription); + } + return $obj_ret; + } + + /** + * Add a subscription for a member + * + * @param int $id ID of member + * @param int $start_date Start date {@from body} {@type timestamp} + * @param int $end_date End date {@from body} {@type timestamp} + * @param float $amount Amount (may be 0) {@from body} + * @param string $label Label {@from body} + * @return int ID of subscription + * + * @url POST {id}/subscriptions + */ + public function createSubscription($id, $start_date, $end_date, $amount, $label = '') + { + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->creer) { + throw new RestException(401); + } + + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (!$result) { + throw new RestException(404, 'member not found'); + } + + return $member->subscription($start_date, $amount, 0, '', $label, '', '', '', $end_date); + } + + /** + * Get categories for a member + * + * @param int $id ID of member + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET {id}/categories + */ @@ -542,0 +413,4 @@ + if (empty($result)) { + throw new RestException(404, 'No category found'); + } + --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_api_memberstypes.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_api_memberstypes.class.php @@ -30,301 +30,294 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'label', - ); - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - } - - /** - * Get properties of a member type object - * - * Return an array with member type informations - * - * @param int $id ID of member type - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $membertype = new AdherentType($this->db); - $result = $membertype->fetch($id); - if (!$result) { - throw new RestException(404, 'member type not found'); - } - - if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - return $this->_cleanObjectDatas($membertype); - } - - /** - * List members types - * - * Get a list of members types - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.libelle:like:'SO-%') and (t.subscription:=:'1')" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of member type objects - * - * @throws RestException - */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '') - { - global $db, $conf; - - $obj_ret = array(); - - if (!DolibarrApiAccess::$user->hasRight('adherent', 'lire')) { - throw new RestException(401); - } - - $sql = "SELECT t.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type AS t LEFT JOIN ".MAIN_DB_PREFIX."adherent_type_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields - $sql .= ' WHERE t.entity IN ('.getEntity('member_type').')'; - - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - if ($result) { - $i = 0; - $num = $this->db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) { - $obj = $this->db->fetch_object($result); - $membertype = new AdherentType($this->db); - if ($membertype->fetch($obj->rowid)) { - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($membertype), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve member type list : '.$this->db->lasterror()); - } - - return $obj_ret; - } - - /** - * Create member type object - * - * @param array $request_data Request data - * @return int ID of member type - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - $membertype = new AdherentType($this->db); - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $membertype->context['caller'] = $request_data['caller']; - continue; - } - - $membertype->$field = $value; - } - if ($membertype->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors)); - } - return $membertype->id; - } - - /** - * Update member type - * - * @param int $id ID of member type to update - * @param array $request_data Datas - * @return int - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) { - throw new RestException(401); - } - - $membertype = new AdherentType($this->db); - $result = $membertype->fetch($id); - if (!$result) { - throw new RestException(404, 'member type not found'); - } - - if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $membertype->context['caller'] = $request_data['caller']; - continue; - } - - // Process the status separately because it must be updated using - // the validate(), resiliate() and exclude() methods of the class AdherentType. - $membertype->$field = $value; - } - - // If there is no error, update() returns the number of affected rows - // so if the update is a no op, the return value is zero. - if ($membertype->update(DolibarrApiAccess::$user) >= 0) { - return $this->get($id); - } else { - throw new RestException(500, 'Error when updating member type: '.$membertype->error); - } - } - - /** - * Delete member type - * - * @param int $id member type ID - * @return array - */ - public function delete($id) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'configurer')) { - throw new RestException(401); - } - $membertype = new AdherentType($this->db); - $result = $membertype->fetch($id); - if (!$result) { - throw new RestException(404, 'member type not found'); - } - - if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $res = $membertype->delete(DolibarrApiAccess::$user); - if ($res < 0) { - throw new RestException(500, "Can't delete, error occurs"); - } elseif ($res == 0) { - throw new RestException(409, "Can't delete, that product is probably used"); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Member type deleted' - ) - ); - } - - /** - * Validate fields before creating an object - * - * @param array|null $data Data to validate - * @return array - * - * @throws RestException - */ - private function _validate($data) - { - $membertype = array(); - foreach (MembersTypes::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $membertype[$field] = $data[$field]; - } - return $membertype; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore - /** - * Clean sensible object datas - * - * @param Object $object Object to clean - * @return Object Object with cleaned properties - */ - protected function _cleanObjectDatas($object) - { - // phpcs:enable - $object = parent::_cleanObjectDatas($object); - - unset($object->array_options); - unset($object->linkedObjectsIds); - unset($object->context); - unset($object->canvas); - unset($object->fk_project); - unset($object->contact); - unset($object->contact_id); - unset($object->thirdparty); - unset($object->user); - unset($object->origin); - unset($object->origin_id); - unset($object->ref_ext); - unset($object->country); - unset($object->country_id); - unset($object->country_code); - unset($object->barcode_type); - unset($object->barcode_type_code); - unset($object->barcode_type_label); - unset($object->barcode_type_coder); - unset($object->mode_reglement_id); - unset($object->cond_reglement_id); - unset($object->cond_reglement); - unset($object->fk_delivery_address); - unset($object->shipping_method_id); - unset($object->model_pdf); - unset($object->fk_account); - unset($object->note_public); - unset($object->note_private); - unset($object->fk_incoterms); - unset($object->label_incoterms); - unset($object->location_incoterms); - unset($object->name); - unset($object->lastname); - unset($object->firstname); - unset($object->civility_id); - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); - - return $object; - } + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'label', + ); + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + } + + /** + * Get properties of a member type object + * + * Return an array with member type informations + * + * @param int $id ID of member type + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $membertype = new AdherentType($this->db); + $result = $membertype->fetch($id); + if (!$result) { + throw new RestException(404, 'member type not found'); + } + + if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + return $this->_cleanObjectDatas($membertype); + } + + /** + * List members types + * + * Get a list of members types + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.libelle:like:'SO-%') and (t.subscription:=:'1')" + * @return array Array of member type objects + * + * @throws RestException + */ + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); + + if (!DolibarrApiAccess::$user->rights->adherent->lire) { + throw new RestException(401); + } + + $sql = "SELECT t.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as t"; + $sql .= ' WHERE t.entity IN ('.getEntity('member_type').')'; + + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $membertype = new AdherentType($this->db); + if ($membertype->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($membertype); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve member type list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No member type found'); + } + + return $obj_ret; + } + + /** + * Create member type object + * + * @param array $request_data Request data + * @return int ID of member type + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->configurer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + $membertype = new AdherentType($this->db); + foreach ($request_data as $field => $value) { + $membertype->$field = $value; + } + if ($membertype->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error creating member type', array_merge(array($membertype->error), $membertype->errors)); + } + return $membertype->id; + } + + /** + * Update member type + * + * @param int $id ID of member type to update + * @param array $request_data Datas + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->configurer) { + throw new RestException(401); + } + + $membertype = new AdherentType($this->db); + $result = $membertype->fetch($id); + if (!$result) { + throw new RestException(404, 'member type not found'); + } + + if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + // Process the status separately because it must be updated using + // the validate() and resiliate() methods of the class AdherentType. + $membertype->$field = $value; + } + + // If there is no error, update() returns the number of affected rows + // so if the update is a no op, the return value is zero. + if ($membertype->update(DolibarrApiAccess::$user) >= 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $membertype->error); + } + } + + /** + * Delete member type + * + * @param int $id member type ID + * @return array + */ + public function delete($id) + { + if (!DolibarrApiAccess::$user->rights->adherent->configurer) { + throw new RestException(401); + } + $membertype = new AdherentType($this->db); + $result = $membertype->fetch($id); + if (!$result) { + throw new RestException(404, 'member type not found'); + } + + if (!DolibarrApi::_checkAccessToResource('member', $membertype->id, 'adherent_type')) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + if (!$membertype->delete()) { + throw new RestException(401, 'error when deleting member type'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'member type deleted' + ) + ); + } + + /** + * Validate fields before creating an object + * + * @param array|null $data Data to validate + * @return array + * + * @throws RestException + */ + private function _validate($data) + { + $membertype = array(); + foreach (MembersTypes::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $membertype[$field] = $data[$field]; + } + return $membertype; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + protected function _cleanObjectDatas($object) + { + // phpcs:enable + $object = parent::_cleanObjectDatas($object); + + unset($object->array_options); + unset($object->linkedObjectsIds); + unset($object->context); + unset($object->canvas); + unset($object->fk_project); + unset($object->contact); + unset($object->contact_id); + unset($object->thirdparty); + unset($object->user); + unset($object->origin); + unset($object->origin_id); + unset($object->ref_ext); + unset($object->country); + unset($object->country_id); + unset($object->country_code); + unset($object->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + unset($object->mode_reglement_id); + unset($object->cond_reglement_id); + unset($object->cond_reglement); + unset($object->fk_delivery_address); + unset($object->shipping_method_id); + unset($object->modelpdf); + unset($object->fk_account); + unset($object->note_public); + unset($object->note_private); + unset($object->fk_incoterms); + unset($object->label_incoterms); + unset($object->location_incoterms); + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + + return $object; + } --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_api_subscriptions.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_api_subscriptions.class.php @@ -30,231 +30,224 @@ - /** - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - public static $FIELDS = array( - 'fk_adherent', - 'dateh', - 'datef', - 'amount', - ); - - /** - * Constructor - */ - public function __construct() - { - global $db, $conf; - $this->db = $db; - } - - /** - * Get properties of a subscription object - * - * Return an array with subscription informations - * - * @param int $id ID of subscription - * @return Object Object with cleaned properties - * - * @throws RestException - */ - public function get($id) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) { - throw new RestException(401); - } - - $subscription = new Subscription($this->db); - $result = $subscription->fetch($id); - if (!$result) { - throw new RestException(404, 'Subscription not found'); - } - - return $this->_cleanObjectDatas($subscription); - } - - /** - * List subscriptions - * - * Get a list of subscriptions - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')" - * @param string $properties Restrict the data returned to theses properties. Ignored if empty. Comma separated list of properties names - * @return array Array of subscription objects - * - * @throws RestException - */ - public function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '', $properties = '') - { - global $conf; - - $obj_ret = array(); - - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'lire')) { - throw new RestException(401); - } - - $sql = "SELECT rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."subscription as t"; - $sql .= ' WHERE 1 = 1'; - // Add sql filters - if ($sqlfilters) { - $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage); - if ($errormessage) { - throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); - } - } - - $sql .= $this->db->order($sortfield, $sortorder); - if ($limit) { - if ($page < 0) { - $page = 0; - } - $offset = $limit * $page; - - $sql .= $this->db->plimit($limit + 1, $offset); - } - - $result = $this->db->query($sql); - if ($result) { - $i = 0; - $num = $this->db->num_rows($result); - while ($i < min($limit, $num)) { - $obj = $this->db->fetch_object($result); - $subscription = new Subscription($this->db); - if ($subscription->fetch($obj->rowid)) { - $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($subscription), $properties); - } - $i++; - } - } else { - throw new RestException(503, 'Error when retrieve subscription list : '.$this->db->lasterror()); - } - - return $obj_ret; - } - - /** - * Create subscription object - * - * @param array $request_data Request data - * @return int ID of subscription - */ - public function post($request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - $subscription = new Subscription($this->db); - foreach ($request_data as $field => $value) { - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $subscription->context['caller'] = $request_data['caller']; - continue; - } - - $subscription->$field = $value; - } - if ($subscription->create(DolibarrApiAccess::$user) < 0) { - throw new RestException(500, 'Error when creating contribution', array_merge(array($subscription->error), $subscription->errors)); - } - return $subscription->id; - } - - /** - * Update subscription - * - * @param int $id ID of subscription to update - * @param array $request_data Datas - * @return Object - */ - public function put($id, $request_data = null) - { - if (!DolibarrApiAccess::$user->hasRight('adherent', 'creer')) { - throw new RestException(401); - } - - $subscription = new Subscription($this->db); - $result = $subscription->fetch($id); - if (!$result) { - throw new RestException(404, 'Subscription not found'); - } - - foreach ($request_data as $field => $value) { - if ($field == 'id') { - continue; - } - if ($field === 'caller') { - // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again whith the caller - $subscription->context['caller'] = $request_data['caller']; - continue; - } - - $subscription->$field = $value; - } - - if ($subscription->update(DolibarrApiAccess::$user) > 0) { - return $this->get($id); - } else { - throw new RestException(500, 'Error when updating contribution: '.$subscription->error); - } - } - - /** - * Delete subscription - * - * @param int $id ID of subscription to delete - * @return array - */ - public function delete($id) - { - // The right to delete a subscription comes with the right to create one. - if (!DolibarrApiAccess::$user->hasRight('adherent', 'cotisation', 'creer')) { - throw new RestException(401); - } - $subscription = new Subscription($this->db); - $result = $subscription->fetch($id); - if (!$result) { - throw new RestException(404, 'Subscription not found'); - } - - $res = $subscription->delete(DolibarrApiAccess::$user); - if ($res < 0) { - throw new RestException(500, "Can't delete, error occurs"); - } elseif ($res == 0) { - throw new RestException(409, "Can't delete, that product is probably used"); - } - - return array( - 'success' => array( - 'code' => 200, - 'message' => 'Subscription deleted' - ) - ); - } - - /** - * Validate fields before creating an object - * - * @param array|null $data Data to validate - * @return array - * - * @throws RestException - */ - private function _validate($data) - { - $subscription = array(); - foreach (Subscriptions::$FIELDS as $field) { - if (!isset($data[$field])) { - throw new RestException(400, "$field field missing"); - } - $subscription[$field] = $data[$field]; - } - return $subscription; - } + /** + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'fk_adherent', + 'dateh', + 'datef', + 'amount', + ); + + /** + * Constructor + */ + public function __construct() + { + global $db, $conf; + $this->db = $db; + } + + /** + * Get properties of a subscription object + * + * Return an array with subscription informations + * + * @param int $id ID of subscription + * @return array|mixed data without useless information + * + * @throws RestException + */ + public function get($id) + { + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->lire) { + throw new RestException(401); + } + + $subscription = new Subscription($this->db); + $result = $subscription->fetch($id); + if (!$result) { + throw new RestException(404, 'Subscription not found'); + } + + return $this->_cleanObjectDatas($subscription); + } + + /** + * List subscriptions + * + * Get a list of subscriptions + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.import_key:<:'20160101')" + * @return array Array of subscription objects + * + * @throws RestException + */ + public function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') + { + global $db, $conf; + + $obj_ret = array(); + + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->lire) { + throw new RestException(401); + } + + $sql = "SELECT rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."subscription as t"; + $sql .= ' WHERE 1 = 1'; + // Add sql filters + if ($sqlfilters) + { + if (!DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } + + $sql .= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql .= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + while ($i < min($limit, $num)) + { + $obj = $db->fetch_object($result); + $subscription = new Subscription($this->db); + if ($subscription->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($subscription); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve subscription list : '.$db->lasterror()); + } + if (!count($obj_ret)) { + throw new RestException(404, 'No Subscription found'); + } + + return $obj_ret; + } + + /** + * Create subscription object + * + * @param array $request_data Request data + * @return int ID of subscription + */ + public function post($request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->creer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + $subscription = new Subscription($this->db); + foreach ($request_data as $field => $value) { + $subscription->$field = $value; + } + if ($subscription->create(DolibarrApiAccess::$user) < 0) { + throw new RestException(500, 'Error when creating subscription', array_merge(array($subscription->error), $subscription->errors)); + } + return $subscription->id; + } + + /** + * Update subscription + * + * @param int $id ID of subscription to update + * @param array $request_data Datas + * @return int + */ + public function put($id, $request_data = null) + { + if (!DolibarrApiAccess::$user->rights->adherent->creer) { + throw new RestException(401); + } + + $subscription = new Subscription($this->db); + $result = $subscription->fetch($id); + if (!$result) { + throw new RestException(404, 'Subscription not found'); + } + + foreach ($request_data as $field => $value) { + if ($field == 'id') continue; + $subscription->$field = $value; + } + + if ($subscription->update(DolibarrApiAccess::$user) > 0) + { + return $this->get($id); + } + else + { + throw new RestException(500, $subscription->error); + } + } + + /** + * Delete subscription + * + * @param int $id ID of subscription to delete + * @return array + */ + public function delete($id) + { + // The right to delete a subscription comes with the right to create one. + if (!DolibarrApiAccess::$user->rights->adherent->cotisation->creer) { + throw new RestException(401); + } + $subscription = new Subscription($this->db); + $result = $subscription->fetch($id); + if (!$result) { + throw new RestException(404, 'Subscription not found'); + } + + if (!$subscription->delete(DolibarrApiAccess::$user)) { + throw new RestException(401, 'error when deleting subscription'); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'subscription deleted' + ) + ); + } + + /** + * Validate fields before creating an object + * + * @param array|null $data Data to validate + * @return array + * + * @throws RestException + */ + private function _validate($data) + { + $subscription = array(); + foreach (Subscriptions::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $subscription[$field] = $data[$field]; + } + return $subscription; + } --- /tmp/dsg/dolibarr/htdocs/adherents/class/github_19.0.3_subscription.class.php +++ /tmp/dsg/dolibarr/htdocs/adherents/class/client_subscription.class.php @@ -35,522 +35,462 @@ - /** - * @var string ID to identify managed object - */ - public $element = 'subscription'; - - /** - * @var string Name of table without prefix where object is stored - */ - public $table_element = 'subscription'; - - /** - * @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by fk_soc, 'field@table'=Test with link by field@table - */ - public $ismultientitymanaged = 'fk_adherent@adherent'; - - /** - * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png - */ - public $picto = 'payment'; - - /** - * Date creation record (datec) - * - * @var integer - */ - public $datec; - - /** - * Date modification record (tms) - * - * @var integer - */ - public $datem; - - /** - * Subscription start date (date subscription) - * - * @var integer - */ - public $dateh; - - /** - * Subscription end date - * - * @var integer - */ - public $datef; - - /** - * @var int ID - */ - public $fk_type; - - /** - * @var int Member ID - */ - public $fk_adherent; - - /** - * @var double amount subscription - */ - public $amount; - - /** - * @var int ID of bank in llx_bank - */ - public $fk_bank; - - /** - * @var array Array with all fields into database and their property. Do not use it as a static var. It may be modified by constructor. - */ - public $fields = array( - 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), - 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15), - 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>20), - 'fk_adherent' =>array('type'=>'integer', 'label'=>'Member', 'enabled'=>1, 'visible'=>-1, 'position'=>25), - 'dateadh' =>array('type'=>'datetime', 'label'=>'DateSubscription', 'enabled'=>1, 'visible'=>-1, 'position'=>30), - 'datef' =>array('type'=>'datetime', 'label'=>'DateEndSubscription', 'enabled'=>1, 'visible'=>-1, 'position'=>35), - 'subscription' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>-1, 'position'=>40, 'isameasure'=>1), - 'fk_bank' =>array('type'=>'integer', 'label'=>'BankId', 'enabled'=>1, 'visible'=>-1, 'position'=>45), - 'note' =>array('type'=>'html', 'label'=>'Note', 'enabled'=>1, 'visible'=>-1, 'position'=>50), - 'fk_type' =>array('type'=>'integer', 'label'=>'MemberType', 'enabled'=>1, 'visible'=>-1, 'position'=>55), - 'fk_user_creat' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>60), - 'fk_user_valid' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>65), - ); - - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - public function __construct($db) - { - $this->db = $db; - } - - - /** - * Function who permitted creation of the subscription - * - * @param User $user User that create - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int Return integer <0 if KO, Id subscription created if OK - */ - public function create($user, $notrigger = false) - { - global $langs; - - $error = 0; - - $now = dol_now(); - - // Check parameters - if ($this->datef <= $this->dateh) { - $this->error = $langs->trans("ErrorBadValueForDate"); - return -1; - } - if (empty($this->datec)) { - $this->datec = $now; - } - - $this->db->begin(); - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)"; - - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member = new Adherent($this->db); - $result = $member->fetch($this->fk_adherent); - - if ($this->fk_type == null) { // If type not defined, we use the type of member - $type = $member->typeid; - } else { - $type = $this->fk_type; - } - $sql .= " VALUES (".((int) $this->fk_adherent).", '".$this->db->escape($type)."', '".$this->db->idate($now)."',"; - $sql .= " '".$this->db->idate($this->dateh)."',"; - $sql .= " '".$this->db->idate($this->datef)."',"; - $sql .= " ".((float) $this->amount).","; - $sql .= " '".$this->db->escape($this->note_public ? $this->note_public : $this->note)."')"; - - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->errors[] = $this->db->lasterror(); - } - - if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - $this->fk_type = $type; - } - - if (!$error && !$notrigger) { - $this->context = array('member' => $member); - // Call triggers - $result = $this->call_trigger('MEMBER_SUBSCRIPTION_CREATE', $user); - if ($result < 0) { - $error++; - } - // End call triggers - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return $this->id; - } - } - - - /** - * Method to load a subscription - * - * @param int $rowid Id subscription - * @return int Return integer <0 if KO, =0 if not found, >0 if OK - */ - public function fetch($rowid) - { - $sql = "SELECT rowid, fk_type, fk_adherent, datec,"; - $sql .= " tms,"; - $sql .= " dateadh as dateh,"; - $sql .= " datef,"; - $sql .= " subscription, note as note_public, fk_bank"; - $sql .= " FROM ".MAIN_DB_PREFIX."subscription"; - $sql .= " WHERE rowid = ".((int) $rowid); - - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - - $this->fk_type = $obj->fk_type; - $this->fk_adherent = $obj->fk_adherent; - $this->datec = $this->db->jdate($obj->datec); - $this->datem = $this->db->jdate($obj->tms); - $this->dateh = $this->db->jdate($obj->dateh); - $this->datef = $this->db->jdate($obj->datef); - $this->amount = $obj->subscription; - $this->note = $obj->note_public; // deprecated - $this->note_public = $obj->note_public; - $this->fk_bank = $obj->fk_bank; - return 1; - } else { - return 0; - } - } else { - $this->error = $this->db->lasterror(); - return -1; - } - } - - - /** - * Update subscription - * - * @param User $user User who updated - * @param int $notrigger 0=Disable triggers - * @return int Return integer <0 if KO, >0 if OK - */ - public function update($user, $notrigger = 0) - { - $error = 0; - - $this->db->begin(); - - if (!is_numeric($this->amount)) { - $this->error = 'BadValueForParameterAmount'; - return -1; - } - - if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility - $this->note_public = $this->note; - } - - $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET "; - $sql .= " fk_type = ".((int) $this->fk_type).","; - $sql .= " fk_adherent = ".((int) $this->fk_adherent).","; - $sql .= " note = ".($this->note_public ? "'".$this->db->escape($this->note_public)."'" : 'null').","; - $sql .= " subscription = ".price2num($this->amount).","; - $sql .= " dateadh = '".$this->db->idate($this->dateh)."',"; - $sql .= " datef = '".$this->db->idate($this->datef)."',"; - $sql .= " datec = '".$this->db->idate($this->datec)."',"; - $sql .= " fk_bank = ".($this->fk_bank ? ((int) $this->fk_bank) : 'null'); - $sql .= " WHERE rowid = ".((int) $this->id); - - dol_syslog(get_class($this)."::update", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member = new Adherent($this->db); - $result = $member->fetch($this->fk_adherent); - $result = $member->update_end_date($user); - - if (!$error && !$notrigger) { - $this->context = array('member'=>$member); - // Call triggers - $result = $this->call_trigger('MEMBER_SUBSCRIPTION_MODIFY', $user); - if ($result < 0) { - $error++; - } //Do also here what you must do to rollback action if trigger fail - // End call triggers - } - } else { - $error++; - $this->error = $this->db->lasterror(); - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return $this->id; - } - } - - /** - * Delete a subscription - * - * @param User $user User that delete - * @param bool $notrigger false=launch triggers after, true=disable triggers - * @return int Return integer <0 if KO, 0 if not found, >0 if OK - */ - public function delete($user, $notrigger = false) - { - $error = 0; - - // It subscription is linked to a bank transaction, we get it - if ($this->fk_bank > 0) { - require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - $accountline = new AccountLine($this->db); - $result = $accountline->fetch($this->fk_bank); - } - - $this->db->begin(); - - if (!$error) { - if (!$notrigger) { - // Call triggers - $result = $this->call_trigger('MEMBER_SUBSCRIPTION_DELETE', $user); - if ($result < 0) { - $error++; - } // Do also here what you must do to rollback action if trigger fail - // End call triggers - } - } - - if (!$error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE rowid = ".((int) $this->id); - dol_syslog(get_class($this)."::delete", LOG_DEBUG); - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->affected_rows($resql); - if ($num) { - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; - $member = new Adherent($this->db); - $result = $member->fetch($this->fk_adherent); - $result = $member->update_end_date($user); - - if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) { // If we found bank account line (this means this->fk_bank defined) - $result = $accountline->delete($user); // Return false if refused because line is reconciled - if ($result > 0) { - $this->db->commit(); - return 1; - } else { - $this->error = $accountline->error; - $this->db->rollback(); - return -1; - } - } else { - $this->db->commit(); - return 1; - } - } else { - $this->db->commit(); - return 0; - } - } else { - $error++; - $this->error = $this->db->lasterror(); - } - } - - // Commit or rollback - if ($error) { - $this->db->rollback(); - return -1; - } else { - $this->db->commit(); - return 1; - } - } - - - /** - * Return clicable name (with picto eventually) - * - * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto - * @param int $notooltip 1=Disable tooltip - * @param string $option Page for link ('', 'nolink', ...) - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking - * @return string Chaine avec URL - */ - public function getNomUrl($withpicto = 0, $notooltip = 0, $option = '', $morecss = '', $save_lastsearch_value = -1) - { - global $langs; - - $result = ''; - - $langs->load("members"); - - $label = img_picto('', $this->picto).' '.$langs->trans("Subscription").''; - /*if (isset($this->statut)) { - $label .= ' '.$this->getLibStatut(5); - }*/ - $label .= '
'.$langs->trans('Ref').': '.$this->ref; - if (!empty($this->dateh)) { - $label .= '
'.$langs->trans('DateStart').': '.dol_print_date($this->dateh, 'day'); - } - if (!empty($this->datef)) { - $label .= '
'.$langs->trans('DateEnd').': '.dol_print_date($this->datef, 'day'); - } - - $url = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.((int) $this->id); - - if ($option != 'nolink') { - // Add param to save lastsearch_values or not - $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { - $add_save_lastsearch_values = 1; - } - if ($add_save_lastsearch_values) { - $url .= '&save_lastsearch_values=1'; - } - } - - $linkstart = ''; - $linkend = ''; - - $result .= $linkstart; - if ($withpicto) { - $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - } - if ($withpicto != 2) { - $result .= $this->ref; - } - $result .= $linkend; - - return $result; - } - - - /** - * Return the label of the status - * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status - */ - public function getLibStatut($mode = 0) - { - return ''; - } - - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Return the label of a given status - * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @return string Label of status - */ - public function LibStatut($status, $mode = 0) - { - // phpcs:enable - global $langs; - - //$langs->load("members"); - - return ''; - } - - /** - * Load information of the subscription object - * - * @param int $id Id subscription - * @return void - */ - public function info($id) - { - $sql = 'SELECT c.rowid, c.datec,'; - $sql .= ' c.tms as datem'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'subscription as c'; - $sql .= ' WHERE c.rowid = '.((int) $id); - - $resql = $this->db->query($sql); - if ($resql) { - if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); - $this->id = $obj->rowid; - - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datem); - } - - $this->db->free($resql); - } else { - dol_print_error($this->db); - } - } - - /** - * Return clicable link of object (with eventually picto) - * - * @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) - * @param array $arraydata Array of data - * @return string HTML Code for Kanban thumb. - */ - public function getKanbanView($option = '', $arraydata = null) - { - $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); - - $return = '
'; - $return .= '
'; - $return .= ''; - $return .= img_picto('', $this->picto); - $return .= ''; - - $return .= '
'; - $return .= ''; - $return .= $this->getNomUrl(-1); - $return .= ''; - if ($selected >= 0) { - $return .= ''; - } - if (property_exists($this, 'dateh') || property_exists($this, 'datef')) { - $return .= '
'.dol_print_date($this->dateh, 'day').' - '.dol_print_date($this->datef, 'day').''; - } - - if (!empty($arraydata['member']) && is_object($arraydata['member'])) { - $return .= '
'.$arraydata['member']->getNomUrl(-4).''; - } - - if (property_exists($this, 'amount')) { - $return .= '
'.price($this->amount).''; - if (!empty($arraydata['bank'])) { - $return .= '   '.$arraydata['bank']->getNomUrl(-1).''; - } - } - $return .= '
'; - $return .= '
'; - $return .= '
'; - return $return; - } + /** + * @var string ID to identify managed object + */ + public $element = 'subscription'; + + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'subscription'; + + /** + * @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by fk_soc, 'field@table'=Test with link by field@table + */ + public $ismultientitymanaged = 'fk_adherent@adherent'; + + /** + * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png + */ + public $picto = 'payment'; + + /** + * Date creation record (datec) + * + * @var integer + */ + public $datec; + + /** + * Date modification record (tms) + * + * @var integer + */ + public $datem; + + /** + * Subscription start date (date subscription) + * + * @var integer + */ + public $dateh; + + /** + * Subscription end date + * + * @var integer + */ + public $datef; + + /** + * @var int ID + */ + public $fk_type; + public $fk_adherent; + + public $amount; + + /** + * @var int ID + */ + public $fk_bank; + + public $fields = array( + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), + 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>15), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>20), + 'fk_adherent' =>array('type'=>'integer', 'label'=>'Member', 'enabled'=>1, 'visible'=>-1, 'position'=>25), + 'dateadh' =>array('type'=>'datetime', 'label'=>'DateSubscription', 'enabled'=>1, 'visible'=>-1, 'position'=>30), + 'datef' =>array('type'=>'date', 'label'=>'DateEndSubscription', 'enabled'=>1, 'visible'=>-1, 'position'=>35), + 'subscription' =>array('type'=>'double(24,8)', 'label'=>'Amount', 'enabled'=>1, 'visible'=>-1, 'position'=>40, 'isameasure'=>1), + 'fk_bank' =>array('type'=>'integer', 'label'=>'BankId', 'enabled'=>1, 'visible'=>-1, 'position'=>45), + 'note' =>array('type'=>'text', 'label'=>'Note', 'enabled'=>1, 'visible'=>-1, 'position'=>50), + 'fk_type' =>array('type'=>'integer', 'label'=>'MemberType', 'enabled'=>1, 'visible'=>-1, 'position'=>55), + 'fk_user_creat' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'position'=>60), + 'fk_user_valid' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>65), + ); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; + } + + + /** + * Function who permitted cretaion of the subscription + * + * @param User $user User that create + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, Id subscription created if OK + */ + public function create($user, $notrigger = false) + { + global $langs; + + $error = 0; + + $now = dol_now(); + + // Check parameters + if ($this->datef <= $this->dateh) + { + $this->error = $langs->trans("ErrorBadValueForDate"); + return -1; + } + if (empty($this->datec)) $this->datec = $now; + + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."subscription (fk_adherent, fk_type, datec, dateadh, datef, subscription, note)"; + + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member = new Adherent($this->db); + $result = $member->fetch($this->fk_adherent); + + if ($this->fk_type == null) { // If type not defined, we use the type of member + $type = $member->typeid; + } else { + $type = $this->fk_type; + } + $sql .= " VALUES (".$this->fk_adherent.", '".$type."', '".$this->db->idate($now)."',"; + $sql .= " '".$this->db->idate($this->dateh)."',"; + $sql .= " '".$this->db->idate($this->datef)."',"; + $sql .= " ".$this->amount.","; + $sql .= " '".$this->db->escape($this->note_public ? $this->note_public : $this->note)."')"; + + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + + if (!$error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->fk_type = $type; + } + + if (!$error && !$notrigger) + { + $this->context = array('member'=>$member); + // Call triggers + $result = $this->call_trigger('MEMBER_SUBSCRIPTION_CREATE', $user); + if ($result < 0) { $error++; } + // End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } + } + + + /** + * Method to load a subscription + * + * @param int $rowid Id subscription + * @return int <0 if KO, =0 if not found, >0 if OK + */ + public function fetch($rowid) + { + $sql = "SELECT rowid, fk_type, fk_adherent, datec,"; + $sql .= " tms,"; + $sql .= " dateadh as dateh,"; + $sql .= " datef,"; + $sql .= " subscription, note, fk_bank"; + $sql .= " FROM ".MAIN_DB_PREFIX."subscription"; + $sql .= " WHERE rowid=".$rowid; + + dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->fk_type = $obj->fk_type; + $this->fk_adherent = $obj->fk_adherent; + $this->datec = $this->db->jdate($obj->datec); + $this->datem = $this->db->jdate($obj->tms); + $this->dateh = $this->db->jdate($obj->dateh); + $this->datef = $this->db->jdate($obj->datef); + $this->amount = $obj->subscription; + $this->note = $obj->note; + $this->fk_bank = $obj->fk_bank; + return 1; + } + else + { + return 0; + } + } + else + { + $this->error = $this->db->lasterror(); + return -1; + } + } + + + /** + * Update subscription + * + * @param User $user User who updated + * @param int $notrigger 0=Disable triggers + * @return int <0 if KO, >0 if OK + */ + public function update($user, $notrigger = 0) + { + $error = 0; + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."subscription SET "; + $sql .= " fk_type = ".$this->fk_type.","; + $sql .= " fk_adherent = ".$this->fk_adherent.","; + $sql .= " note=".($this->note ? "'".$this->db->escape($this->note)."'" : 'null').","; + $sql .= " subscription = '".price2num($this->amount)."',"; + $sql .= " dateadh='".$this->db->idate($this->dateh)."',"; + $sql .= " datef='".$this->db->idate($this->datef)."',"; + $sql .= " datec='".$this->db->idate($this->datec)."',"; + $sql .= " fk_bank = ".($this->fk_bank ? $this->fk_bank : 'null'); + $sql .= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member = new Adherent($this->db); + $result = $member->fetch($this->fk_adherent); + $result = $member->update_end_date($user); + + if (!$error && !$notrigger) { + $this->context = array('member'=>$member); + // Call triggers + $result = $this->call_trigger('MEMBER_SUBSCRIPTION_MODIFY', $user); + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail + // End call triggers + } + } + else + { + $error++; + $this->error = $this->db->lasterror(); + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return $this->id; + } + } + + /** + * Delete a subscription + * + * @param User $user User that delete + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function delete($user, $notrigger = false) + { + $error = 0; + + // It subscription is linked to a bank transaction, we get it + if ($this->fk_bank > 0) + { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $accountline = new AccountLine($this->db); + $result = $accountline->fetch($this->fk_bank); + } + + $this->db->begin(); + + if (!$error) { + if (!$notrigger) { + // Call triggers + $result = $this->call_trigger('MEMBER_SUBSCRIPTION_DELETE', $user); + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail + // End call triggers + } + } + + if (!$error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."subscription WHERE rowid = ".$this->id; + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $num = $this->db->affected_rows($resql); + if ($num) + { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; + $member = new Adherent($this->db); + $result = $member->fetch($this->fk_adherent); + $result = $member->update_end_date($user); + + if ($this->fk_bank > 0 && is_object($accountline) && $accountline->id > 0) // If we found bank account line (this means this->fk_bank defined) + { + $result = $accountline->delete($user); // Return false if refused because line is conciliated + if ($result > 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error = $accountline->error; + $this->db->rollback(); + return -1; + } + } + else + { + $this->db->commit(); + return 1; + } + } + else + { + $this->db->commit(); + return 0; + } + } + else + { + $error++; + $this->error = $this->db->lasterror(); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + return -1; + } else { + $this->db->commit(); + return 1; + } + } + + + /** + * Return clicable name (with picto eventually) + * + * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto + * @param int $notooltip 1=Disable tooltip + * @param string $option Page for link ('', 'nolink', ...) + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string Chaine avec URL + */ + public function getNomUrl($withpicto = 0, $notooltip = 0, $option = '', $morecss = '', $save_lastsearch_value = -1) + { + global $langs; + + $result = ''; + + $langs->load("members"); + $label = $langs->trans("ShowSubscription").': '.$this->ref; + + $url = DOL_URL_ROOT.'/adherents/subscription/card.php?rowid='.$this->id; + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; + if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + } + + $linkstart = ''; + $linkend = ''; + + $picto = 'payment'; + + $result .= $linkstart; + if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + if ($withpicto != 2) $result .= $this->ref; + $result .= $linkend; + + return $result; + } + + + /** + * Retourne le libelle du statut d'une adhesion + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label + */ + public function getLibStatut($mode = 0) + { + return ''; + } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Renvoi le libelle d'un statut donne + * + * @param int $status Id status + * @return string Label + */ + public function LibStatut($status) + { + // phpcs:enable + global $langs; + $langs->load("members"); + return ''; + } + + /** + * Load information of the subscription object + * + * @param int $id Id subscription + * @return void + */ + public function info($id) + { + $sql = 'SELECT c.rowid, c.datec,'; + $sql .= ' c.tms as datem'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'subscription as c'; + $sql .= ' WHERE c.rowid = '.$id; + + $result = $this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); + $this->id = $obj->rowid; + + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->datem); + } + + $this->db->free($result); + } + else + { + dol_print_error($this->db); + } + }