diff --git a/.tx/class/autotranslator.class.php b/.tx/class/autotranslator.class.php index 3db343c..afa4dae 100644 --- a/.tx/class/autotranslator.class.php +++ b/.tx/class/autotranslator.class.php @@ -27,7 +27,7 @@ */ class AutoTranslator { - private $translatedFiles = array(); + private $translatedFiles = []; private $destlang = ''; private $refLang = ''; private $langDir = ''; @@ -88,9 +88,9 @@ private function parseRefLangTranslationFiles() print "Processing file " . $file . ", with " . count($fileContent) . " lines
\n"; // Define target dirs - $targetlangs = array($this->destlang); + $targetlangs = [$this->destlang]; if ($this->destlang == 'all') { - $targetlangs = array(); + $targetlangs = []; // If we must process all languages $arraytmp = dol_dir_list($this->langDir, 'directories', 0); @@ -130,7 +130,7 @@ private function parseRefLangTranslationFiles() // Process translation of source file for each target languages foreach ($targetlangs as $my_destlang) { - $this->translatedFiles = array(); + $this->translatedFiles = []; $destPath = $this->langDir . $my_destlang . self::DIR_SEPARATOR . $file; // Check destination file presence @@ -238,9 +238,9 @@ private function translateFileLine($content, $file, $key, $value, $my_destlang) } else { // If not translated then translate if ($this->outputpagecode == 'UTF-8') { - $val = $this->translateTexts(array($value), substr($this->refLang, 0, 2), substr($my_destlang, 0, 2)); + $val = $this->translateTexts([$value], substr($this->refLang, 0, 2), substr($my_destlang, 0, 2)); } else { - $val = utf8_decode($this->translateTexts(array($value), substr($this->refLang, 0, 2), substr($my_destlang, 0, 2))); + $val = utf8_decode($this->translateTexts([$value], substr($this->refLang, 0, 2), substr($my_destlang, 0, 2))); } } diff --git a/.tx/class/translate.class.php b/.tx/class/translate.class.php index 17f84b3..6d831a0 100644 --- a/.tx/class/translate.class.php +++ b/.tx/class/translate.class.php @@ -35,11 +35,11 @@ class Translate public $shortlang; // Short language for current user public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs - public $tab_translate = array(); // Array of all translations key=>value - private $tab_loaded = array(); // Array to store result after loading each language file + public $tab_translate = []; // Array of all translations key=>value + private $tab_loaded = []; // Array to store result after loading each language file - public $cache_labels = array(); // Cache for labels return by getLabelFromKey method - public $cache_currencies = array(); // Cache to store currency symbols + public $cache_labels = []; // Cache for labels return by getLabelFromKey method + public $cache_currencies = []; // Cache to store currency symbols private $cache_currencies_all_loaded = false; /** @@ -49,7 +49,7 @@ class Translate */ public function __construct($dir) { - $this->dir = array($dir); + $this->dir = [$dir]; } @@ -80,13 +80,13 @@ public function setDefaultLang($srclang = 'en_US') //print "Short code before _ : ".$langpart[0].' / Short code after _ : '.$langpart[1].'
'; if (!empty($langpart[1])) { // If it's for a codetouse that is a long code xx_YY // Array force long code from first part, even if long code is defined - $longforshort = array('ar' => 'ar_SA'); - $longforshortexcep = array('ar_EG'); + $longforshort = ['ar' => 'ar_SA']; + $longforshortexcep = ['ar_EG']; if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) { $srclang = $longforshort[strtolower($langpart[0])]; } elseif (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]); - $longforlong = array('no_nb' => 'nb_NO'); + $longforlong = ['no_nb' => 'nb_NO']; if (isset($longforlong[strtolower($srclang)])) { $srclang = $longforlong[strtolower($srclang)]; } @@ -95,12 +95,12 @@ public function setDefaultLang($srclang = 'en_US') } } else { // If it's for a codetouse that is a short code xx // Array to convert short lang code into long code. - $longforshort = array( + $longforshort = [ 'am' => 'am_ET', 'ar' => 'ar_SA', 'bn' => 'bn_DB', 'el' => 'el_GR', 'ca' => 'ca_ES', 'cs' => 'cs_CZ', 'en' => 'en_US', 'fa' => 'fa_IR', 'gl' => 'gl_ES', 'he' => 'he_IL', 'hi' => 'hi_IN', 'ja' => 'ja_JP', 'ka' => 'ka_GE', 'km' => 'km_KH', 'kn' => 'kn_IN', 'ko' => 'ko_KR', 'lo' => 'lo_LA', 'nb' => 'nb_NO', 'no' => 'nb_NO', 'ne' => 'ne_NP', 'sl' => 'sl_SI', 'sq' => 'sq_AL', 'sr' => 'sr_RS', 'sv' => 'sv_SE', 'uk' => 'uk_UA', 'vi' => 'vi_VN', 'zh' => 'zh_CN' - ); + ]; if (isset($longforshort[strtolower($langpart[0])])) { $srclang = $longforshort[strtolower($langpart[0])]; } elseif (!empty($langpart[0])) { @@ -185,7 +185,7 @@ public function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = $modulename = ''; // Search if a module directory name is provided into lang file name - $regs = array(); + $regs = []; if (preg_match('/^([^@]+)@([^@]+)$/i', $domain, $regs)) { $newdomain = $regs[1]; $modulename = $regs[2]; @@ -204,7 +204,7 @@ public function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = // Redefine alt $langarray = explode('_', $langofdir); - if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) { + if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), ['el_gr']))) { $alt = 1; } if ($alt < 2 && strtolower($langofdir) == 'en_us') { @@ -255,7 +255,7 @@ public function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = continue; } else { // Convert some strings: Parse and render carriage returns. Also, change '\\s' into '\s' because transifex sync pull the string '\s' into string '\\s' - $this->tab_translate[$key] = str_replace(array('\\n', '\\\\s'), array("\n", '\s'), $value); + $this->tab_translate[$key] = str_replace(['\\n', '\\\\s'], ["\n", '\s'], $value); } } } @@ -359,7 +359,7 @@ private function getTradFromKey($key) } $newstr = $key; - $reg = array(); + $reg = []; if (preg_match('/^Civility([0-9A-Z]+)$/i', $key, $reg)) { $newstr = $this->getLabelFromKey($db, $reg[1], 'c_civility', 'code', 'label'); } elseif (preg_match('/^Currency([A-Z][A-Z][A-Z])$/i', $key, $reg)) { @@ -412,8 +412,8 @@ public function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 = // We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities because // we want to keep '"' '' '' '' '' '
' '< ' '' that are reliable HTML tags inside translation strings. $str = str_replace( - array('"', '', '', '', '', '', '
', '
', '', '', '
', '
', '', '< ', '>'), // We accept '< ' but not '<'. We can accept however '>' - array('__quot__', '__tagb__', '__tagbend__', '__tagu__', '__taguend__', '__tagi__', '__tagiend__', '__tagcenter__', '__tagcenterend__', '__tagb__', '__tagbend__', '__taga__', '__tagaend__', '__tagbr__', '__tagspan__', '__tagspanend__', '__ltspace__', '__gt__'), + ['"', '', '', '', '', '', '
', '
', '', '', '
', '
', '', '< ', '>'], // We accept '< ' but not '<'. We can accept however '>' + ['__quot__', '__tagb__', '__tagbend__', '__tagu__', '__taguend__', '__tagi__', '__tagiend__', '__tagcenter__', '__tagcenterend__', '__tagb__', '__tagbend__', '__taga__', '__tagaend__', '__tagbr__', '__tagspan__', '__tagspanend__', '__ltspace__', '__gt__'], $str ); @@ -426,8 +426,8 @@ public function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 = // Restore reliable HTML tags into original translation string $str = str_replace( - array('__quot__', '__tagb__', '__tagbend__', '__tagu__', '__taguend__', '__tagi__', '__tagiend__', '__tagcenter__', '__tagcenterend__', '__taga__', '__tagaend__', '__tagbr__', '__tagspan__', '__tagspanend__', '__ltspace__', '__gt__'), - array('"', '', '', '', '', '', '
', '
', '
', '
', '', '< ', '>'), + ['__quot__', '__tagb__', '__tagbend__', '__tagu__', '__taguend__', '__tagi__', '__tagiend__', '__tagcenter__', '__tagcenterend__', '__taga__', '__tagaend__', '__tagbr__', '__tagspan__', '__tagspanend__', '__ltspace__', '__gt__'], + ['"', '', '', '', '', '', '
', '
', '
', '
', '', '< ', '>'], $str ); @@ -584,13 +584,13 @@ public function getAvailableLanguages($langdir = DOL_DOCUMENT_ROOT, $maxlength = // We scan directory langs to detect available languages $handle = opendir($langdir . "/langs"); - $langs_available = array(); + $langs_available = []; while ($dir = trim(readdir($handle))) { - $regs = array(); + $regs = []; if (preg_match('/^([a-z]+)_([A-Z]+)/i', $dir, $regs)) { // We must keep only main languages if ($mainlangonly) { - $arrayofspecialmainlanguages = array( + $arrayofspecialmainlanguages = [ 'en' => 'en_US', 'am' => 'am_ET', 'ar' => 'ar_SA', @@ -619,7 +619,7 @@ public function getAvailableLanguages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 'uk' => 'uk_UA', 'vi' => 'vi_VN', 'zh' => 'zh_CN' - ); + ]; if (strtolower($regs[1]) != strtolower($regs[2]) && !in_array($dir, $arrayofspecialmainlanguages)) { continue; } @@ -697,7 +697,7 @@ public function getLabelFromNumber($number, $isamount = '') $newnumber = $number; - $dirsubstitutions = array_merge(array(), $conf->modules_parts['substitutions']); + $dirsubstitutions = array_merge([], $conf->modules_parts['substitutions']); foreach ($dirsubstitutions as $reldir) { $dir = dol_buildpath($reldir, 0); $newdir = dol_osencode($dir); @@ -798,7 +798,7 @@ public function getCurrencyAmount($currency_code, $amount) { $symbol = $this->getCurrencySymbol($currency_code); - if (in_array($currency_code, array('USD'))) { + if (in_array($currency_code, ['USD'])) { return $symbol . $amount; } else { return $amount . $symbol; @@ -859,7 +859,7 @@ public function loadCacheCurrencies($currency_code) $resql = $db->query($sql); if ($resql) { $this->load("dict"); - $label = array(); + $label = []; if (!empty($currency_code)) { foreach ($this->cache_currencies as $key => $val) { $label[$key] = $val['label']; // Label in already loaded cache diff --git a/.tx/config b/.tx/config deleted file mode 100644 index 1743c5d..0000000 --- a/.tx/config +++ /dev/null @@ -1,9 +0,0 @@ -[main] -host = https://www.transifex.com -lang_map = uz: uz_UZ - -[mymodule.mymodule] -file_filter = langs//mymodule.lang -source_file = langs/en_US/mymodule.lang -source_lang = en_US -type = MOZILLAPROPERTIES diff --git a/admin/oauthlogintokens.php b/admin/oauthlogintokens.php index 75ad7ba..47faa86 100644 --- a/admin/oauthlogintokens.php +++ b/admin/oauthlogintokens.php @@ -36,7 +36,7 @@ use League\OAuth2\Client\Provider\GoogleUser; // Load translation files required by the page -$langs->loadLangs(array('admin', 'oauth', 'googleapi@googleapi')); +$langs->loadLangs(["errors","admin","googleapi@googleapi"]); if (!$user->admin) { accessforbidden(); @@ -46,12 +46,12 @@ $value = GETPOST('value', 'alpha'); $varname = GETPOST('varname', 'alpha'); -$key = array( +$key = [ 'OAUTH_GOOGLEAPI_NAME', 'OAUTH_GOOGLEAPI_ID', 'OAUTH_GOOGLEAPI_SECRET', 'OAUTH_GOOGLEAPI_DESC', -); +]; /* diff --git a/admin/setup.php b/admin/setup.php index 3f3ac0c..92f96da 100644 --- a/admin/setup.php +++ b/admin/setup.php @@ -38,7 +38,7 @@ use Cache\Adapter\Filesystem\FilesystemCachePool; // Translations -$langs->loadLangs(array("admin", 'oauth', "googleapi@googleapi")); +$langs->loadLangs(["errors","admin","googleapi@googleapi"]); // Access control if (! $user->admin) { @@ -56,35 +56,35 @@ $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; //$urlwithroot = DOL_MAIN_URL_ROOT; // This is to use same domain name than current -$arrayofparameters = array( - 'OAUTH_GOOGLEAPI_ID' => array( +$arrayofparameters = [ + 'OAUTH_GOOGLEAPI_ID' => [ 'css' => 'minwidth500', 'type' => 'text', 'enabled' => 1, - ), - 'OAUTH_GOOGLEAPI_SECRET' => array( + ], + 'OAUTH_GOOGLEAPI_SECRET' => [ 'css' => 'minwidth500', 'type' => 'password', 'enabled' => 1, - ), - 'OAUTH_GOOGLEAPI_URI' => array( + ], + 'OAUTH_GOOGLEAPI_URI' => [ 'css' => 'minwidth500', 'default' => $urlwithroot . dol_buildpath('/googleapi/core/modules/oauth/googleapi_oauthcallback.php', 1), - ), - // 'GOOGLEAPI_MYPARAM1' => array( + ], + // 'GOOGLEAPI_MYPARAM1' => [ // 'css' => 'minwidth500', // 'type' => 'text', // 'enabled' => 1, - // ), - // 'GOOGLEAPI_MYPARAM2' => array( + // ], + // 'GOOGLEAPI_MYPARAM2' => [ // 'css' => 'minwidth500', // 'type' => 'text', // 'enabled' => 1, - // ) -); + // ], +]; // Paramètres ON/OFF GOOGLEAPI_ est rajouté au paramètre -$modules = array( +$modules = [ 'GOOGLEAPI_ENABLE_PUSH_ME_EVENTS' => 'GoogleApiEnablePushMeEvents', 'GOOGLEAPI_ENABLE_PUSH_ME_MESSAGES' => 'GoogleApiEnablePushMeMessages', 'GOOGLEAPI_ENABLE_PUSH_ME_CONTACTS' => 'GoogleApiEnablePushMeContacts', @@ -93,7 +93,7 @@ 'GOOGLEAPI_ENABLE_DEVELOPPER_MODE' => 'GoogleApiEnableDevelopperMode', // tweak dolibarr 'CHECKLASTVERSION_EXTERNALMODULE' => 'CHECKLASTVERSION_EXTERNALMODULE', -); +]; /* * Actions @@ -236,7 +236,7 @@ print '
' . PHP_EOL; } -dol_fiche_end(); +print dol_get_fiche_end(); // TESTS diff --git a/class/actions_googleapi.class.php b/class/actions_googleapi.class.php index da88012..82231e8 100644 --- a/class/actions_googleapi.class.php +++ b/class/actions_googleapi.class.php @@ -49,6 +49,10 @@ class ActionsGoogleApi */ public $errors = []; + /** + * @var array Warnings + */ + public $warnings = []; /** * @var array Hook results. Propagated to $hookmanager->resArray for later reuse @@ -282,7 +286,7 @@ public function sendMail($parameters, $object, &$action, $hookmanager) // what TODO with context 'emailing' // context notification? // https://developers.google.com/resources/api-libraries/documentation/gmail/v1/php/latest/class-Google_Service_Gmail_Message.html - if (in_array('mail', $contexts) && !in_array($object->sendcontext, array('emailing', 'notification'))) { + if (in_array('mail', $contexts) && !in_array($object->sendcontext, ['emailing', 'notification'])) { dol_include_once('/googleapi/lib/googleapi.lib.php'); $fromsender = $this->getArrayAddress($object->addr_from); if (!empty($user->array_options['options_googleapi_email']) && $fromsender[0]['address'] == $user->array_options['options_googleapi_email']) { @@ -475,10 +479,10 @@ private function getArrayAddress($address) $name = null; $email = trim($val); } - $ret[] = array( + $ret[] = [ 'name' => empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null, 'address' => $email, - ); + ]; } } diff --git a/class/googleapi.class.php b/class/googleapi.class.php index b215933..b40851e 100644 --- a/class/googleapi.class.php +++ b/class/googleapi.class.php @@ -36,8 +36,14 @@ class GoogleApi public $watchResp = ''; + /** + * @var string + */ public $error; + /** + * @var string[] + */ public $errors = []; /** @@ -91,18 +97,18 @@ public function checkExpiredSheduledWatch() $staticuser = new User($this->db); $staticuser->fetch($row->uid); // we check for user which have a token - if (!empty($conf->global->GOOGLEAPI_ENABLE_PUSH_ME_EVENTS)) { - $this->chekValidPushNotificationFor($staticuser, 'events', $urlfornotification); + if (getDolGlobalInt('GOOGLEAPI_ENABLE_PUSH_ME_EVENTS')) { + $this->chekValidPushNotificationForEvents($staticuser, $urlfornotification); $pushactive++; } // if (! empty($conf->global->GOOGLEAPI_ENABLE_PUSH_ME_MESSAGES)) { // $this->chekValidPushNotificationFor($staticuser, 'messages', $urlfornotification); // $pushactive++; // } - // if (! empty($conf->global->GOOGLEAPI_ENABLE_PUSH_ME_CONTACTS)) { - // $this->chekValidPushNotificationFor($staticuser, 'contacts', $urlfornotification); - // $pushactive++; - // } + if (getDolGlobalInt('GOOGLEAPI_ENABLE_PUSH_ME_CONTACTS')) { + $this->chekValidPushNotificationForContacts($staticuser, $urlfornotification); + $pushactive++; + } } } } @@ -118,15 +124,11 @@ public function checkExpiredSheduledWatch() * Function to check if push is valid for user * * @param User $user user id - * @param string $type type * @param string $urlfornotification url * @return int */ - private function chekValidPushNotificationFor($user, $type, $urlfornotification) + private function chekValidPushNotificationForEvents($user, $urlfornotification) { - - global $conf, $db; - $now = dol_now(); require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; dol_include_once('/googleapi/lib/googleapi.lib.php'); @@ -135,12 +137,13 @@ private function chekValidPushNotificationFor($user, $type, $urlfornotification) $service = new Google\Service\Calendar($client); $sql = "SELECT rowid, userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber FROM " . MAIN_DB_PREFIX . "googleapi_watchs"; - $sql .= ' WHERE userid=' . (int) $user->id . ' AND resourcetype="' . $this->db->escape($type) . '"'; + $sql .= ' WHERE userid=' . (int) $user->id . ' AND resourcetype="events"'; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { // on a déjà quelquechose $row = $this->db->fetch_object($resql); + $calendarId = $user->array_options['options_googleapi_calendarId'] ?: 'primary'; // is it going to expire in 30min // expiration is gmt @@ -158,14 +161,14 @@ private function chekValidPushNotificationFor($user, $type, $urlfornotification) $channel->setId($channelId); $channel->setType('web_hook'); $channel->setAddress($urlfornotification); - $watch = $service->events->watch('primary', $channel); + $watch = $service->events->watch($calendarId, $channel); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "googleapi_watchs"; $sql .= " (userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber) VALUES("; $sql .= " " . (int) $user->id; $sql .= ", '" . $this->db->escape($uuid) . "'"; $sql .= ", '" . $this->db->escape($watch->getId()) . "'"; - $sql .= ", '" . $this->db->escape($type) . "'"; + $sql .= ", 'events'"; $sql .= ", '" . $this->db->escape($watch->getResourceUri()) . "'"; $sql .= ", '" . $this->db->escape($watch->getResourceId()) . "'"; //$sql .= ", '" . ($watch->getExpiration())->format('Y-m-d H:i:s') . "'"; @@ -173,6 +176,108 @@ private function chekValidPushNotificationFor($user, $type, $urlfornotification) $sql .= ", '1')"; $resql = $this->db->query($sql); dol_syslog(get_class($this) . ' ' . $sql, LOG_NOTICE); + } catch (Exception $e) { + dol_syslog($e->getmessage(), LOG_ERR); + } + // delete the old one from db + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "googleapi_watchs "; + $sql .= " WHERE rowid=" . (int) $row->rowid; + $this->db->query($sql); + dol_syslog(get_class($this) . ' ' . $sql, LOG_NOTICE); + $this->output .= 'New Active ' . ($expiration - $now) . ' sec, '; + //print $sql;exit; + } else { + // active + $this->output .= 'Active ' . ($expiration - $now) . ' sec, '; + } + } else { + $uuid = $this->getUuid(); + + try { + $channelId = $uuid; + $channel = new Google\Service\Calendar\Channel($client); + $channel->setId($channelId); + $channel->setType('web_hook'); + $channel->setAddress($urlfornotification); + $watch = $service->events->watch($calendarId, $channel); + + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "googleapi_watchs"; + $sql .= " (userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber) VALUES("; + $sql .= " " . (int) $user->id; + $sql .= ", '" . $this->db->escape($uuid) . "'"; + $sql .= ", '" . $this->db->escape($watch->getId()) . "'"; + $sql .= ", 'events'"; + $sql .= ", '" . $this->db->escape($watch->getResourceUri()) . "'"; + $sql .= ", '" . $this->db->escape($watch->getResourceId()) . "'"; + //$sql .= ", '" . ($watch->getExpiration())->format('Y-m-d H:i:s') . "'"; + // timestamp in ms + $sql .= ", '" . ($this->db->idate(substr($watch->getExpiration(), 0, -3))) . "'"; + $sql .= ", '1')"; + + $resql = $this->db->query($sql); + } catch (Exception $e) { + dol_syslog($e->getmessage(), LOG_ERR); + } + //exit; + } + return 0; + } + + /** + * Function to check if push is valid for user + * + * @param User $user user id + * @param string $urlfornotification url + * @return int + */ + private function chekValidPushNotificationForContacts($user, $urlfornotification) + { + $now = dol_now(); + require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; + dol_include_once('/googleapi/lib/googleapi.lib.php'); + dol_include_once('/prune/vendor/autoload.php'); + $client = getGoogleApiClient($user); + $service = new Google\Service\WorkspaceEvents($client); + + $sql = "SELECT rowid, userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber FROM " . MAIN_DB_PREFIX . "googleapi_watchs"; + $sql .= ' WHERE userid=' . (int) $user->id . ' AND resourcetype="contacts"'; + + $resql = $this->db->query($sql); + if ($resql && $this->db->num_rows($resql) > 0) { + // on a déjà quelquechose + $row = $this->db->fetch_object($resql); + + // is it going to expire in 30min + // expiration is gmt + $expiration = dol_stringtotime($row->expirationDateTime, 1); + // check with cron + if (($expiration - $now - (13 * 3600)) < 0) { + // expired + $this->output .= 'push expired '; + // create a new one which may overlap + $uuid = $this->getUuid(); + + try { + $channelId = $uuid; + $channel = new Google\Service\WorkspaceEvents\Subscription(); + $channel->setEventTypes(['google.workspace.people.contact.v1.modified']); + $channel->setNotificationEndpoint($urlfornotification); + $channel->setPayloadOptions(['includeResource' => true]); + $watch = $service->subscriptions->create($channel); + + $sql = "INSERT INTO " . MAIN_DB_PREFIX . "googleapi_watchs"; + $sql .= " (userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber) VALUES("; + $sql .= " " . (int) $user->id; + $sql .= ", '" . $this->db->escape($uuid) . "'"; + $sql .= ", '" . $this->db->escape($watch->getName()) . "'"; + $sql .= ", 'contacts'"; + $sql .= ", ''"; + $sql .= ", ''"; + //$sql .= ", '" . ($watch->getExpiration())->format('Y-m-d H:i:s') . "'"; + $sql .= ", '" . ($this->db->idate(substr($watch->getExpirationTime(), 0, -3))) . "'"; + $sql .= ", '1')"; + $resql = $this->db->query($sql); + dol_syslog(get_class($this) . ' ' . $sql, LOG_NOTICE); //var_dump($this->watchResp);print $sql;exit; } catch (Exception $e) { dol_syslog($e->getmessage(), LOG_ERR); @@ -198,14 +303,14 @@ private function chekValidPushNotificationFor($user, $type, $urlfornotification) $channel->setType('web_hook'); $channel->setAddress($urlfornotification); $calendarId = $user->array_options['options_googleapi_calendarId'] ?? 'primary'; - $watch = $service->events->watch($calendarId, $channel); + $watch = $service->peoples->watch($calendarId, $channel); $sql = "INSERT INTO " . MAIN_DB_PREFIX . "googleapi_watchs"; $sql .= " (userid, uuid, id, resourcetype, resourceUri, ressourceId, expirationDateTime, lastmessagenumber) VALUES("; $sql .= " " . (int) $user->id; $sql .= ", '" . $this->db->escape($uuid) . "'"; $sql .= ", '" . $this->db->escape($watch->getId()) . "'"; - $sql .= ", '" . $this->db->escape($type) . "'"; + $sql .= ", 'contacts'"; $sql .= ", '" . $this->db->escape($watch->getResourceUri()) . "'"; $sql .= ", '" . $this->db->escape($watch->getResourceId()) . "'"; //$sql .= ", '" . ($watch->getExpiration())->format('Y-m-d H:i:s') . "'"; diff --git a/codesniffer/ruleset.xml b/codesniffer/ruleset.xml index 60cdbd7..890e36d 100644 --- a/codesniffer/ruleset.xml +++ b/codesniffer/ruleset.xml @@ -20,6 +20,7 @@ + diff --git a/config.php b/config.php index 17ce312..fe169c5 100644 --- a/config.php +++ b/config.php @@ -33,13 +33,13 @@ $arraymain[] = implode('/', $newfile); } $arraymain = array_merge( - array( + [ $_SERVER["CONTEXT_DOCUMENT_ROOT"] ?? '', '..', '../..', '../../..', '../../../..', - ), + ], array_reverse($arraymain) ); foreach ($arraymain as $path) { diff --git a/core/modules/modGoogleApi.class.php b/core/modules/modGoogleApi.class.php index f30eba5..60dabbb 100644 --- a/core/modules/modGoogleApi.class.php +++ b/core/modules/modGoogleApi.class.php @@ -255,13 +255,13 @@ public function init($options = '') $extrafields = new ExtraFields($this->db); // actioncomm - $extrafields->addExtraField('googleapi_EventId', "GoogleApi Id", 'varchar', $this->numero, 180, 'actioncomm', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_EventId', "GoogleApi Id", 'varchar', $this->numero, 180, 'actioncomm', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); // user - $extrafields->addExtraField('googleapi_Id', "GoogleApi Id", 'varchar', $this->numero, 64, 'user', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); - $extrafields->addExtraField('googleapi_lastevent_sync', "GoogleApiLastEventSync", 'varchar', $this->numero + 1, 64, 'user', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); - $extrafields->addExtraField('googleapi_email', "GoogleApiOwnerEmail", 'varchar', $this->numero + 2, 128, 'user', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); - $extrafields->addExtraField('googleapi_calendarId', "GoogleApiCalendarId", 'varchar', $this->numero + 3, 128, 'user', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); - $extrafields->addExtraField('googleapi_calendarTZ', "GoogleApiCalendarTZ", 'varchar', $this->numero + 4, 128, 'user', 0, 0, '', '', 1, '', '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_Id', "GoogleApi Id", 'varchar', $this->numero, 64, 'user', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_lastevent_sync', "GoogleApiLastEventSync", 'varchar', $this->numero + 1, 64, 'user', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_email', "GoogleApiOwnerEmail", 'varchar', $this->numero + 2, 128, 'user', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_calendarId', "GoogleApiCalendarId", 'varchar', $this->numero + 3, 128, 'user', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); + $extrafields->addExtraField('googleapi_calendarTZ', "GoogleApiCalendarTZ", 'varchar', $this->numero + 4, 128, 'user', 0, 0, '', '', 1, '', 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', 'googleapi@googleapi', 'isModEnabled("googleapi")'); // thirdparty $result = $extrafields->addExtraField( 'googleapiId', @@ -276,7 +276,7 @@ public function init($options = '') '', 1, '', - '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', + 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', @@ -297,7 +297,7 @@ public function init($options = '') '', 1, '', - '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', + 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', @@ -318,7 +318,7 @@ public function init($options = '') '', 1, '', - '(empty($conf->global->GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG) ? 0:3)', + 'getDolGloblaInt("GOOGLEAPI_ENABLE_EXTRAFIELDS_DEBUG") ? 3:0', 0, '', '', diff --git a/core/triggers/interface_99_modGoogleApi_GoogleApiTriggers.class.php b/core/triggers/interface_99_modGoogleApi_GoogleApiTriggers.class.php index b70f98c..270f627 100644 --- a/core/triggers/interface_99_modGoogleApi_GoogleApiTriggers.class.php +++ b/core/triggers/interface_99_modGoogleApi_GoogleApiTriggers.class.php @@ -128,7 +128,7 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf // For example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf) $methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action))))); // setEventMessage($methodName); - $callback = array($this, $methodName); + $callback = [$this, $methodName]; if (is_callable($callback)) { dol_syslog("Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id, LOG_INFO); return call_user_func($callback, $action, $object, $user, $langs, $conf); @@ -195,20 +195,20 @@ public function actionCreate($action, ActionComm $object, User $user, Translate 'description' => $object->note, 'start' => $start, 'end' => $end, - 'recurrence' => array( + 'recurrence' => [ //'RRULE:FREQ=DAILY;COUNT=2' - ), - 'attendees' => array( + ], + 'attendees' => [ // array('email' => 'lpage@example.com'), // array('email' => 'sbrin@example.com'), - ), - 'reminders' => array( + ], + 'reminders' => [ // 'useDefault' => false, // 'overrides' => array( // array('method' => 'email', 'minutes' => 24 * 60), // array('method' => 'popup', 'minutes' => 10), // ), - ), + ], ]); if (empty($staticuser->array_options['options_googleapi_calendarId'])) { @@ -217,11 +217,18 @@ public function actionCreate($action, ActionComm $object, User $user, Translate $calendarId = $staticuser->array_options['options_googleapi_calendarId']; } $service = new \Google\Service\Calendar($client); - $event = $service->events->insert($calendarId, $event); + try { + $event = $service->events->insert($calendarId, $event); - // enregistrer l'id googleapi dans dolibarr (extrafield) - $object->array_options['options_googleapi_EventId'] = $event->getId(); - $object->update($user, 1); + // enregistrer l'id googleapi dans dolibarr (extrafield) + $object->array_options['options_googleapi_EventId'] = $event->getId(); + $object->update($user, 1); + } catch (Throwable $t) { + dol_syslog($t->getMessage(), LOG_ERR); + setEventMessage($t->getMessage()); + } catch (Exception $e) { + setEventMessage($e->getMessage()); + } return (!$error ? 0 : -1); } @@ -339,11 +346,18 @@ public function actionModify($action, ActionComm $object, User $user, Translate } $service = new \Google\Service\Calendar($client); if (empty($object->array_options['options_googleapi_EventId'])) { - $event = $service->events->insert($calendarId, $event); - // // enregistrer l'id googleapi dans dolibarr (extrafield) - $object->fetch_optionals(); - $object->array_options['options_googleapi_EventId'] = $event->getId(); - $object->update($user, 1); + try { + $event = $service->events->insert($calendarId, $event); + // // enregistrer l'id googleapi dans dolibarr (extrafield) + $object->fetch_optionals(); + $object->array_options['options_googleapi_EventId'] = $event->getId(); + $object->update($user, 1); + } catch (Throwable $t) { + dol_syslog($t->getMessage(), LOG_ERR); + setEventMessage($t->getMessage()); + } catch (Exception $e) { + setEventMessage($e->getMessage()); + } } else { $event = $service->events->update($calendarId, $object->array_options['options_googleapi_EventId'], $event); } diff --git a/sql/update_0.0.0.-1.0.0.sql b/sql/update_0.0.0.-1.0.0.sql index 4b1d895..23a4ed0 100644 --- a/sql/update_0.0.0.-1.0.0.sql +++ b/sql/update_0.0.0.-1.0.0.sql @@ -1,4 +1,4 @@ --- Copyright (C) 2019 Frédéric France +-- Copyright (C) 2019-2026 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 @@ -14,5 +14,6 @@ -- along with this program. If not, see http://www.gnu.org/licenses/. -- TO FIX PHP WARNINGS -UPDATE llx_extrafields SET enabled='!empty($conf->googleapi->enabled)' WHERE enabled='$conf->googleapi->enabled'; +UPDATE llx_extrafields SET enabled='isModEnabled("googleapi")' WHERE enabled='!empty($conf->googleapi->enabled)'; +UPDATE llx_extrafields set enabled = 'isModEnabled("googleapi")' WHERE enabled = '$conf->googleapi->enabled'; UPDATE llx_c_actioncomm SET type='module', module='googleapi@googleapi' WHERE type='system' AND module='googleapi'; diff --git a/tabs/action/card.php b/tabs/action/card.php index cb6ff83..4c82cc8 100644 --- a/tabs/action/card.php +++ b/tabs/action/card.php @@ -59,7 +59,7 @@ */ // Load translation files required by the page -$langs->loadLangs(array("companies", "other", "commercial", "bills", "orders", "agenda", "mails")); +$langs->loadLangs(["companies", "other", "commercial", "bills", "orders", "agenda", "mails"]); // Get Parameters $action = GETPOST('action', 'aZ09'); @@ -158,14 +158,14 @@ } // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context -$hookmanager->initHooks(array('actioncard', 'globalcard')); +$hookmanager->initHooks(['actioncard', 'globalcard']); $TRemindTypes = []; if (getDolGlobalString('AGENDA_REMINDER_BROWSER')) { - $TRemindTypes['browser'] = array('label' => $langs->trans('BrowserPush'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_BROWSER') ? 0 : 1)); + $TRemindTypes['browser'] = ['label' => $langs->trans('BrowserPush'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_BROWSER') ? 0 : 1)]; } if (getDolGlobalString('AGENDA_REMINDER_EMAIL')) { - $TRemindTypes['email'] = array('label' => $langs->trans('EMail'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_EMAIL') ? 0 : 1)); + $TRemindTypes['email'] = ['label' => $langs->trans('EMail'), 'disabled' => (getDolGlobalString('AGENDA_REMINDER_EMAIL') ? 0 : 1)]; } if (getDolGlobalString('AGENDA_REMINDER_SMS')) { $langs->load('sms'); @@ -272,7 +272,7 @@ if (!empty($_SESSION['assignedtouser'])) { $assignedtouser = json_decode($_SESSION['assignedtouser'], true); } - $assignedtouser[GETPOST('assignedtouser')] = array('id' => GETPOSTINT('assignedtouser'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1); + $assignedtouser[GETPOST('assignedtouser')] = ['id' => GETPOSTINT('assignedtouser'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1]; $_SESSION['assignedtouser'] = json_encode($assignedtouser); } $donotclearsession = 1; @@ -294,7 +294,7 @@ if (!empty($_SESSION['assignedtoresource'])) { $assignedtoresource = json_decode($_SESSION['assignedtoresource'], true); } - $assignedtoresource[GETPOST('assignedtoresource')] = array('id' => GETPOSTINT('assignedtoresource'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1); + $assignedtoresource[GETPOST('assignedtoresource')] = ['id' => GETPOSTINT('assignedtoresource'), 'transparency' => GETPOST('transparency'), 'mandatory' => 1]; $_SESSION['assignedtoresource'] = json_encode($assignedtoresource); } $donotclearsession = 1; @@ -359,7 +359,7 @@ exit; } - $percentage = in_array(GETPOST('status'), array(-1, 100)) ? GETPOST('status') : (in_array($complete, array(-1, 100)) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status + $percentage = in_array(GETPOST('status'), [-1, 100]) ? GETPOST('status') : (in_array($complete, [-1, 100]) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status // Clean parameters if ($fulldayevent) { @@ -478,7 +478,7 @@ $object->transparency = $transparency; } - $object->userassigned[$value['id']] = array('id' => $value['id'], 'transparency' => $transparency); + $object->userassigned[$value['id']] = ['id' => $value['id'], 'transparency' => $transparency]; $i++; } @@ -518,7 +518,7 @@ } foreach ($socpeopleassigned as $cid) { - $object->socpeopleassigned[$cid] = array('id' => $cid); + $object->socpeopleassigned[$cid] = ['id' => $cid]; } if (!empty($object->socpeopleassigned)) { reset($object->socpeopleassigned); @@ -876,7 +876,7 @@ $apmin = GETPOSTINT('apmin'); $p2hour = GETPOSTINT('p2hour'); $p2min = GETPOSTINT('p2min'); - $percentage = in_array(GETPOST('status'), array(-1, 100)) ? GETPOST('status') : (in_array($complete, array(-1, 100)) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status + $percentage = in_array(GETPOST('status'), [-1, 100]) ? GETPOST('status') : (in_array($complete, [-1, 100]) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status // Clean parameters if ($aphour == -1) { @@ -952,7 +952,7 @@ $socpeopleassigned = GETPOST("socpeopleassigned", 'array'); $object->socpeopleassigned = []; foreach ($socpeopleassigned as $cid) { - $object->socpeopleassigned[$cid] = array('id' => $cid); + $object->socpeopleassigned[$cid] = ['id' => $cid]; } $object->contact_id = GETPOSTINT("contactid"); if (empty($object->contact_id) && !empty($object->socpeopleassigned)) { @@ -1005,7 +1005,7 @@ } else { $assignedtouser = (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : 0); if ($assignedtouser) { - $listofuserid[$assignedtouser] = array('id' => $assignedtouser, 'mandatory' => 0, 'transparency' => ($user->id == $assignedtouser ? $transparency : '')); // Owner first + $listofuserid[$assignedtouser] = ['id' => $assignedtouser, 'mandatory' => 0, 'transparency' => ($user->id == $assignedtouser ? $transparency : '')]; // Owner first } } $object->userassigned = []; @@ -1015,7 +1015,7 @@ if ($i == 0) { $object->userownerid = $val['id']; } - $object->userassigned[$val['id']] = array('id' => $val['id'], 'mandatory' => 0, 'transparency' => ($user->id == $val['id'] ? $transparency : '')); + $object->userassigned[$val['id']] = ['id' => $val['id'], 'mandatory' => 0, 'transparency' => ($user->id == $val['id'] ? $transparency : '')]; $i++; } @@ -1331,12 +1331,12 @@ $form = new Form($db); $formproject = new FormProjets($db); -$arrayrecurrulefreq = array( +$arrayrecurrulefreq = [ 'no' => $langs->trans("OnceOnly"), 'MONTHLY' => $langs->trans("EveryMonth"), 'WEEKLY' => $langs->trans("EveryWeek") // 'DAILY'=>$langs->trans("EveryDay") -); +]; $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda|DE:Modul_Terminplanung'; @@ -1602,7 +1602,7 @@ function init_repeat() if (empty($donotclearsession)) { $assignedtouser = GETPOST("assignedtouser") ? GETPOST("assignedtouser") : (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : $user->id); if ($assignedtouser) { - $listofuserid[$assignedtouser] = array('id' => $assignedtouser, 'mandatory' => 0); // Owner first + $listofuserid[$assignedtouser] = ['id' => $assignedtouser, 'mandatory' => 0]; // Owner first } //$listofuserid[$user->id] = array('id'=>$user->id, 'mandatory'=>0, 'transparency'=>(GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1)); // 1 by default at first init $listofuserid[$assignedtouser]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1); // 1 by default at first init @@ -1644,7 +1644,7 @@ function init_repeat() if (empty($donotclearsession)) { $assignedtoresource = GETPOST("assignedtoresource"); if ($assignedtoresource) { - $listofresourceid[$assignedtoresource] = array('id' => $assignedtoresource, 'mandatory' => 0); // Owner first + $listofresourceid[$assignedtoresource] = ['id' => $assignedtoresource, 'mandatory' => 0]; // Owner first } $_SESSION['assignedtoresource'] = json_encode($listofresourceid); } else { @@ -1701,7 +1701,7 @@ function init_repeat() print ''; } else { $events = []; - $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token=' . currentToken(), 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); + $events[] = ['method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token=' . currentToken(), 1), 'htmlname' => 'contactid', 'params' => ['add-customer-contact' => 'disabled']]; //For external user force the company to user company if (!empty($user->socid)) { print img_picto('', 'company', 'class="paddingrightonly"') . $form->select_company($user->socid, 'socid', '', 1, 1, 0, $events, 0, 'minwidth300 widthcentpercentminusxx maxwidth500'); @@ -1811,7 +1811,7 @@ function init_repeat() } //var_dump('origin='.$origin.' originid='.$originid.' hasPermissionOnLinkedObject='.$hasPermissionOnLinkedObject); - if (! in_array($origin, array('societe', 'project', 'task', 'user'))) { + if (! in_array($origin, ['societe', 'project', 'task', 'user'])) { // We do not use link for object that already contains a hard coded field to make links with agenda events print '' . $langs->trans("LinkedObject") . ''; print ''; @@ -1974,7 +1974,7 @@ function selectremindertype() { $result5 = $object->fetch_optionals(); if ($listUserAssignedUpdated || $donotclearsession) { - $percentage = in_array(GETPOST('status'), array(-1, 100)) ? GETPOST('status') : (in_array($complete, array(-1, 100)) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status + $percentage = in_array(GETPOST('status'), [-1, 100]) ? GETPOST('status') : (in_array($complete, [-1, 100]) ? $complete : GETPOSTINT("percentage")); // If status is -1 or 100, percentage is not defined and we must use status $datep = dol_mktime($fulldayevent ? 0 : $aphour, $fulldayevent ? 0 : $apmin, 0, GETPOSTINT("apmonth"), GETPOSTINT("apday"), GETPOSTINT("apyear"), 'tzuserrel'); $datef = dol_mktime($fulldayevent ? 23 : $p2hour, $fulldayevent ? 59 : $p2min, $fulldayevent ? 59 : 0, GETPOSTINT("p2month"), GETPOSTINT("p2day"), GETPOSTINT("p2year"), 'tzuserrel'); @@ -1990,7 +1990,7 @@ function selectremindertype() { $object->socid = GETPOSTINT("socid"); $socpeopleassigned = GETPOST("socpeopleassigned", 'array'); foreach ($socpeopleassigned as $tmpid) { - $object->socpeopleassigned[$id] = array('id' => $tmpid); + $object->socpeopleassigned[$id] = ['id' => $tmpid]; } $object->contact_id = GETPOSTINT("contactid"); $object->fk_project = GETPOSTINT("projectid"); @@ -2200,14 +2200,14 @@ function setdatefields() $listofuserid = []; // User assigned if (empty($donotclearsession)) { if ($object->userownerid > 0) { - $listofuserid[$object->userownerid] = array( + $listofuserid[$object->userownerid] = [ 'id' => $object->userownerid, 'type' => 'user', //'transparency'=>$object->userassigned[$user->id]['transparency'], 'transparency' => $object->transparency, // Force transparency on ownerfrom event 'answer_status' => (isset($object->userassigned[$object->userownerid]['answer_status']) ? $object->userassigned[$object->userownerid]['answer_status'] : null), 'mandatory' => (isset($object->userassigned[$object->userownerid]['mandatory']) ? $object->userassigned[$object->userownerid]['mandatory'] : null) - ); + ]; } if (!empty($object->userassigned)) { // Now concat assigned users // Restore array with key with same value than param 'id' @@ -2272,7 +2272,7 @@ function setdatefields() print ''; print '
'; $events = []; // 'method'=parameter action of url, 'url'=url to call that return new list of contacts - $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token=' . currentToken(), 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); + $events[] = ['method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php?showempty=1&token=' . currentToken(), 1), 'htmlname' => 'contactid', 'params' => ['add-customer-contact' => 'disabled']]; // TODO Refresh also list of project if conf PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY not defined with list linked to socid ? // FIXME If we change company, we may get a project that does not match print img_picto('', 'company', 'class="pictofixedwidth"') . $form->select_company($object->socid, 'socid', '', 'SelectThirdParty', 1, 0, $events, 0, 'minwidth300'); @@ -2713,12 +2713,12 @@ function setdatefields() $listofuserid = []; if (empty($donotclearsession)) { if ($object->userownerid > 0) { - $listofuserid[$object->userownerid] = array( + $listofuserid[$object->userownerid] = [ 'id' => $object->userownerid, 'transparency' => $object->transparency, // Force transparency on owner from property of event 'answer_status' => $object->userassigned[$object->userownerid]['answer_status'], 'mandatory' => $object->userassigned[$object->userownerid]['mandatory'] - ); + ]; } if (!empty($object->userassigned)) { // Now concat assigned users // Restore array with key with same value than param 'id' @@ -2816,7 +2816,7 @@ function setdatefields() // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table // for such objects because there is already a dedicated field into table llx_actioncomm. - if (!empty($object->elementid) && !empty($object->elementtype) && !in_array($object->elementtype, array('societe', 'contact', 'project'))) { + if (!empty($object->elementid) && !empty($object->elementtype) && !in_array($object->elementtype, ['societe', 'contact', 'project'])) { include_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php'; print '' . $langs->trans("LinkedObject") . ''; $link = dolGetElementUrl($object->elementid, $object->elementtype, ($object->elementtype == 'user' ? -1 : 1)); @@ -2958,7 +2958,7 @@ function setdatefields() if (getDolGlobalString('AGENDA_ENABLE_LINKED_ELEMENTS')) { // Show links to link elements - $tmparray = $form->showLinkToObjectBlock($object, [], array('myobject'), 1); + $tmparray = $form->showLinkToObjectBlock($object, [], ['myobject'], 1); if (is_array($tmparray)) { $linktoelem = $tmparray['linktoelem']; $htmltoenteralink = $tmparray['htmltoenteralink']; diff --git a/tabs/googleapi_emails.php b/tabs/googleapi_emails.php index b502c4b..c44253c 100644 --- a/tabs/googleapi_emails.php +++ b/tabs/googleapi_emails.php @@ -53,7 +53,7 @@ $rowid = (int) GETPOST('rowid', 'int'); $ref = GETPOST('ref', 'alpha'); // Note that conf->hooks_modules contains array -$hookmanager->initHooks(array('googleapiemaillist', 'globalcard')); +$hookmanager->initHooks(['googleapiemaillist', 'globalcard']); $linkback = ''; // Initialize technical objects @@ -205,15 +205,15 @@ //$socid = $user->socid; accessforbidden(); } -$arrayofjs = array( +$arrayofjs = [ 'https://uicdn.toast.com/tui.code-snippet/latest/tui-code-snippet.js', 'https://uicdn.toast.com/tui.pagination/latest/tui-pagination.js', 'https://uicdn.toast.com/tui-grid/latest/tui-grid.js', -); -$arrayofcss = array( +]; +$arrayofcss = [ 'https://uicdn.toast.com/tui-grid/latest/tui-grid.css', 'https://uicdn.toast.com/tui.pagination/latest/tui-pagination.css', -); +]; llxHeader('', $pagetitle, '', '', 0, 0, $arrayofjs, $arrayofcss); @@ -241,24 +241,24 @@ print '
'; - $arrayfields = array( - 'rowid' => array( + $arrayfields = [ + 'rowid' => [ 'label' => $langs->transnoentities("Id"), 'checked' => 1 - ), - 'userid' => array( + ], + 'userid' => [ 'label' => $langs->transnoentities("GoogleApiUserId"), 'checked' => 1 - ), - 'fk_object' => array( + ], + 'fk_object' => [ 'label' => $langs->transnoentities("ObjectId"), 'checked' => 1, - ), - 'messageid' => array( + ], + 'messageid' => [ 'label' => $langs->transnoentities("GoogleApiMessageId"), 'checked' => 1, - ), - ); + ], + ]; print '
'; print "