Subversion Repositories wimsdev

Rev

Rev 14335 | Rev 14572 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

!if $notallowed=1
  error=notallowedmodule
  !exit
!endif

!! check access
!if $statutfreework!=open
  !restart module=home
!endif

wims_prefix=class user
!read adm/language lang/names.phtml

tmp=!defof MAX_FREEWORKS\
MAX_USERFORGRADES in wimshome/public_html/bases/sys/define.conf
!distribute line $tmp into max_freeworks,max_userforgrades
title_limit=80
desc_limit=4000

!if $cmd=help
  !exit
!endif


!if $class_expiration=$empty
  !defread wimshome/log/classes/$wims_class/.def
  !if $wims_superclass!=$empty
    class_expiration=!defof class_expiration in wimshome/log/classes/$wims_superclass/.def
  !endif
!endif

!if $class_expiration=$empty
  error=bad_class
  !exit
!endif

jquery_defined=!defof jquery_defined in wimshome/public_html/themes/$class_theme/header.phtml

!if $cmd=resume and $jquery_defined!=yes
  !for k in infoshow1,infoshow2
    !bound $k within yes,no default yes
    !if $(wims_$k)!=$($k)
      wims_$k=$($k)
      !setdef wims_$k=$($k) in wimshome/session/$wims_session/var.stat
    !endif
  !next k
!endif


!! ------ check job function of user right
!if $wims_user=supervisor
  listjob=configfw,prep_activate,expire,hide,reactivate,deactivate,prep_erase,uploadco,savescore
  defjob=configfw
!else
  listjob=student1
  defjob=student1
!endif
!bound job within $listjob default $defjob

today=!char 1 to 8 of $wims_now
!! --------- read general data of the freework
nbfreework=!recordcnt wimshome/log/classes/$wims_class/freeworks/.freeworks
!if $wims_user=supervisor
  !if $job=configfw
    !bound freework between 1 and $[$nbfreework+1] default $[$nbfreework+1]
  !else
    !bound freework between 1 and $nbfreework default 1
  !endif
!else
  !bound freework between 1 and $nbfreework default 1
!endif
!if $freework>$max_freeworks
  error=bad_maxfreework
  !exit
!endif


!if $job isitemof configfw,uploadco,savescore
  uucnt=!recordcnt wimshome/log/classes/$wims_class/.grades
  !if $uucnt>0
    !! --- check for column for score
    tmp=!record 1 of wimshome/log/classes/$wims_class/.grades
    !distribute line $tmp into bl,score_title,bl
    score_title=!item 3 to -1 of $score_title
    nbscore=!itemcnt $score_title
    !! --- check for score key for each user
    uucnt=$[$uucnt-1]
    !for i=1 to $uucnt
      u_=!record $i+1 of wimshome/log/classes/$wims_class/.grades
      n_=!item 1 of $u_
      uulist=!append item $n_ to $uulist
    !next i
  !else
    nbscore=0
  !endif
!endif

!if $save=$empty and $freework<=$nbfreework
  tmp=!record $freework of wimshome/log/classes/$wims_class/freeworks/.freeworks
  !distribute line $tmp into activetest,expdate,title,desc,comment,type,deadline,soldate,sizelimitfile,scoring
  !for val in deadline,soldate
    t=!replace internal . by , in $($val)
    !distribute item $t into $val,time$val
    !default $val=$today
    !default time$val=00:00
  !next val
  !bound activetest between 0 and 3
  !if $type>=2 and $nbscore>0
    !bound scoring between 0 and $nbscore default 0
  !else
    scoring=0
  !endif
!endif

!if $freework>$nbfreework
  !default deadline=$today
  !default timedeadline=00:00
  !default soldate=$today
  !default timesoldate=00:01
  !default sizelimitfile=4
  wims_infoshow1=yes
  scoring=$empty
!endif

!! ---------  check variable
title=!singlespace $title
title=!char 1 to $title_limit of $title
title=!replace internal : by &#58; in $title

desc=!replace internal $\
$ by $ $ in $desc
desc=!singlespace $desc
desc=!char 1 to $desc_limit of $desc
desc=!replace internal : by &#58; in $desc

comment=!replace internal $\
$ by $ $ in $comment
comment=!singlespace $comment

