Skip to content

Commit

Permalink
Fix link to create event from user card
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 21, 2022
1 parent 330a119 commit 9a5a3a3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 3 additions & 2 deletions htdocs/comm/action/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,9 +1181,10 @@ function setdatefields()
// Type of event
if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
print '<tr><td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Type").'</span></b></td><td>';
$default = (empty($conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT) ? 'AC_RDV' : $conf->global->AGENDA_USE_EVENT_TYPE_DEFAULT);
$default = getDolGlobalString('AGENDA_USE_EVENT_TYPE_DEFAULT', 'AC_RDV');
print img_picto($langs->trans("ActionType"), 'square', 'class="fawidth30 inline-block" style="color: #ddd;"');
print $formactions->select_type_actions(GETPOSTISSET("actioncode") ? GETPOST("actioncode", 'aZ09') : ($object->type_code ? $object->type_code : $default), "actioncode", "systemauto", 0, -1, 0, 1); // TODO Replace 0 with -2 in onlyautoornot
$selectedvalue = GETPOSTISSET("actioncode") ? GETPOST("actioncode", 'aZ09') : ($object->type_code ? $object->type_code : $default);
print $formactions->select_type_actions($selectedvalue, "actioncode", "systemauto", 0, -1, 0, 1); // TODO Replace 0 with -2 in onlyautoornot
print '</td></tr>';
}

Expand Down
19 changes: 16 additions & 3 deletions htdocs/core/class/html.formactions.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ function select_status() {
* @param int $max Max number of record
* @param string $moreparambacktopage More param for the backtopage
* @param string $morehtmlcenter More html text on center of title line
* @param int $assignedtouser Assign event by default to this user id (will be ignored if not enough permissions)
* @return int <0 if KO, >=0 if OK
*/
public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '')
public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0)
{
global $langs, $conf, $user;

Expand Down Expand Up @@ -225,9 +226,21 @@ public function showactions($object, $typeelement, $socid = 0, $forceshowtitle =
$taskid = $object->id;
}

$usercanaddaction = 0;
if (empty($assignedtouser) || $assignedtouser == $user->id) {
$usercanaddaction = $user->hasRight('agenda', 'myactions', 'create');
$assignedtouser = 0;
} else {
$usercanaddaction = $user->hasRight('agenda', 'allactions', 'create');
}

$newcardbutton = '';
if (isModEnabled('agenda') && !empty($user->rights->agenda->myactions->create)) {
$url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser')).'&origin='.urlencode($typeelement).'&originid='.((int) $object->id).((!empty($object->socid) && $object->socid > 0) ? '&socid='.((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid='.((int) $socid) : '')).($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '').'&backtopage='.urlencode($urlbacktopage);
if (isModEnabled('agenda') && $usercanaddaction) {
$url = DOL_URL_ROOT.'/comm/action/card.php?action=create&token='.newToken().'&datep='.urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser'));
$url .= '&origin='.urlencode($typeelement).'&originid='.((int) $object->id).((!empty($object->socid) && $object->socid > 0) ? '&socid='.((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid='.((int) $socid) : ''));
$url .= ($projectid > 0 ? '&projectid='.((int) $projectid) : '').($taskid > 0 ? '&taskid='.((int) $taskid) : '');
$url .= ($assignedtouser > 0 ? '&assignedtouser='.$assignedtouser : '');
$url .= '&backtopage='.urlencode($urlbacktopage);
$newcardbutton .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url);
}

Expand Down
2 changes: 1 addition & 1 deletion htdocs/user/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@
// List of actions on element
include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
$formactions = new FormActions($db);
$somethingshown = $formactions->showactions($object, 'user', $socid, 1);
$somethingshown = $formactions->showactions($object, 'user', $socid, 1, 'listactions', 0, '', '', $object->id);

print '</div></div>';
}
Expand Down

0 comments on commit 9a5a3a3

Please sign in to comment.