ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilFileDataExercise Class Reference

This class handles all operations on files for the exercise object. More...

+ Inheritance diagram for ilFileDataExercise:
+ Collaboration diagram for ilFileDataExercise:

Public Member Functions

 ilFileDataExercise ($a_obj_id=0)
 Constructor call base constructors checks if directory is writable and sets the optional obj_id.
 getObjId ()
 getExercisePath ()
 get exercise path public
 getFiles ()
 ilClone ($a_new_obj_id)
 delete ()
 storeUploadedFile ($a_http_post_file, $secure_filename=false, $is_unziped=false)
 store uploaded file in filesystem
 storeContentAsFile ($filename, $content, $secure_filename=false)
 store content as file in filesystem
 downloadAllDeliveredFiles ($members)
 Download all submitted files of all members.
 unlinkFiles ($a_filenames)
 unlink files: expects an array of filenames e.g.
 unlinkFile ($a_filename)
 unlink one uploaded file expects a filename e.g 'foo'
 getAbsolutePath ($a_path)
 get absolute path of filename
 checkFilesExist ($a_files)
 check if files exist
 __checkPath ()
 __checkReadWrite ()
 check if directory is writable overwritten method from base class private
 __initDirectory ()
 init directory overwritten method public
 __rotateFiles ($a_path)
 rotate files with same name recursive method
- Public Member Functions inherited from ilFileData
 ilFileData ()
 Constructor class bas constructor and read path of directory from ilias.ini setup an mail object public.
 checkPath ($a_path)
 check if path exists and is writable
 getPath ()
 get Path public
- Public Member Functions inherited from ilFile
 ilFile ()
 Constructor get ilias object public.
 deleteTrailingSlash ($a_path)
 delete trailing slash of path variables

Data Fields

 $obj_id
 $exercise_path

Detailed Description

This class handles all operations on files for the exercise object.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 14 of file class.ilFileDataExercise.php.

Member Function Documentation

ilFileDataExercise::__checkPath ( )

Definition at line 382 of file class.ilFileDataExercise.php.

References __checkReadWrite(), and getExercisePath().

Referenced by ilFileDataExercise().

