!!##preparation of the "bottom menu"

!if _check isin $session or $wims_mode=popup
  !read themes.phtml tail
  !exit
!endif

!if _test isin $session and $wims_hacked_variables!=$empty
  <p><span class="wims_warning">WIMS WARNING</span>. The following variables of your module could be hacked
    by students using manually modified http addresses! You might want to put more
    strict permissions to them in var.def, in order to build a secure exercise module.
  </p>
  <pre>$wims_hacked_variables</pre>
!endif

!read name.phtml.$lang
!read themes/$wims_theme/name.phtml.$lang
!default wims_homeref_bgcolor=$wims_ref_bgcolor
!read themes/$wims_theme/local.phtml

!if exam isin $wims_session
  !read examclock.proc
  !goto rmend
!endif

!if $wims_rm_1=no
  !reset wims_rm_1
  !goto local
!endif
!if $wims_rm_1!=$empty
  !goto rm2
!endif
!reset 1_

!!********* Link #1 : "Close Window" or "Home" (Not Shown if Embedded)
!if _ isin $wims_subsession
  !!set 1_=!append line back2,3,window.close() to $1_
!else
  !!set 1_=!append line class_home,1,session=$wims_session.1 to $1_
!endif

!!********* Link #2 : "Sheet"
!if $wims_sheet>0 or P isin $wims_sheet
  !if $wims_sheet>0
    !set tmp_=sheetmanagement,1,module=adm/class/sheet&sheet=$wims_sheet
  !else
    !set tmp_=sheet,1,module=adm/sheet&sh=$wims_sheet&
  !endif
  !if yes notin $wims_lightpopup
    !set 1_=!append line $tmp_ to $1_
  !endif
  !let wims_menu_items=!append line $tmp_ to $wims_menu_items
  !let p=!positionof item $wims_exo in $wims_listexo
  !if $wims_exo!=$(wims_listexo[1])
    !let wims_menu_items=!append line previousseries,1,module=home&directworksheet=$wims_sheet.$(wims_listexo[$p-1]) to $wims_menu_items
  !endif
  !if $wims_exo!=$(wims_listexo[-1])
    !let wims_menu_items=!append line nextseries,1,module=home&directworksheet=$wims_sheet.$(wims_listexo[$p+1]) to $wims_menu_items
  !endif
!endif

!if $wims_sheet>0 or P isin $wims_sheet
  !if $(wims_exofeedback[$wims_exo;])!=$empty
    !if $module_score!=$empty
      !set feedexotot=!declosing $(wims_exofeedback[$wims_exo;])
      !set feedexocnt=!itemcnt $(feedexotot[;1])
      !for t=1 to $feedexocnt
        !set feedexo=$(feedexotot[$t;])
        !if $module_score < $(feedexo[2]) and $module_score >= $(feedexo[3])
          !if $module_score < 10
            !set 5_=!append line feedbackexo,7,$(feedexo[1]),mfeed to $5_
          !else
            !set 5_=!append line feedbackplus,7,$(feedexo[1]),mfeed to $5_
          !endif
        !endif
      !next
    !endif
  !endif
!endif

!!********* Link #3 : "Resume"
!if $cmd=help or $cmd=hint
  !set 1_=!append line resume,1,cmd=resume to $1_
!endif

!!********* Link #4 : "Introduction" (Not Shown if Embedded)
!if $module_has_intro=yes and $cmd notwordof intro help and\
        $wims_sheet=$empty and exam notin $wims_session
  !!set 1_=!append line intro,1,module=$module&cmd=intro&special_parm=$special_parm&special_parm2=$special_parm2&special_parm3=$special_parm3&special_parm4=$special_parm4 to $1_
!endif

!!********* Link #5 : "Help"
!if $module_has_help=yes and $cmd notwordof intro help
  !if $module_help=$empty or $module_help=popup
   !!set 1_=!append line help,4,module=$module&cmd=help&special_parm=$wims_help_parm,mhelp to $1_
  !else
   !!set 1_=!append line help,1,module=$module&cmd=help&special_parm=$wims_help_parm to $1_
  !endif
!endif

!!********* Link #6 : "About"
!if $module_has_about=yes and $cmd notwordof help intro
  !!set 1_=!append line about,4,module=$module&cmd=help&special_parm=about,mhelp to $1_
!endif

!if print isin $job,$job2 or $print!=
  !set 1_=!append line print,3,window.print() to $1_
!endif
!set wims_rm_1=$1_

:local
!reset 1_
!if $wims_sheet!=$empty or _exam isin $wims_session
  !set 1_=!append line itemsep,0,\
  tools,4,module=home,tool\
  to $1_
!endif

!if $wims_developer!=$empty and COPYING isin $module_copyright and ../classes/ notin ../$module
  !set V_=!char 1 of $module
  !set M_=!translate internal / to , in $module
  !set M_=!item 1 of $M_
  !if $V_ isin ABCDEFGHIJKLMNOPQRTSUVWXYZ or $M_ iswordof local contrib tool
    !set 1_=!append line modify,1,module=adm/modtool&original=$module to $1_
  !endif
