Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#207 [Hook] add: addHtmlHeader manage manifest file #208

Merged
merged 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions class/actions_easycrm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function addMoreBoxStatsCustomer(array $parameters, CommonObject $object,
global $conf, $langs, $user;

// Do something only for the current context
if ($parameters['currentcontext'] == 'thirdpartycomm') {
if (strpos($parameters['context'], 'thirdpartycomm') !== false) {
if (isModEnabled('project') && $user->hasRight('projet', 'lire') && isModEnabled('saturne')) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once __DIR__ . '/../../saturne/lib/object.lib.php';
Expand Down Expand Up @@ -129,7 +129,7 @@ public function addMoreRecentObjects(array $parameters, CommonObject $object, st
global $conf, $db, $langs, $user;

// Do something only for the current context
if ($parameters['currentcontext'] == 'thirdpartycomm') {
if (strpos($parameters['context'], 'thirdpartycomm') !== false) {
if (isModEnabled('project') && $user->hasRight('projet', 'lire') && isModEnabled('saturne')) {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once __DIR__ . '/../../saturne/lib/object.lib.php';
Expand Down Expand Up @@ -217,9 +217,9 @@ public function addMoreActionsButtons(array $parameters, CommonObject $object, s
global $langs, $user;

// Do something only for the current context
if (in_array($parameters['currentcontext'], ['thirdpartycomm', 'projectcard'])) {
if (preg_match('/thirdpartycomm|projectcard/', $parameters['context'])) {
if (empty(GETPOST('action')) || GETPOST('action') == 'update') {
if ($parameters['currentcontext'] == 'thirdpartycomm') {
if (strpos($parameters['context'], 'thirdpartycomm') !== false) {
$socid = $object->id;
$moreparam = '';
} else {
Expand All @@ -245,7 +245,7 @@ public function addMoreActionsButtons(array $parameters, CommonObject $object, s
*/
public function doActions(array $parameters, $object, string $action): int
{
if (in_array($parameters['currentcontext'], ['invoicecard', 'invoicereccard', 'thirdpartycomm', 'thirdpartycard'])) {
if (preg_match('/invoicecard|invoicereccard|thirdpartycomm|thirdpartycard/', $parameters['context'])) {
if ($action == 'set_notation_object_contact') {
require_once __DIR__ . '/../lib/easycrm_function.lib.php';

Expand All @@ -271,7 +271,7 @@ public function printCommonFooter(array $parameters): int
global $conf, $db, $langs , $object;

// Do something only for the current context
if (in_array($parameters['currentcontext'], ['thirdpartycomm', 'projectcard'])) {
if (preg_match('/thirdpartycomm|projectcard/', $parameters['context'])) {
if (isModEnabled('agenda')) {
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';

Expand All @@ -281,7 +281,7 @@ public function printCommonFooter(array $parameters): int
$actiomcomm = new ActionComm($db);

$filter = ' AND a.id IN (SELECT c.fk_actioncomm FROM ' . MAIN_DB_PREFIX . 'categorie_actioncomm as c WHERE c.fk_categorie = ' . $conf->global->EASYCRM_ACTIONCOMM_COMMERCIAL_RELAUNCH_TAG . ')';
$actiomcomms = $actiomcomm->getActions(GETPOST('socid'), ($parameters['currentcontext'] != 'thirdpartycomm' ? GETPOST('id') : ''), ($parameters['currentcontext'] != 'thirdpartycomm' ? 'project' : ''), $filter, 'a.datec');
$actiomcomms = $actiomcomm->getActions(GETPOST('socid'), ((strpos($parameters['context'], 'thirdpartycomm') !== false) ? '' : GETPOST('id')), ((strpos($parameters['context'], 'thirdpartycomm') !== false) ? '' : 'project'), $filter, 'a.datec');
if (is_array($actiomcomms) && !empty($actiomcomms)) {
$nbActiomcomms = count($actiomcomms);
$lastActiomcomm = array_shift($actiomcomms);
Expand All @@ -306,7 +306,7 @@ public function printCommonFooter(array $parameters): int
}

// Do something only for the current context
if ($parameters['currentcontext'] == 'projectcard') {
if (strpos($parameters['context'], 'projectcard') !== false) {
if (empty(GETPOST('action')) || GETPOST('action') == 'update') {
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT . '/projet/class/task.class.php';
Expand All @@ -329,7 +329,7 @@ public function printCommonFooter(array $parameters): int
}
}

if (in_array($parameters['currentcontext'], ['invoicelist', 'invoicereclist', 'thirdpartylist'])) {
if (preg_match('/invoicelist|invoicereclist|thirdpartylist/', $parameters['context'])) {
$cssPath = dol_buildpath('/saturne/css/saturne.min.css', 1);
print '<link href="' . $cssPath . '" rel="stylesheet">';

Expand All @@ -346,7 +346,7 @@ public function printCommonFooter(array $parameters): int
<?php
}

if (in_array($parameters['currentcontext'], ['invoicecard', 'invoicereccard', 'thirdpartycomm', 'thirdpartycard'])) {
if (preg_match('/invoicecard|invoicereccard|thirdpartycomm|thirdpartycard/', $parameters['context'])) {
$cssPath = dol_buildpath('/saturne/css/saturne.min.css', 1);
print '<link href="' . $cssPath . '" rel="stylesheet">';

Expand All @@ -368,7 +368,7 @@ public function printCommonFooter(array $parameters): int
<?php
}

if ($parameters['currentcontext'] == 'contactcard') {
if (strpos($parameters['context'], 'contactcard') !== false) {
if (in_array(GETPOST('action'), ['create', 'edit'])) {
$out = img_picto('', 'fontawesome_fa-id-card-alt_fas', 'class="pictofixedwidth"'); ?>
<script>
Expand All @@ -381,6 +381,27 @@ public function printCommonFooter(array $parameters): int
return 0; // or return 1 to replace standard code
}

/**
* Overloading the addHtmlHeader function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadata (context, etc...)
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function addHtmlHeader(array $parameters): int
{
if (strpos($_SERVER['PHP_SELF'], 'easycrm') !== false) {
?>
<script>
$('link[rel="manifest"]').remove();
</script>
<?php

$this->resprints = '<link rel="manifest" href="' . DOL_URL_ROOT . '/custom/easycrm/manifest.json.php' . '" />';
}

return 0; // or return 1 to replace standard code-->
}

/**
* Overloading the printFieldListValue function : replacing the parent's function with the one below
*
Expand All @@ -393,7 +414,7 @@ public function printFieldListValue(array $parameters): int
global $conf, $db, $langs, $object, $user;

// Do something only for the current context
if ($parameters['currentcontext'] == 'projectlist') {
if (strpos($parameters['context'], 'projectlist') !== false) {
if (isModEnabled('agenda') && isModEnabled('project') && $user->hasRight('projet', 'lire') && isModEnabled('saturne')) {
require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php';
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
Expand Down Expand Up @@ -436,7 +457,7 @@ public function printFieldListValue(array $parameters): int
}
}

if (in_array($parameters['currentcontext'], ['invoicelist', 'invoicereclist', 'thirdpartylist'])) {
if (preg_match('/invoicelist|invoicereclist|thirdpartylist/', $parameters['context'])) {
if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
$extrafieldName = 'options_notation_' . $object->element . '_contact';
if ($object->element == 'facturerec') {
Expand Down Expand Up @@ -472,7 +493,7 @@ public function printFieldListValue(array $parameters): int
*/
public function formConfirm(array $parameters, CommonObject $object): int
{
if ($parameters['currentcontext'] == 'propalcard') {
if (strpos($parameters['context'], 'propalcard') !== false) {
if (empty($object->thirdparty->id)) {
$object->fetch_thirdparty();
}
Expand All @@ -491,7 +512,7 @@ public function completeTabsHead(array $parameters): int
{
global $langs;

if (in_array($parameters['currentcontext'], ['invoicereccard', 'invoicereccontact'])) {
if (preg_match('/invoicereccard|invoicereccontact/', $parameters['context'])) {
$nbContact = 0;
// Enable caching of thirdrparty count Contacts
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
Expand Down
3 changes: 2 additions & 1 deletion core/modules/modEasyCRM.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ public function __construct($db)
'invoicecard',
'contactcard',
'thirdpartycard',
'thirdpartylist'
'thirdpartylist',
'main'
],
// Set this to 1 if features of module are opened to external users
'moduleforexternal' => 0,
Expand Down
100 changes: 50 additions & 50 deletions view/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,55 +147,55 @@
$num = 0;
$allObjects = saturne_fetch_all_object_type($objectInfos['class_name']);

if ($conf->global->EASYCRM_DISPLAY_MAIN_ADDRESS) {
if (is_array($allObjects) && !empty($allObjects)) {
foreach ($allObjects as $objectLinked) {
$objectLinked->fetch_optionals();

if (!isset($objectLinked->array_options['options_' . $objectType . 'address']) || dol_strlen($objectLinked->array_options['options_' . $objectType . 'address']) <= 0) {
continue;
} else {
$addressId = $objectLinked->array_options['options_' . $objectType . 'address'];
}

$object->fetch($addressId);

if (($filterId > 0 && $filterId != $objectLinked->id) || (dol_strlen($filterType) > 0 && $filterType != $object->type) || (dol_strlen($filterTown) > 0 && $filterTown != $object->town) ||
($filterCountry > 0 && $filterCountry != $object->fk_country) || ($filterRegion > 0 && $filterRegion != $object->fk_region) || ($filterState > 0 && $filterState != $object->fk_department)) {
continue;
}

if ($object->longitude != 0 && $object->latitude != 0) {
$object->convertCoordinates();
$num++;
} else {
continue;
}

$locationID = $addressId;

$description = $objectLinked->getNomUrl(1) . '</br>';
$description .= $langs->trans($object->type) . ' : ' . $object->name;
$description .= dol_strlen($object->town) > 0 ? '</br>' . $langs->trans('Town') . ' : ' . $object->town : '';
$color = randomColor();

$objectList[$locationID] = !empty($object->fields['color']) ? $object->fields['color'] : '#' . $color;

// Add geoJSON point
$features[] = [
'type' => 'Feature',
'geometry' => [
'type' => 'Point',
'coordinates' => [$object->longitude, $object->latitude],
],
'properties' => [
'desc' => $description,
'address' => $locationID,
],
];
}
}
} else {
//if ($conf->global->EASYCRM_DISPLAY_MAIN_ADDRESS) {
// if (is_array($allObjects) && !empty($allObjects)) {
// foreach ($allObjects as $objectLinked) {
// $objectLinked->fetch_optionals();
//
// if (!isset($objectLinked->array_options['options_' . $objectType . 'address']) || dol_strlen($objectLinked->array_options['options_' . $objectType . 'address']) <= 0) {
// continue;
// } else {
// $addressId = $objectLinked->array_options['options_' . $objectType . 'address'];
// }
//
// $object->fetch($addressId);
//
// if (($filterId > 0 && $filterId != $objectLinked->id) || (dol_strlen($filterType) > 0 && $filterType != $object->type) || (dol_strlen($filterTown) > 0 && $filterTown != $object->town) ||
// ($filterCountry > 0 && $filterCountry != $object->fk_country) || ($filterRegion > 0 && $filterRegion != $object->fk_region) || ($filterState > 0 && $filterState != $object->fk_department)) {
// continue;
// }
//
// if ($object->longitude != 0 && $object->latitude != 0) {
// $object->convertCoordinates();
// $num++;
// } else {
// continue;
// }
//
// $locationID = $addressId;
//
// $description = $objectLinked->getNomUrl(1) . '</br>';
// $description .= $langs->trans($object->type) . ' : ' . $object->name;
// $description .= dol_strlen($object->town) > 0 ? '</br>' . $langs->trans('Town') . ' : ' . $object->town : '';
// $color = randomColor();
//
// $objectList[$locationID] = !empty($object->fields['color']) ? $object->fields['color'] : '#' . $color;
//
// // Add geoJSON point
// $features[] = [
// 'type' => 'Feature',
// 'geometry' => [
// 'type' => 'Point',
// 'coordinates' => [$object->longitude, $object->latitude],
// ],
// 'properties' => [
// 'desc' => $description,
// 'address' => $locationID,
// ],
// ];
// }
// }
//} else {
$geolocations = $geolocation->fetchAll('', '', 0, 0, ['customsql' => 't.element_type = ' . "'" . GETPOST('from_type') . "'"]);
if (is_array($geolocations) && !empty($geolocations)) {
foreach($geolocations as $geolocation) {
Expand Down Expand Up @@ -247,7 +247,7 @@
];
}
}
}
//}

if ($fromId > 0) {
$objectLinked->fetch($fromId);
Expand Down