!bound type between 1 and 3 default 1
!if $type=1
  sizelimitfile=$empty
!else
  !bound sizelimitfile between 1 and 10 default 4
  
!endif

!if $jquery_defined!=yes and $save!=$empty
  !for k in deadline,soldate
    !for l in month,day
      $(l)$(k)=$[100+$($(l)$(k))]
      $(l)$(k)=!char 2 to 3 of $($(l)$(k))
    !next l
  !next k
  deadline=$yeardeadline$monthdeadline$daydeadline
  soldate=$yearsoldate$monthsoldate$daysoldate
!endif

t=0
!for val in deadline,soldate
  !! -- check date format
  $val=!text select 0123456789 in $($val)
  expmon=!char 5 to 6 of $($val)
  expday=!char 7 to 8 of $($val)
  expyear=!char 1 to 4 of $($val)
  expmon=!char 2,3 of $[abs(floor($expmon))+100]
  expday=!char 2,3 of $[abs(floor($expday))+100]
  expyear=!char -4 to -1 of $[abs(floor($expyear))+100000]
  !if $expday>=1 and $expday<=31 and $expmon>=1 and $expmon<=12 \
      and $($val)<=$class_expiration \
      and N notin $expmon$expday$expyear
    $val=$expyear$expmon$expday
  !else
    $val=$class_expiration
  !endif
  !! -- check time format
  time$val=!text select 0123456789: in $(time$val)
  time$val=!replace internal : by , in $(time$val)
  nb=!itemcnt $(time$val)
  !if $nb=2
    !distribute item $(time$val) into h,m
    h=$[$h*1]
    m=$[$m*1]
    !if $h<0 or $h>23 or $m<0 or $m>59 or NaN isin $h$m
      time$val=00:0$t
    !else
      h=!char 2 to 3 of $[100+$h]
      m=!char 2 to 3 of $[100+$m]
      time$val=$h:$m
    !endif
  !else
    time$val=00:0$t
  !endif
  !increase t
!next val


!! ----------- end of check general variable


!! ------ make file link for download and some title
!if $wims_user=supervisor
  !if $freework>$nbfreework
    activetest=-1
    name_title=$name_tmkfreework
  !else
    name_title=$name_managefreework
  !endif
  !if $activetest>=0
    !sh cd $wims_home/$wims_sesdir;\
       mkdir -p getfile;\
       cd getfile;\
       mkdir -p freeworks;\
       cd freeworks;\
       rm -f $freework;\
       ln -s $wims_home/log/classes/$wims_class/freeworks/$freework $freework;
  !endif
!else
  name_title=!nosubst $wims_name_Freework $freework
  !if $activetest>=1
    flist1=!record 1 of wimshome/log/classes/$wims_class/freeworks/.freework$freework
    flist1=!nonempty line $flist1
    flist1=!lines2items $flist1
    d1=!char 1 to 14 of $wims_now
    d1=!text select char 0123456789 in $d1
    d2=!text select char 0123456789 in $(soldate)$(timesoldate)
    !if $d1>=$d2 or $activetest=2
      displaysolution=1
      flist2=!record 2 of wimshome/log/classes/$wims_class/freeworks/.freework$freework
      flist2=!nonempty line $flist2
      flist2=!lines2items $flist2
      flist=!listunion $flist1 and $flist2
    !else
      displaysolution=0
      flist=$flist1
    !endif
    flist=!items2words $flist
  !endif
  !if $flist!=$empty
    testfile=!word 1 of $flist
    test=!fileexists wimshome/sessions/$wims_session/getfile/freeworks/$freework/$testfile
    !if $test!=yes
      !sh cd $wims_home/$wims_sesdir;\
         mkdir -p getfile;\
         cd getfile;\
         rm -rf freeworks;\
         mkdir -p freeworks;\
         cd freeworks;\
         mkdir $freework;\
         cd $freework;\
         for k in $flist; do\
           ln -s $wims_home/log/classes/$wims_class/freeworks/$freework/$$k $$k;\
         done;
    !endif
  !endif
  !sh mkdir -p $wims_home/sessions/$wims_session/getfile/freeworksdata
!endif

!read lang.phtml.$lang
!changeto $job.proc