!! process to manage file zone (one file deposit only)
!! firstline word1 : type of process to read / word 2 teacher or student / word 3 identification num of zone
!! TODO....

!set p_=!line 1 of $wims_read_parm
!distribute word $p_ into proc_,stype_,zone_,activated_,user_
!bound activated_ within 1,0 default 0
!goto $proc_
!exit

:parahtml
!! form html interface for parameters
  !! ----- first parameter (title)
  !let num_=$[($zone_-1)*5+1]
  <div class="field box">
    !if $activated_=1
       <label for="param$(stype_)$num_"> $(name_titlezone)</label>
       <input type="text" id="param$(stype_)$num_" name="param$(stype_)$(num_)" value="$(param$(stype_)$(num_))" />
       <div class="formHelp">$name_desc_title</div>
    !else
      <strong>$(name_titlezone)</strong>
      <p>$(param$(stype_)$(num_))</p>
    !endif
  </div>
  !! ----- second parameter - description
  !let num_=$[($zone_-1)*5+2]
  <div class="field box">
    !if $activated_=1
       <label for="param$(stype_)$num_"> $(name_desczone)</label>
       <textarea name="param$(stype_)$(num_)" id="param$(stype_)$(num_)" rows="10" cols="100" class="iEdit" maxlength="$desc_limit">$(param$(stype_)$(num_))</textarea>
!!       <input type="text" id="param$(stype_)$num_" name="param$(stype_)$(num_)" value="$(param$(stype_)$(num_))" />
       <div class="formHelp">$name_desc_desc</div>
    !else
      <strong>$(name_desczone)</strong>
      <div>$(param$(stype_)$(num_))</div>
    !endif
  </div>
!exit

:pararead
  !! parameter reading
  !! --- parameter save 1 (title)
  param$(stype_)$[($zone_-1)*5+1]=!line 1 of $script_data
  param$(stype_)$[($zone_-1)*5+1]=!detag $(param$(stype_)$[($zone_-1)*5+1])
  param$(stype_)$[($zone_-1)*5+1]=!char 1 to $title_limit of $(param$(stype_)$[($zone_-1)*5+1])
  !! --- parameter save 2 (description)
  param$(stype_)$[($zone_-1)*5+2]=!line 2 of $script_data
  param$(stype_)$[($zone_-1)*5+2]=!char 1 to $desc_limit of $(param$(stype_)$[($zone_-1)*5+2])
  ltdownloadzone=!append item $(stype_)$zone_ to $ltdownloadzone
!exit

:parasave
  !! --- parameter save 1 (title)
  output_data=!replace internal $\
$ by ; in $(param$(stype_)$[($zone_-1)*5+1])
  output_data=!detag $output_data
  output_data=!char 1 to $title_limit of $output_data
  !! --- parameter save 2 (description)
  tmpdata_=!replace internal $\
$ by ; in $(param$(stype_)$[($zone_-1)*5+2])
  tmpdata_=!char 1 to $desc_limit of $tmpdata_
  output_data=$output_data\
$tmpdata_
!exit

:displayhtml
<div class="field box">
  !if $job!=configfw
    <h2 class="box_title">
      !if $(param$(stype_)$[($zone_-1)*5+1])!=$empty
        $(param$(stype_)$[($zone_-1)*5+1])
      !else
        $name_zone $zone_
      !endif
    </h2>
    <div class="freeworkdesczone">$(param$(stype_)$[($zone_-1)*5+2])</div>
  !else
    <strong>$(name_zonecontent)</strong>
  !endif
  !read proc/listfile.phtml $(stype_)$(zone_) $activated_ $user_
</div>
!exit

:displayread
  !if $stype_=student
    !! -- make list of file zone for user (not teacher) to manage capacity
    dir_=freeworksdata/$freework/work
    localdir_=$(user_)-file$zone_
  !else
    dir_=freeworks/$freework
    localdir_=$(stype_)-file$zone_
  !endif
  !sh mkdir -p $wims_home/log/classes/$wims_class/$dir_/$localdir_;
  !if $wims_user!=supervisor
    !! link for supervisor are permanent and made by var.proc file : only make specific link for user
    !! make link for upload file and generate list of file
    !sh mkdir -p $wims_home/$wims_sesdir/getfile/$dir_;\
        cd $wims_home/$wims_sesdir/getfile/$dir_;\
        rm -f $localdir_;\
        ln -s $wims_home/log/classes/$wims_class/$dir_/$localdir_ $localdir_;
  !endif
  flist$(stype_)$(zone_)=!filelist $wims_home/log/classes/$wims_class/$dir_/$localdir_
  flist$(stype_)$(zone_)=!words2items $(flist$(stype_)$(zone_))
!exit

:displaysave
  !if $stype_=teacher
      dir_=log/classes/$wims_class/freeworks/$freework/teacher-file$zone_
  !else
      dir_=log/classes/$wims_class/freeworksdata/$freework/work/$(user_)-file$zone_
  !endif
  !! ------- save newfile in the zone
  !if $job2=deposit$stype_ and $wims_deposit!=$empty and / notin $wims_deposit and .. notin $wims_deposit and noname.file!=$wims_deposit and $activated_=1
    !readproc adm/du $wims_home/$wims_sesdir/user-deposit
    du_=!sh du -ks $wims_home/$wims_sesdir/user-deposit;
    du_=!word 1 of $du_
    filesize_=$[$du_/1024]
    !if $stype_=student
      !ifval $filesize_+$used>0.25*$sizelimitfile
        auth_upload_=no
      !endif
      !if $auth_upload_=no
        error=quota_filestudent
        !exit
      !endif
    !endif
    !if $auth_upload!=yes or $filesize_>$quota_free
      error=quota_file
      !exit
    !endif
    !read proc/checkfilename.proc
    !if $error!=$empty
      !exit
    !endif
    success=goodaddfile
    used=$used+$filesize_
    !sh mv $wims_home/$wims_sesdir/user-deposit $wims_home/$dir_/$newfilename
    flist$(stype_)$(zone_)=!append item $newfilename to $(flist$(stype_)$(zone_))
    flist$(stype_)$(zone_)=!listuniq $(flist$(stype_)$(zone_))
    !readproc adm/class/quotafree.proc proc
    !exit
  !endif
  !! ------- delete file in the zone
  test_=!fileexists $wims_home/$dir_/$namefile
  !if $job2=erase$stype_ and $test_=yes and $activated_=1
    du_=!sh du -ks $wims_home/$dir_/$namefile;\
rm -f $wims_home/$dir_/$namefile
    du_=!word 1 of $du_
    success=gooderasefile
    used=$used-$[$du_/1024]
    flist$(stype_)$(zone_)=!listcomplement $namefile in $(flist$(stype_)$(zone_))
  !endif
!exit