!endif
!if $wims_user=supervisor and $module=adm/class/glossary
  !set 1_=!append line newglose,1,module=adm/tool/glossary&gl=0 to $1_
!endif
!if $wims_user=supervisor and ((_adm/doc notin _$module and adddoc notin $module \
    and (document iswordof $module_category or tool iswordof $module_category))\
    or _c isin _$doc)
  !if document iswordof $module_category or _c isin _$doc
    !set wims_homeref_parm=doc=$doc&block=$block&job=read
    !set wims_homeref_parm=!replace internal & by %26 in $wims_homeref_parm
  !endif
  !if adm/tool/glossary isin $module
    !if $gl=0
      !if $special_parm!=$empty
        !set wims_homeref_parm=!getopt gloss_item in $module_init_parm
        !set 1_=!append line addglossary,1,module=adm/class/glossary&job=add&iniparm=$wims_homeref_parm to $1_
      !endif
    !else
      !set wims_homeref_parm=gl=$gl
      !set 1_=!append line newglose,1,module=adm/tool/glossary&gl=0 to $1_
    !endif
  !else
    !if _c notin _$doc
      !default wims_homeref_parm=$module_init_parm
      !set 1_=!append line adddoc,1,module=adm/class/adddoc&job=add&dir=$module&iniparm=$wims_homeref_parm to $1_
    !endif
  !endif
  !if ($gl>0 and $cmd!=reply) or adm/tool/glossary notin $module
    !set 1_=!append line addh,1,module=adm/class/addmodule&job=helpexo&dir=$module&iniparm=$wims_homeref_parm to $1_
  !endif
  !if $gl=0 and adm/tool/glossary isin $module and $wims_homeref_parm!=$empty
    !set 1_=!append line addh,1,module=adm/class/addmodule&job=helpexo&dir=$module&iniparm=special_parm=$wims_homeref_parm to $1_
  !endif
!endif
!if $wims_user=supervisor and $module=adm/doc
  !set 1_=!append line doch_docs,1,module=adm/doc&job=home to $1_
!endif
!if $special_parm4=$empty
  !let tmptest=print=yes
  !if $cmd!=intro and $cmd!=help and $module!=home and \
    ../adm/ notin ../$module and \
      (../devel/ notin ../$module or $wims_devel_modules iswordof open) \
      and exercise isin $module_category and $tmptest notin $module_init_parm
    !set wims_homeref_parm=!replace internal % by %25 in $module_init_parm
    !set wims_homeref_parm=!replace internal + by %2B in $wims_homeref_parm
    !set wims_homeref_parm=!replace internal & by %26 in $wims_homeref_parm
    !set wims_homeref_parm=!replace internal ; by %3B in $wims_homeref_parm
    !set wims_homeref_parm=!lines2rows $wims_homeref_parm
    !set 1_=!append line add,1,module=adm/class/addmodule&dir=$module&scoring=$module_scoring&iniparm=$wims_homeref_parm to $1_
    !set 1_=!append line addh,1,module=adm/class/addmodule&job=helpexo&dir=$module&scoring=$module_scoring&iniparm=$wims_homeref_parm to $1_
    !set 1_=!append line addfw,1,module=adm/class/freework&job=addexo&dir=$module&scoring=$module_scoring&iniparm=$wims_homeref_parm to $1_
  !endif
  !if $wims_user=supervisor and exam notin $session and \
    ..classes/ notin ..$module and ..adm/ notin ..$module and \
    ..devel/ notin ..$module and \
      GNU isin $module_copyright and \
      _check notin $session and \
      $class_importation!=no and $thisexo!=
    !set 1_=!append line import,1,module=adm/createxo&existing=$thisexo&catmodule=$module to $1_
  !endif

!else
  !! ----- place pour ajouter le lien vers la modification de serie dans une feuille
  !if $cmd!=intro and $cmd!=help and $module!=home and \
      ../adm/ notin ../$module and \
      (../devel/ notin ../$module or $wims_devel_modules iswordof open)
    !set wims_homeref_parm=!replace % by %25 in $module_init_parm
    !set wims_homeref_parm=!replace + by %2B in $wims_homeref_parm
    !set wims_homeref_parm=!replace & by %26 in $wims_homeref_parm
    !set 1_=!append line chseries,1,module=adm/class/sheet&dir=$module&scoring=$module_scoring&iniparm=$wims_homeref_parm&job=chseries&num=$special_parm4 to $1_
  !endif
!endif
!! add module links to general links with a separation
!if $wims_menu_items!=$empty
  !set 1_=!append line itemsep,0,\
$wims_menu_items to $1_
!endif
!if $wims_user=supervisor and $cmd!=intro and $cmd!=help and $module!=home and \
    ../adm/ notin ../$module and ($module_category!=document or $job=exosource)\
    and $module_category!=help
  !!last condition is for the uniq module help/main.$lang
  !if $job=exosource
    !set tmp=back2
    !if $block!=$empty
      !set docbl=block=$block
    !else
      !reset docbl
    !endif
  !else
    !set tmp=moduback
  !endif
  !set 1_=!append line $tmp,1,module=$module&cmd=intro&special_parm=$special_parm&special_parm2=$special_parm2&special_parm3=$special_parm3&special_parm4=$special_parm4&$docbl to $1_
