diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 9dbe3bb5928..203ded8cedd 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -241,6 +241,62 @@ class Adherent extends CommonObject */ public $entity; + + public $fields=array( + 'rowid' =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>10), + 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'default'=>1, 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15, 'index'=>1), + 'ref_ext' =>array('type'=>'varchar(128)', 'label'=>'Ref ext', 'enabled'=>1, 'visible'=>0, 'position'=>20), + 'civility' =>array('type'=>'varchar(6)', 'label'=>'Civility', 'enabled'=>1, 'visible'=>-1, 'position'=>25), + '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), + 'pass' =>array('type'=>'varchar(50)', 'label'=>'Pass', 'enabled'=>1, 'visible'=>-1, 'position'=>45), + 'pass_crypted' =>array('type'=>'varchar(128)', 'label'=>'Pass crypted', 'enabled'=>1, 'visible'=>-1, 'position'=>50), + '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), + 'address' =>array('type'=>'text', 'label'=>'Address', 'enabled'=>1, 'visible'=>-1, 'position'=>75), + 'zip' =>array('type'=>'varchar(10)', 'label'=>'Zip', 'enabled'=>1, 'visible'=>-1, 'position'=>80), + 'town' =>array('type'=>'varchar(50)', 'label'=>'Town', 'enabled'=>1, 'visible'=>-1, 'position'=>85), + 'state_id' =>array('type'=>'integer', 'label'=>'State id', 'enabled'=>1, 'visible'=>-1, 'position'=>90), + 'country' =>array('type'=>'integer', '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), + //'skype' =>array('type'=>'varchar(255)', 'label'=>'Skype', 'enabled'=>1, 'visible'=>-1, 'position'=>110), + 'phone' =>array('type'=>'varchar(30)', 'label'=>'Phone', 'enabled'=>1, 'visible'=>-1, 'position'=>115), + 'phone_perso' =>array('type'=>'varchar(30)', 'label'=>'Phone perso', 'enabled'=>1, 'visible'=>-1, 'position'=>120), + 'phone_mobile' =>array('type'=>'varchar(30)', 'label'=>'Phone mobile', 'enabled'=>1, 'visible'=>-1, 'position'=>125), + 'birth' =>array('type'=>'date', 'label'=>'DateToBirth', 'enabled'=>1, 'visible'=>-1, 'position'=>130), + 'photo' =>array('type'=>'varchar(255)', 'label'=>'Photo', 'enabled'=>1, 'visible'=>-1, 'position'=>135), + 'public' =>array('type'=>'smallint(6)', 'label'=>'Public', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>145), + '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), + 'datevalid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>165), + 'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-1, 'position'=>170), + 'tms' =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>175), + 'fk_user_author' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user author', 'enabled'=>1, 'visible'=>-1, 'position'=>180), + 'fk_user_mod' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'Fk user mod', 'enabled'=>1, 'visible'=>-1, 'position'=>185), + 'fk_user_valid' =>array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>190), + 'canvas' =>array('type'=>'varchar(32)', 'label'=>'Canvas', 'enabled'=>1, 'visible'=>-1, 'position'=>195), + 'statut' =>array('type'=>'smallint(6)', 'label'=>'Statut', 'enabled'=>1, 'visible'=>-1, 'notnull'=>1, 'position'=>500, 'arrayofkeyval'=>array(0=>'Draft', 1=>'Validated', -1=>'MemberStatusResiliatedShort')), + 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'Model pdf', 'enabled'=>1, 'visible'=>0, 'position'=>800), + 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>805), + /*'twitter' =>array('type'=>'varchar(255)', 'label'=>'Twitter', 'enabled'=>1, 'visible'=>-1, 'position'=>210), + 'facebook' =>array('type'=>'varchar(255)', 'label'=>'Facebook', 'enabled'=>1, 'visible'=>-1, 'position'=>215), + 'instagram' =>array('type'=>'varchar(255)', 'label'=>'Instagram', 'enabled'=>1, 'visible'=>-1, 'position'=>220), + 'snapchat' =>array('type'=>'varchar(255)', 'label'=>'Snapchat', 'enabled'=>1, 'visible'=>-1, 'position'=>225), + 'googleplus' =>array('type'=>'varchar(255)', 'label'=>'Googleplus', 'enabled'=>1, 'visible'=>-1, 'position'=>230), + 'youtube' =>array('type'=>'varchar(255)', 'label'=>'Youtube', 'enabled'=>1, 'visible'=>-1, 'position'=>235), + 'whatsapp' =>array('type'=>'varchar(255)', 'label'=>'Whatsapp', 'enabled'=>1, 'visible'=>-1, 'position'=>240), + 'linkedin' =>array('type'=>'varchar(255)', 'label'=>'Linkedin', 'enabled'=>1, 'visible'=>-1, 'position'=>245),*/ + ); + + + + /** * Constructor * diff --git a/htdocs/adherents/class/subscription.class.php b/htdocs/adherents/class/subscription.class.php index e2fc13edadf..99a0c113e9a 100644 --- a/htdocs/adherents/class/subscription.class.php +++ b/htdocs/adherents/class/subscription.class.php @@ -42,6 +42,11 @@ class Subscription extends CommonObject */ 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 */ @@ -88,6 +93,21 @@ class Subscription extends CommonObject */ 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 diff --git a/htdocs/core/customreports.php b/htdocs/core/customreports.php index 3d245218807..f278de1a506 100644 --- a/htdocs/core/customreports.php +++ b/htdocs/core/customreports.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2020 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT."/core/class/dolgraph.class.php"; require_once DOL_DOCUMENT_ROOT."/core/class/doleditor.class.php"; // Load traductions files requiredby by page -$langs->loadLangs(array("companies", "contracts", "bills", "other", "exports")); +$langs->loadLangs(array("companies", "bills", "other", "exports")); // Get parameters $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... @@ -73,33 +73,17 @@ $head = array(); $object = null; $ObjectClassName = ''; $arrayoftype = array( - 'thirdparty' => array('label' => 'ThirdParties', 'ObjectClassName' => 'Societe'), - 'contact' => array('label' => 'Contacts', 'ObjectClassName' => 'Contact'), - 'contract' => array('label' => 'Contracts', 'ObjectClassName' => 'Contrat'), - 'invoice' => array('label' => 'Invoices', 'ObjectClassName' => 'Facture'), - 'invoice_template'=>array('label' => 'PredefinedInvoices', 'ObjectClassName' => 'FactureRec'), - 'bom' => array('label' => 'BOM', 'ObjectClassName' => 'Bom'), - 'mo' => array('label' => 'MO', 'ObjectClassName' => 'Mo'), - 'ticket' => array('label' => 'Ticket', 'ObjectClassName' => 'Ticket'), + 'thirdparty' => array('label' => 'ThirdParties', 'ObjectClassName' => 'Societe', 'enabled' => $conf->societe->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"), + 'contact' => array('label' => 'Contacts', 'ObjectClassName' => 'Contact', 'enabled' => $conf->societe->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/contact/class/contact.class.php"), + 'contract' => array('label' => 'Contracts', 'ObjectClassName' => 'Contrat', 'enabled' => $conf->contrat->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php", 'langs'=>'contract'), + 'invoice' => array('label' => 'Invoices', 'ObjectClassName' => 'Facture', 'enabled' => $conf->facture->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"), + 'invoice_template'=>array('label' => 'PredefinedInvoices', 'ObjectClassName' => 'FactureRec', 'enabled' => $conf->facture->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/compta/class/facturerec.class.php"), + 'bom' => array('label' => 'BOM', 'ObjectClassName' => 'Bom', 'enabled' => $conf->bom->enabled), + 'mo' => array('label' => 'MO', 'ObjectClassName' => 'Mo', 'enabled' => $conf->mo->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/mrp/class/mo.class.php"), + 'ticket' => array('label' => 'Ticket', 'ObjectClassName' => 'Ticket', 'enabled' => $conf->ticket->enabled), + 'member' => array('label' => 'Adherent', 'ObjectClassName' => 'Adherent', 'enabled' => $conf->adherent->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php", 'langs'=>'members'), + 'cotisation' => array('label' => 'Subscriptions', 'ObjectClassName' => 'Subscription', 'enabled' => $conf->adherent->enabled, 'ClassPath' => DOL_DOCUMENT_ROOT."/adherents/class/subscription.class.php", 'langs'=>'members'), ); -if ($objecttype == 'thirdparty') { - require_once DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"; -} -elseif ($objecttype == 'contract') { - require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php"; -} -elseif ($objecttype == 'invoice') { - require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"; -} -elseif ($objecttype == 'invoice_template') { - require_once DOL_DOCUMENT_ROOT."/compta/facture/class/facture-rec.class.php"; -} -elseif ($objecttype == 'mo') { - require_once DOL_DOCUMENT_ROOT."/mrp/class/mo.class.php" ; -} -elseif ($objecttype) { - require_once DOL_DOCUMENT_ROOT."/".$objecttype."/class/".$objecttype.".class.php"; -} // Complete $arrayoftype $parameters = array('objecttype'=>$objecttype, 'tabfamily'=>$tabfamily); @@ -124,6 +108,14 @@ elseif (is_array($hookmanager->resArray)) { if ($objecttype) { try { + if ($arrayoftype[$objecttype]['langs']) { + $langs->load($arrayoftype[$objecttype]['langs']); + } + if ($arrayoftype[$objecttype]['ClassPath']) { + include_once $arrayoftype[$objecttype]['ClassPath']; + } else { + include_once DOL_DOCUMENT_ROOT."/".$objecttype."/class/".$objecttype.".class.php"; + } $ObjectClassName = $arrayoftype[$objecttype]['ObjectClassName']; $object = new $ObjectClassName($db); } @@ -249,6 +241,7 @@ foreach($object->fields as $key => $val) { if (isset($val['enabled']) && ! dol_eval($val['enabled'], 1)) continue; if (isset($val['visible']) && ! dol_eval($val['visible'], 1)) continue; if (preg_match('/^fk_/', $key) && ! preg_match('/^fk_statu/', $key)) continue; + if (preg_match('/^pass/', $key)) continue; if (in_array($val['type'], array('html', 'text'))) continue; if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) { $arrayofxaxis['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$langs->trans("Year").')', 'position' => $val['position']); @@ -370,8 +363,22 @@ if (! empty($search_measures) && ! empty($search_xaxis)) if ($object->isextrafieldmanaged) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.$object->table_element.'_extrafields as te ON te.fk_object = t.'.$fieldid; } + if ($object->ismultientitymanaged) { + if ($object->ismultientitymanaged == 1) { + // Nothing here + } else if ($object->ismultientitymanaged == 2) { + $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.'societe as parenttable ON t.fk_soc = parenttable.rowid'; + $sql .= ' AND parenttable.entity IN ('.getEntity('societe').')'; + } else { + $tmparray = explode('@', $object->ismultientitymanaged); + $sql .= ' INNER JOIN '.MAIN_DB_PREFIX.$tmparray[1].' as parenttable ON t.'.$tmparray[0].' = parenttable.rowid'; + $sql .= ' AND parenttable.entity IN ('.getEntity($tmparray[1]).')'; + } + } $sql .= ' WHERE 1 = 1'; - $sql .= ' AND entity IN ('.getEntity($object->element).')'; + if ($object->ismultientitymanaged == 1) { + $sql .= ' AND entity IN ('.getEntity($object->element).')'; + } foreach($search_filters as $key => $val) { // TODO } diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 1490169ec8d..c09f43cdedd 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -190,6 +190,8 @@ function restrictedArea($user, $features, $objectid = 0, $tableandshare = '', $f if ($features == 'facturerec') $features = 'facture'; if ($features == 'mo') $features = 'mrp'; + if ($features == 'member') $features = 'adherent'; + if ($features == 'subscription') { $features = 'adherent'; $feature2 = 'cotisation'; }; // Get more permissions checks from hooks $parameters = array('features'=>$features, 'objectid'=>$objectid, 'idtype'=>$dbt_select); diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index bbc4e08df23..531d8d224d9 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -659,6 +659,7 @@ if ($dirins && $action == 'confirm_removefile' && !empty($module)) } } +// Build the $fields array from SQL table (initfromtablename) if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', 'alpha')) { $tablename = GETPOST('initfromtablename', 'alpha'); @@ -757,6 +758,7 @@ if ($dirins && $action == 'initobject' && $module && GETPOST('createtablearray', // position $position = $i; if (in_array($fieldname, array('status', 'statut', 'fk_status', 'fk_statut'))) $position = 500; + if ($fieldname == 'import_key') $position = 900; // index $index = 0; if ($fieldname == 'entity') $index = 1; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index afa906be06c..5c30783f8e5 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -43,7 +43,8 @@ class MyObject extends CommonObject public $table_element = 'mymodule_myobject'; /** - * @var int Does myobject support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + * @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 = 0;