From 4cff4c693532bb93bfa0feb4620a1f9758784b82 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 25 Nov 2017 00:12:45 +0100 Subject: [PATCH] Simplify and standardize code for agenda pages --- htdocs/comm/action/card.php | 19 +++-- htdocs/comm/action/index.php | 87 +++++++++++---------- htdocs/comm/action/list.php | 18 +++-- htdocs/comm/action/peruser.php | 129 ++++++++++++++++++++++---------- htdocs/core/lib/agenda.lib.php | 16 ++-- htdocs/theme/eldy/style.css.php | 4 +- 6 files changed, 170 insertions(+), 103 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 03c087e1a4e..b4dda563397 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -545,8 +545,9 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') /* * Action move update, used when user move an event in calendar by drag'n drop + * TODO Move this into page comm/action/index that trigger this call by the drag and drop of event. */ -if ($action == 'mupdate') +if (GETPOST('actionmove','alpha') == 'mupdate') { $object->fetch($id); $object->fetch_userassigned(); @@ -557,7 +558,7 @@ if ($action == 'mupdate') $newdate=GETPOST('newdate','alpha'); if (empty($newdate) || strpos($newdate,'dayevent_') != 0 ) { - header("Location: ".$backtopage); + header("Location: ".$backtopage); exit; } @@ -1296,14 +1297,18 @@ if ($id > 0) // Link to other agenda views $out=''; - $out.='
  • '.img_picto($langs->trans("ViewPerUser"),'object_calendarperuser','class="hideonsmartphone pictoactionview"'); - $out.=''.$langs->trans("ViewPerUser").''; - $out.='
  • '.img_picto($langs->trans("ViewCal"),'object_calendar','class="hideonsmartphone pictoactionview"'); + $out.='
  • '; + $out.='
  • '.img_picto($langs->trans("ViewCal"),'object_calendar','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewCal").''; - $out.='
  • '.img_picto($langs->trans("ViewWeek"),'object_calendarweek','class="hideonsmartphone pictoactionview"'); + $out.='
  • '; + $out.='
  • '.img_picto($langs->trans("ViewWeek"),'object_calendarweek','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewWeek").''; - $out.='
  • '.img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone pictoactionview"'); + $out.='
  • '; + $out.='
  • '.img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewDay").''; + $out.='
  • '; + $out.='
  • '.img_picto($langs->trans("ViewPerUser"),'object_calendarperuser','class="hideonsmartphone pictoactionview"'); + $out.=''.$langs->trans("ViewPerUser").''; $linkback.=$out; $morehtmlref='
    '; diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 4418cc014fb..cfa4fd18508 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -359,6 +359,8 @@ $paramnoaction=preg_replace('/action=[a-z_]+/','',$param); $head = calendars_prepare_head($paramnoaction); +print '
    '."\n"; + dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,$listofextcals,$actioncode,$usergroup,'', $resourceid); dol_fiche_end(); @@ -371,25 +373,28 @@ $showextcals=$listofextcals; if (! empty($conf->use_javascript_ajax)) // If javascript on { - $s.=''."\n"; + $s.="\n".''."\n"; $s.='' . "\n"; + // Code to enable drag and drop + $s.='jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n"; + // Code to submit form + $s.='console.log("submit form to record new event");'."\n"; + //$s.='console.log(event.target);'; + $s.='var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n"; + $s.='console.log("found parent div.dayevent with id = "+newval);'."\n"; + $s.='var frm=jQuery("#searchFormList");'."\n"; + $s.='var newurl = ui.item.find("a.cal_event").attr("href");'."\n"; + $s.='console.log(newurl);'."\n"; + $s.='frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n"; + $s.='});'."\n"; + } + $s.='});' . "\n"; + $s.='' . "\n"; // Local calendar $s.='
    ' . $langs->trans("LocalAgenda").'  
    '; @@ -1088,12 +1093,10 @@ if (empty($action) || $action == 'show_month') // View by month echo " \n"; } echo "\n"; - echo ''; - echo ''; - echo ''; - echo '' ; - echo '
    '; + echo ''; + echo ''; + echo '' ; } elseif ($action == 'show_week') // View by week { @@ -1142,11 +1145,10 @@ elseif ($action == 'show_week') // View by week echo " \n"; echo "\n"; - echo '
    '; + + echo ''; echo ''; - echo ''; echo '' ; - echo '
    '; } else // View by day { @@ -1177,6 +1179,8 @@ else // View by day echo ''; } +print "\n".''; + llxFooter(); $db->close(); @@ -1240,11 +1244,12 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa print '
    '; //$curtime = dol_mktime (0, 0, 0, $month, $day, $year); - $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array(); + $i=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array(); $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day); - $nextindextouse=count($colorindexused); // At first run this is 0, so fist user has 0, next 1, ... - //print $nextindextouse; + $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0 + $nextindextouse=count($colorindexused); // At first run this is 0, so first user has 0, next 1, ... + //var_dump($colorindexused); foreach ($eventarray as $daykey => $notused) { @@ -1258,25 +1263,24 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { $keysofuserassigned=array_keys($event->userassigned); - $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); // Define $color (Hex string like '0088FF') and $cssclass of event - $color=-1; $colorindex=-1; + $color=-1; $cssclass=''; $colorindex=-1; if (in_array($user->id, $keysofuserassigned)) { - $nummytasks++; $cssclass='family_mytasks'; + $cssclass='family_mytasks'; - if (empty($cacheusers[$event->userownerid])) - { - $newuser=new User($db); - $newuser->fetch($event->userownerid); - $cacheusers[$event->userownerid]=$newuser; - } - //var_dump($cacheusers[$event->userownerid]->color); + if (empty($cacheusers[$event->userownerid])) + { + $newuser=new User($db); + $newuser->fetch($event->userownerid); + $cacheusers[$event->userownerid]=$newuser; + } + //var_dump($cacheusers[$event->userownerid]->color); - // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) - if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color; + // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) + if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color; } else if ($event->type_code == 'ICALEVENT') // Event come from external ical file { @@ -1287,6 +1291,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa } $numicals[dol_string_nospecial($event->icalname)]++; } + $color=($event->icalcolor?$event->icalcolor:-1); $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other'); } @@ -1311,7 +1316,8 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color; } - if ($color == -1) // Color was not forced. Set color according to color index. + + if ($color < 0) // Color was not set on user card. Set color according to color index. { // Define color index if not yet defined $idusertouse=($event->userownerid?$event->userownerid:0); @@ -1321,8 +1327,8 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa } else { - $colorindex=$nextindextouse; - $colorindexused[$idusertouse]=$colorindex; + $colorindex=$nextindextouse; + $colorindexused[$idusertouse]=$colorindex; if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++; // Prepare to use next color } //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'
    '; @@ -1358,7 +1364,6 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa }else{ $cssclass.= " unmovable"; } - } $h=''; $nowrapontd=1; @@ -1376,7 +1381,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa //var_dump($event->userassigned); //var_dump($event->transparency); print ''."\n"; + dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbirthday,0,$filtert,0,$pid,$socid,$action,-1,$actioncode,$usergroup,'',$resourceid); dol_fiche_end(); @@ -393,7 +395,6 @@ if ($resql) } - print ''."\n"; if ($optioncss != '') print ''; print ''; print ''; @@ -404,7 +405,7 @@ if ($resql) print ''; $nav=''; if ($optioncss != '') $nav.= ''; - if ($actioncode) $nav.=''; + //if ($actioncode) $nav.=''; if ($resourceid) $nav.=''; if ($filter) $nav.=''; if ($filtert) $nav.=''; @@ -627,14 +628,16 @@ if ($resql) if ($late) print img_warning($langs->trans("Late")).' '; print ''; } + + // End date if (! empty($arrayfields['a.datep2']['checked'])) { - // End date print ''; } + + // Third party if (! empty($arrayfields['s.nom']['checked'])) { - // Third party print ''; } + + // Contact if (! empty($arrayfields['a.fk_contact']['checked'])) { - // Contact print ''; } + + // Linked object if (! empty($arrayfields['a.fk_element']['checked'])) { - // Linked object print ''; } + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 188d2e6296f..a4154f5a9e4 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -218,8 +218,13 @@ if ($showbirthday) $param.="&showbirthday=1"; if ($pid) $param.="&projectid=".$pid; if ($type) $param.="&type=".$type; if ($action == 'show_day' || $action == 'show_week' || $action == 'show_month' || $action != 'show_peruser') $param.='&action='.$action; +if ($begin_h != '') $param.='&begin_h='.$begin_h; +if ($end_h != '') $param.='&end_h='.$end_h; +if ($begin_d != '') $param.='&begin_d='.$begin_d; +if ($end_d != '') $param.='&end_d='.$end_d; $param.="&maxprint=".$maxprint; + $prev = dol_get_first_day_week($day, $month, $year); //print "day=".$day." month=".$month." year=".$year; //var_dump($prev); exit; @@ -248,15 +253,15 @@ $lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd'); $max_day_in_month = date("t",dol_mktime(0,0,0,$month,1,$year)); $tmpday = $first_day; +$picto='calendarweek'; $nav ="trans("Previous"))."\">   \n"; $nav.=" ".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week; $nav.=" \n"; $nav.="   trans("Next"))."\">\n"; $nav.="   (".$langs->trans("Today").")"; -$picto='calendarweek'; -$nav.='   '; +/*$nav.='   '; $nav.=''; $nav.=''; $nav.=''; @@ -271,10 +276,10 @@ $nav.=''; $nav.=''; $nav.=''; $nav.=''; - +*/ $nav.=$form->select_date($dateselect, 'dateselect', 0, 0, 1, '', 1, 0, 1); $nav.=' '; -$nav.=''; +//$nav.=''; // Must be after the nav definition $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:''); @@ -294,6 +299,8 @@ $paramnoaction=preg_replace('/action=[a-z_]+/','',$param); $head = calendars_prepare_head($paramnoaction); +print ''."\n"; + dol_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action'); print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid); dol_fiche_end(); @@ -581,6 +588,7 @@ else $maxnbofchar=18; $cachethirdparties=array(); $cachecontacts=array(); +$cacheusers=array(); // Define theme_datacolor array $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php"; @@ -602,11 +610,9 @@ $newparam=preg_replace('/viewweek=[0-9]+&?/i','',$newparam); $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restore correct parameter $newparam.='&viewweek=1'; -echo ''; +echo ''; echo ''; -echo ''; echo '' ; -echo ''; // Line header with list of days @@ -792,7 +798,7 @@ foreach ($usernames as $username) echo "
    '; print dol_print_date($db->jdate($obj->dp2),"dayhour"); print ''; if ($obj->socid) { @@ -646,8 +649,9 @@ if ($resql) else print ' '; print ''; if ($obj->fk_contact > 0) { @@ -662,8 +666,9 @@ if ($resql) } print ''; if ($obj->fk_element > 0 && ! empty($obj->elementtype)) { include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; @@ -674,6 +679,7 @@ if ($resql) print '
    \n"; echo '
    '; -if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) +if (! empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! empty($conf->global->AGENDA_USE_COLOR_PER_EVENT_TYPE)) { $langs->load("commercial"); print '
    '.$langs->trans("Legend").':
    '; @@ -817,6 +823,9 @@ if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) */ } +print "\n".''; +print "\n"; + // Add js code to manage click on a box print '