!endif
!! next exo and prev exo in the menu for supervisor
!if $wims_user=supervisor and $exoprev$exonext != $empty and $wims_sheet=$empty
  !set 1_=!append line itemsep,0\
prev,1,cmd=new&module=$module&exo=$exoprev&special_parm=$special_parm&special_parm2=$special_parm2&special_parm3=$special_parm3&special_parm4=$special_parm4  \
to $1_
  !set 1_=!append line next,1,cmd=new&module=$module&exo=$exonext&special_parm=$special_parm&special_parm2=$special_parm2&special_parm3=$special_parm3&special_parm4=$special_parm4  \
to $1_
  !reset exoprev exonext
!endif

!if $special_parm4=$empty
  !if $cmd!=intro and $cmd!=help and $module!=home and \
      ../adm/ notin ../$module and \
      (../devel/ notin ../$module or $wims_devel_modules iswordof open) \
      and oef isin $module_category and $wims_classification_open=yes and ../devel/ notin ../$module
    !set 1_=!append line itemsep,0,\
    Indexation,4,module=adm/tool/classification&refdir=$module&iniparm=$wims_homeref_parm,test to $1_
  !endif
!endif
!if $module_score!=$empty and $wims_class_exolog>0 and E notin $wims_sheet
  !set 1_=!append line exolog,1,module=adm/class/exolog&cmd=new&job=log&logsheet=$wims_sheet&logexo=$wims_exo to $1_
!endif


!! When in lightpopup mode, only links in whitelist are available

!if yes isin $wims_lightpopup
  !set whitelist = nextseries,previousseries
  !set nb_elem=!linecnt $1_
  !for a=1 to $nb_elem
    !set element = !line $a of $1_
    !set id = !item 1 of $element
    !if $id isitemof $whitelist
      !set wims_rm_0 = !append line $element to $wims_rm_0
    !endif
  !next
!else
  !set wims_rm_0=$1_
!endif

!set wims_rm_3=!append line $wims_menu_tabs to $wims_rm_3
:rm2
!if $wims_rm_2!=$empty
  !goto rmend
!endif
!reset 2_

!!********* Link #8 : "Author(s)"

!if $module_author!=$empty and @ isin $module_address
  !read namewriting.phtml $module_author
  !set wims_homeref_author_num=$script_cnt
  !set module_address=!replace internal ; by , in $module_address
  !if $wims_homeref_author_num>1
    !set 3_=$wims_name_authors:
  !else
    !set 3_=$wims_name_author:
  !endif
  !set 4_=
  !for ad=1 to $wims_homeref_author_num
    !if $(module_address[$ad])!= and @ isin $(module_address[$ad])
      !set 4__=!mailurl $(module_address[$ad]) $(script_out[$ad])\
WIMS $module_title [$module_language]
    !else
      !set 4__=$(script_out[$ad])
   !endif
  !set 4_=!append item $4__ to $4_
  !next
  !set 2_=!append line author,0,$3_ $4_ to $2_
!endif

!!********* Link #9 : "Translator(s)"
!set mod_transl=$(module_translator_$lang)
!if $module_transl!=$empty
  !set module_translator=$mod_transl
  !set module_translator_address=$(module_translator_address_$lang)
!endif

!if $module_translator!=$empty and $module_translator_address!=$empty
  !read namewriting.phtml $module_translator
  !set module_translator=$(script_out[1])
  !set wims_homeref_translator_num=$script_cnt
  !set module_translator_address=!replace internal ; by , in $module_translator_address
  !for ad=1 to $wims_homeref_translator_num
    !set 3_=!mailurl $(module_translator_address[$ad]) $(module_translator[$ad])\
WIMS $module_title [$module_language]
    !set 2_=!append line trans,0,$wims_name_translatedby $3_ to $2_
  !next
!endif
!if $wims_theme_version>=1
  !reset 2_
!endif
!set 2_=!append line syou,0,$wims_name_syou to $2_
!set 2_=!append line class,0,$wims_classname ($wims_institutionname) to $2_

!read date.phtml $wims_now,noprint
!set 2_=!append line time,0,$wims_name_server_time: $slib_out to $2_
!set wims_rm_2=$2_
!set wims_rm_5=$5_

:rmend
!set wims_homeref_n1=!linecnt $wims_rm_1
!set wims_homeref_n2=!linecnt $wims_rm_2
!set wims_homeref_n0=!linecnt $wims_rm_0
!set wims_homeref_n3=!linecnt $wims_rm_3
!!</div><!--div dans homeref_supervisor-->
!set wims_homeref_n5=!linecnt $wims_rm_5
!set wims_homeref_local_n0=!linecnt $wims_local_menu_items
!read themes.phtml tail
!robottrap
