From 6c8dc75c960d7e459d52faa8a7d031e441e81d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 29 Sep 2019 11:20:23 +0200 Subject: [PATCH] socialnetworks for thirdparties --- htdocs/contact/card.php | 2 +- htdocs/societe/card.php | 201 ++++++++++++++++--------- htdocs/societe/class/societe.class.php | 48 +++++- 3 files changed, 169 insertions(+), 82 deletions(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index d122ae509a7..9689a2be18e 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -697,7 +697,7 @@ else foreach ($socialnetworks as $key => $value) { if ($value['active']) { print ''; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index ab224245de8..cdc1af37d4e 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -69,6 +69,8 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); +$socialnetworks = getArrayOfSocialNetworks(); + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('thirdpartycard','globalcard')); @@ -146,7 +148,7 @@ if (empty($reshook)) $object->client = $object->client | $soc_origin->client; $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; $listofproperties=array( - 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'linkedin', 'url', 'barcode', + 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'twitter', 'facebook', 'linkedin', 'socialnetworks', 'url', 'barcode', 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', @@ -405,11 +407,19 @@ if (empty($reshook)) $object->town = GETPOST('town', 'alpha'); $object->country_id = GETPOST('country_id', 'int'); $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->linkedin = GETPOST('linkedin', 'alpha'); - $object->phone = GETPOST('phone', 'alpha'); + //$object->skype = GETPOST('skype', 'alpha'); + //$object->twitter = GETPOST('twitter', 'alpha'); + //$object->facebook = GETPOST('facebook', 'alpha'); + //$object->linkedin = GETPOST('linkedin', 'alpha'); + $object->socialnetworks = array(); + if (! empty($conf->socialnetworks->enabled)) { + foreach ($socialnetworks as $key => $value) { + if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml')!='') { + $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + } + } + } + $object->phone = GETPOST('phone', 'alpha'); $object->fax = GETPOST('fax', 'alpha'); $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); @@ -971,10 +981,18 @@ else $object->zip = GETPOST('zipcode', 'alpha'); $object->town = GETPOST('town', 'alpha'); $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->linkedin = GETPOST('linkedin', 'alpha'); + //$object->skype = GETPOST('skype', 'alpha'); + //$object->twitter = GETPOST('twitter', 'alpha'); + //$object->facebook = GETPOST('facebook', 'alpha'); + //$object->linkedin = GETPOST('linkedin', 'alpha'); + $object->socialnetworks = array(); + if (! empty($conf->socialnetworks->enabled)) { + foreach ($socialnetworks as $key => $value) { + if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml')!='') { + $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + } + } + } $object->phone = GETPOST('phone', 'alpha'); $object->fax = GETPOST('fax', 'alpha'); $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); @@ -1295,42 +1313,57 @@ else print ''.$form->editfieldkey('Web', 'url', '', $object, 0).''; print ''; - if (! empty($conf->socialnetworks->enabled)) - { - // Skype - if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) - { - print ''.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; - print ''; - print 'skype).'">'; - print ''; - } - // Twitter - if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) - { - print ''.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; - print ''; - print 'twitter).'">'; - print ''; - } - // Facebook - if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) - { - print ''.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; - print ''; - print 'facebook).'">'; - print ''; - } - // LinkedIn - if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN)) - { - print ''.$form->editfieldkey('LinkedIn', 'linkedin', '', $object, 0).''; - print ''; - print 'linkedin).'">'; - print ''; + if (! empty($conf->socialnetworks->enabled)) { + foreach ($socialnetworks as $key => $value) { + if ($value['active']) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } elseif (!empty($object->socialnetworks[$key])) { + print ''; + } } } + // if (! empty($conf->socialnetworks->enabled)) + // { + // // Skype + // if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) + // { + // print ''.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; + // print ''; + // print 'skype).'">'; + // print ''; + // } + // // Twitter + // if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) + // { + // print ''.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; + // print ''; + // print 'twitter).'">'; + // print ''; + // } + // // Facebook + // if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) + // { + // print ''.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; + // print ''; + // print 'facebook).'">'; + // print ''; + // } + // // LinkedIn + // if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN)) + // { + // print ''.$form->editfieldkey('LinkedIn', 'linkedin', '', $object, 0).''; + // print ''; + // print 'linkedin).'">'; + // print ''; + // } + // } + // Phone / Fax print ''.$form->editfieldkey('Phone', 'phone', '', $object, 0).''; print ''; @@ -1609,10 +1642,18 @@ else $object->town = GETPOST('town', 'alpha'); $object->country_id = GETPOST('country_id')?GETPOST('country_id', 'int'):$mysoc->country_id; $object->state_id = GETPOST('state_id', 'int'); - $object->skype = GETPOST('skype', 'alpha'); - $object->twitter = GETPOST('twitter', 'alpha'); - $object->facebook = GETPOST('facebook', 'alpha'); - $object->linkedin = GETPOST('linkedin', 'alpha'); + //$object->skype = GETPOST('skype', 'alpha'); + //$object->twitter = GETPOST('twitter', 'alpha'); + //$object->facebook = GETPOST('facebook', 'alpha'); + //$object->linkedin = GETPOST('linkedin', 'alpha'); + $object->socialnetworks = array(); + if (! empty($conf->socialnetworks->enabled)) { + foreach ($socialnetworks as $key => $value) { + if (GETPOSTISSET($key) && GETPOST($key, 'alphanohtml')!='') { + $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml'); + } + } + } $object->phone = GETPOST('phone', 'alpha'); $object->fax = GETPOST('fax', 'alpha'); $object->email = GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL); @@ -1918,33 +1959,47 @@ else print ''.$form->editfieldkey('Web', 'url', '', $object, 0).''; print ''; - if (! empty($conf->socialnetworks->enabled)) - { - // Skype - if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) - { - print ''.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; - print ''; - } - // Twitter - if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) - { - print ''.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; - print ''; - } - // Facebook - if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) - { - print ''.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; - print ''; - } - // LinkedIn - if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN)) - { - print ''.$form->editfieldkey('LinkedIn', 'linkedin', '', $object, 0).''; - print ''; + if (! empty($conf->socialnetworks->enabled)) { + foreach ($socialnetworks as $key => $value) { + if ($value['active']) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } elseif (!empty($object->socialnetworks[$key])) { + print ''; + } } - } + } + // if (! empty($conf->socialnetworks->enabled)) + // { + // // Skype + // if (! empty($conf->global->SOCIALNETWORKS_SKYPE)) + // { + // print ''.$form->editfieldkey('Skype', 'skype', '', $object, 0).''; + // print ''; + // } + // // Twitter + // if (! empty($conf->global->SOCIALNETWORKS_TWITTER)) + // { + // print ''.$form->editfieldkey('Twitter', 'twitter', '', $object, 0).''; + // print ''; + // } + // // Facebook + // if (! empty($conf->global->SOCIALNETWORKS_FACEBOOK)) + // { + // print ''.$form->editfieldkey('Facebook', 'facebook', '', $object, 0).''; + // print ''; + // } + // // LinkedIn + // if (! empty($conf->global->SOCIALNETWORKS_LINKEDIN)) + // { + // print ''.$form->editfieldkey('LinkedIn', 'linkedin', '', $object, 0).''; + // print ''; + // } + // } // Phone / Fax print ''.$form->editfieldkey('Phone', 'phone', '', $object, 0).''; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index ef2f5f66868..3c79e6ff61a 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -15,6 +15,7 @@ * Copyright (C) 2017 Rui Strecht * Copyright (C) 2018 Philippe Grand * Copyright (C) 2019 Josep Lluís Amador + * Copyright (C) 2019 Frédéric France * * 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 @@ -1013,7 +1014,8 @@ class Societe extends CommonObject $sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null"); $sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null"); - $sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null"); + $sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null"); + $sql .= ", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks))."'"; $sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null"); $sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null"); $sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null"); @@ -1363,12 +1365,41 @@ class Societe extends CommonObject $this->stcomm_id = $obj->fk_stcomm; // id statut commercial $this->statut_commercial = $libelle; // libelle statut commercial - $this->email = $obj->email; - $this->skype = $obj->skype; - $this->twitter = $obj->twitter; - $this->facebook = $obj->facebook; - $this->linkedin = $obj->linkedin; - $this->socialnetworks = json_decode($obj->socialnetworks); + $this->email = $obj->email; + $arraysocialnetworks = array(); + $updatesocial = false; + if (!empty($obj->skype)) { + $arraysocialnetworks['skype'] = $obj->skype; + $updatesocial = true; + } + if (!empty($obj->twitter)) { + $arraysocialnetworks['twitter'] = $obj->twitter; + $updatesocial = true; + } + if (!empty($obj->facebook)) { + $arraysocialnetworks['facebook'] = $obj->facebook; + $updatesocial = true; + } + if (!empty($obj->linkedin)) { + $arraysocialnetworks['linkedin'] = $obj->linkedin; + $updatesocial = true; + } + $socialarray = ($obj->socialnetworks==''?array():json_decode($obj->socialnetworks, true)); + $this->socialnetworks = array_merge($arraysocialnetworks, $socialarray); + if ($updatesocial) { + $sqlupd = 'UPDATE '.MAIN_DB_PREFIX.'societe SET skype=null'; + $sqlupd .= ', twitter=null'; + $sqlupd .= ', facebook=null'; + $sqlupd .= ', linkedin=null'; + $sqlupd .= ', socialnetworks="'.$this->db->escape(json_encode($this->socialnetworks)).'"'; + $sqlupd .= ' WHERE rowid='.$this->id; + $this->db->query($sqlupd); + } + + $this->skype = $this->socialnetworks['skype']; + $this->twitter = $this->socialnetworks['twitter']; + $this->facebook = $this->socialnetworks['facebook']; + $this->linkedin = $this->socialnetworks['linkedin']; $this->url = $obj->url; $this->phone = $obj->phone; @@ -3410,7 +3441,8 @@ class Societe extends CommonObject $this->skype=$member->skype; $this->twitter=$member->twitter; $this->facebook=$member->facebook; - $this->linkedin=$member->linkedin; + $this->linkedin=$member->linkedin; + $this->socialnetworks = $member->socialnetworks; $this->client = 1; // A member is a customer by default $this->code_client = ($customercode?$customercode:-1);