{
if(!@file_exists($this->getExercisePath()))
{
return false;
}
$this->__checkReadWrite();
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataExercise::__checkReadWrite ( )

check if directory is writable overwritten method from base class private

Returns
bool

Definition at line 398 of file class.ilFileDataExercise.php.

Referenced by __checkPath().

{
if(is_writable($this->exercise_path) && is_readable($this->exercise_path))
{
return true;
}
else
{
$this->ilias->raiseError("Exercise directory is not readable/writable by webserver",$this->ilias->error_obj->FATAL);
}
}

+ Here is the caller graph for this function:

ilFileDataExercise::__initDirectory ( )

init directory overwritten method public

Returns
string path

Definition at line 415 of file class.ilFileDataExercise.php.

References ilFileData\getPath(), and ilUtil\makeDir().

Referenced by ilFileDataExercise().

{
if(is_writable($this->getPath()))
{
return ilUtil::makeDir($this->excercise_path = $this->getPath().'/'.EXERCISE_PATH);
}
return false;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataExercise::__rotateFiles (   $a_path)

rotate files with same name recursive method

Parameters
stringfilename private
Returns
bool

Definition at line 430 of file class.ilFileDataExercise.php.

Referenced by storeContentAsFile(), and storeUploadedFile().

{
if(file_exists($a_path))
{
$this->__rotateFiles($a_path.".old");
return rename($a_path,$a_path.'.old');
}
return true;
}

+ Here is the caller graph for this function:

ilFileDataExercise::checkFilesExist (   $a_files)

check if files exist

Parameters
arrayfilenames to check public
Returns
bool

Definition at line 365 of file class.ilFileDataExercise.php.

References $file.

{
if($a_files)
{
foreach($a_files as $file)
{
if(!file_exists($this->exercise_path.'/'.$this->obj_id.'_'.$file))
{
return false;
}
}
return true;
}
return true;
}
ilFileDataExercise::delete ( )

Definition at line 104 of file class.ilFileDataExercise.php.

References $file, ilUtil\delDir(), getExercisePath(), getFiles(), and unlinkFile().

{
foreach($this->getFiles() as $file)
{
$this->unlinkFile($file["name"]);
}
$delivered_file_path = $this->getExercisePath() . "/" . $this->obj_id . "/";
if (is_dir($delivered_file_path))
{
include_once "./Services/Utilities/classes/class.ilUtil.php";
ilUtil::delDir($delivered_file_path);
}
return true;
}

+ Here is the call graph for this function:

ilFileDataExercise::downloadAllDeliveredFiles (   $members)

Download all submitted files of all members.

Parameters
$membersarray of user names, key is user id

Definition at line 209 of file class.ilFileDataExercise.php.

References $lng, ilObjUser\_lookupLogin(), ilObjUser\_lookupName(), ilUtil\delDir(), ilUtil\deliverFile(), ilUtil\dirsize(), ilUtil\escapeShellArg(), ilUtil\getASCIIFilename(), getExercisePath(), getObjId(), ilUtil\ilTempnam(), and ilUtil\makeDir().

{
require_once "./Services/Utilities/classes/class.ilUtil.php";
global $lng, $ilObjDataCache;
ksort($members);
$savepath = $this->getExercisePath() . "/" . $this->obj_id . "/";
$cdir = getcwd();
// important check: if the directory does not exist
// ILIAS stays in the current directory (echoing only a warning)
// and the zip command below archives the whole ILIAS directory
// (including the data directory) and sends a mega file to the user :-o
if (!is_dir($savepath))
{
return;
}
// Safe mode fix
chdir($this->getExercisePath());
$zip = PATH_TO_ZIP;
// check first, if we have enough free disk space to copy all files to temporary directory
$tmpdir = ilUtil::ilTempnam();
ilUtil::makeDir($tmpdir);
chdir($tmpdir);
$dirsize = 0;
foreach ($members as $id => $object) {
$directory = $savepath.DIRECTORY_SEPARATOR.$id;
$dirsize += ilUtil::dirsize($directory);
}
if ($dirsize > disk_free_space($tmpdir)) {
return -1;
}
// copy all member directories to the temporary folder
// switch from id to member name and append the login if the member name is double
// ensure that no illegal filenames will be created
// remove timestamp from filename
$cache = array();
foreach ($members as $id => $user)
{
$sourcedir = $savepath.DIRECTORY_SEPARATOR.$id;
if (!is_dir($sourcedir))
continue;
$userName = ilObjUser::_lookupName($id);
$directory = ilUtil::getASCIIFilename(trim($userName["lastname"])."_".trim($userName["firstname"]));
if (array_key_exists($directory, $cache))
{
// first try is to append the login;
$directory = ilUtil::getASCIIFilename($directory."_".trim(ilObjUser::_lookupLogin($id)));
if (array_key_exists($directory, $cache)) {
// second and secure: append the user id as well.
$directory .= "_".$id;
}
}
$cache[$directory] = $directory;
ilUtil::makeDir ($directory);
$sourcefiles = scandir($sourcedir);
foreach ($sourcefiles as $sourcefile) {
if ($sourcefile == "." || $sourcefile == "..")
continue;
$targetfile = trim(basename($sourcefile));
$pos = strpos($targetfile, "_");
if ($pos === false)
{
} else
{
$targetfile= substr($targetfile, $pos + 1);
}
$targetfile = $directory.DIRECTORY_SEPARATOR.$targetfile;
$sourcefile = $sourcedir.DIRECTORY_SEPARATOR.$sourcefile;
if (!copy ($sourcefile, $targetfile))
{
//echo 'Could not copy '.$sourcefile.' to '.$targetfile;
$this->ilias->raiseError('Could not copy '.basename($sourcefile)." to '".$targetfile."'.",
$this->ilias->error_obj->MESSAGE);
}
else
{
// preserve time stamp
touch($targetfile, filectime($sourcefile));
}
}
}
$tmpfile = ilUtil::ilTempnam();
$tmpzipfile = $tmpfile . ".zip";
// Safe mode fix
$zipcmd = $zip." -r ".ilUtil::escapeShellArg($tmpzipfile)." .";
exec($zipcmd);
ilUtil::delDir($tmpdir);
$exerciseTitle = $ilObjDataCache->lookupTitle($this->getObjId());
ilUtil::deliverFile($tmpzipfile, (strlen($exerciseTitle) == 0? strtolower($lng->txt("excs")) : $exerciseTitle). ".zip");
chdir($cdir);
unlink($tmpfile);
unlink($tmpzipfile);
}

+ Here is the call graph for this function:

ilFileDataExercise::getAbsolutePath (   $a_path)

get absolute path of filename

Parameters
stringrelative path public
Returns
string absolute path

Definition at line 354 of file class.ilFileDataExercise.php.

Referenced by storeContentAsFile().

{
return $this->exercise_path.'/'.$this->obj_id.'_'.$a_path;
}

+ Here is the caller graph for this function:

ilFileDataExercise::getExercisePath ( )

get exercise path public

Returns
string path

Definition at line 62 of file class.ilFileDataExercise.php.

References $exercise_path.

Referenced by __checkPath(), delete(), downloadAllDeliveredFiles(), ilClone(), and storeUploadedFile().

{
}

+ Here is the caller graph for this function:

ilFileDataExercise::getFiles ( )

Definition at line 67 of file class.ilFileDataExercise.php.

References $file, $obj_id, $rest, and ilFormat\formatDate().

Referenced by delete(), and ilClone().

{
$files = array();
$dp = opendir($this->exercise_path);
while($file = readdir($dp))
{
if(is_dir($file))
{
continue;
}
list($obj_id,$rest) = split('_',$file,2);
if($obj_id == $this->obj_id)
{
if(!is_dir($this->exercise_path.'/'.$file))
{
$files[] = array(
'name' => $rest,
'size' => filesize($this->exercise_path.'/'.$file),
'ctime' => ilFormat::formatDate(date('Y-m-d H:i:s',filectime($this->exercise_path.'/'.$file))),
'fullpath' => $this->exercise_path.'/'.$file);
}
}
}
closedir($dp);
return $files;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilFileDataExercise::getObjId ( )

Definition at line 52 of file class.ilFileDataExercise.php.

References $obj_id.

Referenced by downloadAllDeliveredFiles().

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilFileDataExercise::ilClone (   $a_new_obj_id)

Definition at line 95 of file class.ilFileDataExercise.php.

References $file, getExercisePath(), and getFiles().

{
foreach($this->getFiles() as $file)
{
@copy($this->getExercisePath()."/".$this->obj_id.'_'.$file["name"],
$this->getExercisePath()."/".$a_new_obj_id.'_'.$file["name"]);
}
return true;
}

+ Here is the call graph for this function:

ilFileDataExercise::ilFileDataExercise (   $a_obj_id = 0)

Constructor call base constructors checks if directory is writable and sets the optional obj_id.

Parameters
integeregerobj_id public

Definition at line 37 of file class.ilFileDataExercise.php.

References __checkPath(), __initDirectory(), ilFileData\getPath(), and ilFileData\ilFileData().

{
die ("ilFileDataExercise is deprecated.");
define('EXERCISE_PATH','exercise');
$this->exercise_path = parent::getPath()."/".EXERCISE_PATH;
// IF DIRECTORY ISN'T CREATED CREATE IT
if(!$this->__checkPath())
{
$this->__initDirectory();
}
$this->obj_id = $a_obj_id;
}

+ Here is the call graph for this function:

ilFileDataExercise::storeContentAsFile (   $filename,
  $content,
  $secure_filename = false 
)

store content as file in filesystem

Parameters
$filenameFilename
$contentbase64 decoded content public
Returns
bool

Definition at line 172 of file class.ilFileDataExercise.php.

References $filename, __rotateFiles(), getAbsolutePath(), and ilUtil\virusHandling().

{
// TODO:
// CHECK UPLOAD LIMIT
//
if ($secure_filename)
{
// replace whitespaces with underscores
$filename = preg_replace("/\s/", "_", $filename);
// remove all special characters
$filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
}
if(count($content) > 0 )
{
// CHECK IF FILE WITH SAME NAME EXISTS
file_put_contents($filename, $content);
// check for virus
if (!$vir[0] ||$vir[1] != "")
{
unlink($filename);
return false;
}
return true;
}
return false;
}

+ Here is the call graph for this function:

ilFileDataExercise::storeUploadedFile (   $a_http_post_file,
  $secure_filename = false,
  $is_unziped = false 
)

store uploaded file in filesystem

Parameters
arrayHTTP_POST_FILES
boolean$is_unzipedtrue if uploaded file is unziped from archive public
Returns
bool

Definition at line 128 of file class.ilFileDataExercise.php.

References $filename, __rotateFiles(), getExercisePath(), and ilUtil\moveUploadedFile().

{
// TODO:
// CHECK UPLOAD LIMIT
//
$filename = $a_http_post_file['name'];
if ($secure_filename)
{
// replace whitespaces with underscores
$filename = preg_replace("/\s/", "_", $filename);
// remove all special characters
$filename = preg_replace("/[^_a-zA-Z0-9\.]/", "", $filename);
}
if(isset($a_http_post_file) && $a_http_post_file['size'])
{
// CHECK IF FILE WITH SAME NAME EXISTS
$this->__rotateFiles($this->getExercisePath().'/'.$this->obj_id.'_'.$filename);
//move_uploaded_file($a_http_post_file['tmp_name'],$this->getExercisePath().'/'.$this->obj_id.'_'.
// $filename);
if (!$is_unziped)
{
ilUtil::moveUploadedFile($a_http_post_file['tmp_name'], $a_http_post_file['name'],
$this->getExercisePath().'/'.$this->obj_id.'_'.$filename);
}
else
{
// ######## Warning, there is no check whether the unziped files are virus free or not
rename($a_http_post_file['tmp_name'],
$this->getExercisePath().'/'.$this->obj_id.'_'.$filename);
}
}
return true;
}

+ Here is the call graph for this function:

ilFileDataExercise::unlinkFile (   $a_filename)

unlink one uploaded file expects a filename e.g 'foo'

Parameters
stringfilename to delete public
Returns
bool

Definition at line 341 of file class.ilFileDataExercise.php.

Referenced by delete(), and unlinkFiles().

{
if(file_exists($this->exercise_path.'/'.$this->obj_id.'_'.$a_filename))
{
return unlink($this->exercise_path.'/'.$this->obj_id.'_'.$a_filename);
}
}

+ Here is the caller graph for this function:

ilFileDataExercise::unlinkFiles (   $a_filenames)

unlink files: expects an array of filenames e.g.

array('foo','bar')

Parameters
arrayfilenames to delete public
Returns
string error message with filename that couldn't be deleted

Definition at line 321 of file class.ilFileDataExercise.php.

References $file, and unlinkFile().

{
if(is_array($a_filenames))
{
foreach($a_filenames as $file)
{
if(!$this->unlinkFile($file))
{
return $file;
}
}
}
return '';
}

+ Here is the call graph for this function:

Field Documentation

ilFileDataExercise::$exercise_path

Definition at line 28 of file class.ilFileDataExercise.php.

Referenced by getExercisePath().

ilFileDataExercise::$obj_id

Definition at line 21 of file class.ilFileDataExercise.php.

Referenced by getFiles(), and getObjId().


The documentation for this class was generated from the following file: