/**
  * Check submission restriction
  * @param $data Object with submitted data
  * @param & $error string
  * @return bool
  **/
 function pass_submission_restriction(&$alldata, &$error)
 {
     $max = $this->get_maxfilesize();
     $rfn = $this->get_required_fgm();
     $list = $rfn->getFilelist();
     $error = '';
     if (count($alldata) > $this->instance->maxfiles) {
         $error .= get_string('maxfilesexceeded', VPL) . "\n";
     }
     $lr = count($list);
     $lad = count($alldata);
     for ($i = 0; $i < $lad; $i++) {
         $name = $alldata[$i]['name'];
         $data = $alldata[$i]['data'];
         if (strlen($data) > $max) {
             $error .= '"' . s($name) . '" ' . get_string('maxfilesizeexceeded', VPL) . "<br />";
         }
         if (!vpl_is_valid_path_name($name)) {
             $error .= '"' . s($name) . '" ' . get_string('incorrect_file_name', VPL) . "<br />";
         }
         if ($i < $lr && $list[$i] != $name) {
             $a = new stdClass();
             $a->expected = $list[$i];
             $a->found = $name;
             $error .= s(get_string('unexpected_file_name', VPL, $a)) . "<br />";
         }
     }
     return strlen($error) == 0;
 }
 /**
  * Rename a file
  *
  * @param int $num
  * @param string $filename new filename
  * @return bool (renamed==true)
  */
 function renameFile($num, $filename)
 {
     if ($num < $this->numstaticfiles || !vpl_is_valid_path_name($filename)) {
         return false;
     }
     ignore_user_abort(true);
     $filelist = $this->getFileList();
     if (array_search($filename, $filelist) !== false) {
         return false;
     }
     if ($num >= 0 && $num < count($filelist)) {
         $path1 = $this->dir . self::encodeFileName($filelist[$num]);
         $path2 = $this->dir . self::encodeFileName($filename);
         if (file_exists($path1)) {
             rename($path1, $path2);
             $filelist[$num] = $filename;
             $this->setFileList($filelist);
             return true;
         }
     }
     return false;
 }