Source for file MED_FILE.phpclass
Documentation is available at MED_FILE.phpclass
* Class file MED_FILE.phpclass
* @project Open CSP-Management
* @author Peter Krebs (pk) <p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
require_once __OCSP_PHPINCPATH__.
"default_config/media.conf.phpinc";
require_once $GLOBALS['MED']['PHPINCPATH'].
"MED_TABLEOBJ.phpclass";
require_once $GLOBALS['PROJECT']['PHPINCPATH'].
'common/pcf_file.phpinc';
define("MEF_FILE_NOT_FOUND","FILE_NOT_FOUND");
* Handels medias which consists only of one single file
* @project Open CSP-Management
* @author Peter Krebs (pk) <p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @staticvar string $myTable
* fields in $this->myTable starts with
* @staticvar string $colPrevix
* @staticvar stirng $myClassSrcFile
* @param string $mimeType
function MED_FILE($aId=
0,$mimeType=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::MED_FILE($aId,$mimeType,$debug)</b> (".
get_class($this).
")</p>";
if (empty($mimeType)) $this->MEF_MIMETYPE=
"application/octet-stream";
else $this->MEF_MIMETYPE=
$mimeType;
if (!empty($s_name)) return $s_name;
// ###################################################################
// ###################################################################
* returns a field => value array
* @param bool $withoutNull null values are not added to the array
* @param bool $debug show debug info?
function getDBRow($withoutNull=
TRUE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::getDBRow($withoutNull,$debug)</b> (".
get_class($this).
")</p>";
foreach($this->myObjVars as $key) {
if (file_exists($GLOBALS['MED']['PHPINCPATH'].
strtoupper(get_class($this)).
".phpclass")) {
$this->setDBField("MEF_OBJCLASS",strtoupper(get_class($this)));
return parent::getDBRow($withoutNull,$debug);
* sets a database row to the object fields
* sets each key (=columname) value
* @param array $row the row form a select * from DBMS_TABLEOBJ::myTable
* @param bool $asPopulated set populateTS as if the object has been populated
function setDBRow($row,$asPopulated=
TRUE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::setDBRow($row,$asPopulated,$debug)</b> (".
get_class($this).
")</p><blockquote>";
if (parent::setDBRow($row,$asPopulated,$debug)) {
if (!empty($this->MEF_OBJVARS)) {
foreach($arr as $key =>
$objVar) {
if ($debug) echo
"</blockquote>";
if ($debug) echo
"<p>RETURNS FALSE</blockquote>";
function dbInsert($gDBIDX=
"USRDB",$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::dbInsert()</b> (".
get_class($this).
")</p>";
if (empty($this->MEF_UPLHOST)) $this->setDBField("MEF_UPLHOST",$_SERVER['REMOTE_ADDR']);
$this->setDBField("MEF_UPLTIME",$GLOBALS[$gDBIDX]->quickQuery("SELECT NOW()",0));
return parent::dbInsert($gDBIDX,$debug);
* if $backupData is true the file is not deleted
* and remains in the category directory.
* @param boolean $backupData
function dbDelete($gDBIDX=
"USRDB",$backupData=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::dbDelete(...)</b> (".
get_class($this).
")</p>";
if (parent::dbDelete($gDBIDX,$backupData,$debug)) {
if ($debug) echo
"<p>unlink ".
$this->MEF_FILE.
"</p>";
* sets post array with form checks
* @param DBMS_FORM $frmObj a formObj as ref
* @param array $dbVal array with data
if ($debug) echo
"<hr><p><b>MED_FILE::setFORMPOST($frmObj,$dbval,$debug)</b> (".
get_class($this).
")</p>";
if ($debug) echo
"<blockquote>";
$this->MEF_ID=
intval($dbval['MEF_ID']);
$this->MEC_ID=
intval($dbval['MEC_ID']);
if ($debug) echo
"</blockquote>";
if (empty($dbval['MEF_FILE'])) {
return parent::setFORMPOST($frmObj,$dbval,$debug);
* returns a database form
* @param int $mode dbms form show mode
* @param string $frmName dbms form name
function &dbGetForm($mode,$frmName=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::dbGetForm($mode,$frmName)</b> (".
get_class($this).
")</p>\n";
if ($frmObj=
parent::dbGetForm($mode,$frmName,$debug)) {
$fld=
&$frmObj->addNoDbField("CHKCLASS","Anzeigeklasse �berpr�fen",DBMS_FLDTYPE_CHECKBOX,DBMS_NO_DBFIELD);
// ###################################################################
// ###################################################################
* returns the file name (used for downloads,online views ...)
if (!empty($s_name)) return $s_name;
if (!empty($s_name)) return $s_name;
* returns the absolute system file path
if (empty($s_fileName)) {
if (file_exists($GLOBALS['PROJECT']['PATH'].
"/".
$s_fileName)) return $GLOBALS['PROJECT']['PATH'].
"/".
$s_fileName;
if (file_exists($_SERVER['DOCUMENTROOT'].
"/".
$s_fileName)) return $_SERVER['DOCUMENTROOT'].
"/".
$s_fileName;
require_once($GLOBALS['PROJECT']['PHPINCPATH'].
"common/pcf_templates.phpinc");
if (file_exists($s_medPath.
"/".
$s_fileName)) return $s_medPath.
"/".
$s_fileName;
function setFile($aName,$isTmp=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_FILE::setFile($aName,$isTmp,$debug)</b> (".
get_class($this).
")</p>";
if (!$this->getCategory($debug)) { // to make sure category is populated
echo
"could not get category";
if ($debug) echo
"<blockquote><p>FILE NOT FOUND: $aName -> $file</p></blockquote>";
* moves the file from a source on the server to the category dir
* returns the full path to the file
* @param bool $link link the file instead of moving
if ($debug) echo
"<p><b>MED_FILE::setFileFromSource($source,overwrite=$overwrite,link=$link,$debug)</b> (".
get_class($this).
")</p><blockquote>";
if ($debug) echo
"<p>SOURCE FOUND</p>";
if (!$this->getCategory($debug)) { // to make sure category is populated
echo
"could not get category";
// first get the file name
$dDir=
$this->getCatRootDir($debug); // now we also have set $this->myCategory :-)
$dest=
$dDir.
"/".
$this->myCategory->getNewFileName($this->MEF_NAME);
$dest=
$dDir.
"/".
$this->myCategory->getNewFileName($this->MEF_NAME);
$dest=
$dDir.
"/".
$this->MEF_FILE;
if ($debug) echo
"<p>DEST: $dest</p>";
if (pcf_flieLink($source,$dest,$debug)) {
if ($debug) echo
"<p>FILE $source linked to $dest</p>";
$this->setDBField("MEF_UPLUSR",$_SESSION['USER_ID']);
if (empty($this->MEF_UPLTIME)) $this->setDBField("MEF_UPLTIME",$GLOBALS['USRDB']->qs_getNowStmt());
$this->setDBField("MEF_UPLHOST",$_SERVER['REMOTE_ADDR']);
if ($this->setFile($dest,$debug)) {
if ($debug) echo
"<p>FILE $source moved to $dest</p>";
if ($debug) echo
"<p>NOTHING DONE WITH: $source</p>";
if ($debug) echo
"<p>FILE NOT FOUND</p>";
* sets the file values from a php $_FILES array by
* setting MEF_NAME and calling setFileFromSource() and finaly
* calling setMIMEfromExtension
* @note class is not changed according to the mimetype of
* the uploaded file please call chkObjectClass afterwords
* to ensure that you work with the right class
* @param boolean $overwrite
if ($debug) echo
"<p><b>MED_FILE::setFileFromUpload(...)</b> (".
get_class($this).
")</p><blockquote><pre>".
print_r($uplFile).
"</pre>";
$this->MEF_NAME=
basename($uplFile['name']);
$this->MEF_FILE=
basename($uplFile['name']);
$asLink=
FALSE; // do not link temp files !!
if ($debug) echo
"</blockquote>";
* creates a zip file from the file
* @returns string zip file path
require_once $GLOBALS['PROJECT']['PHPINCPATH'].
'common/pcf_directory.phpinc';
$cmd=
$GLOBALS['OCSP_MED']['ZIP']['CMD'].
" ".
$GLOBALS['OCSP_MED']['ZIP']['ARGS'];
* echos the file with header information to force browser
* @param boolean $checkRights check if user has rights
$b_canDownload=
TRUE;$s_errMsg=
"";
$s_errMsg=
"Sie sind nicht berechtigt diese Datei herunter zu laden.";
$s_errMsg=
"Fehler: Datei nicht gefunden!";
echo
"<html><script type=\"text/javascript\" language=\"javascript\"><--\n";
echo
"alert('".
$s_errMsg.
"');\n";
echo
"if (history.length) {history.back()}\nelse {self.close()}\n";
echo
"//--></script></html>";
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
if (($ziped) &&
($fPath=
$this->createZip())) {
header("Content-Type: application/zip");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Transfer-Encoding: binary");
$user_agent =
strtolower ($_SERVER["HTTP_USER_AGENT"]);
header( "Content-Disposition: filename=".
$fName);
header( "Content-Disposition: attachment; filename=".
$fName);
$fp=
fopen($s_filePath, "rb");
* sets header and passthru the file
* @param bool $checkRights check if user has rights
$s_errMsg=
"Sie sind nicht berechtigt diese Datei herunter zu laden.";
$s_errMsg=
"Datei nicht gefunden!";
echo
"<html><head><title>Fehler</title><script type=\"text/javascript\" language=\"javascript\">\n<--\n";
echo
"alert('Fehler: ".
$s_errMsg.
"');\n";
echo
"if (history.length) {history.back()}\nelse {self.close()}\n";
echo
"//-->\n</script></head><body><h1 align=\"center\">Fehler: <br />".
$s_errMsg.
"</h1></html>";
$fp=
fopen($s_filePath, "rb");
* gets the html list tag representing the file
* @version pk-06-11-13 use $this->getMyLink()
$ret =
"<a href=\"".
$this->getMyLink().
"\" target=\"_blank\">";
* retuns the link url to the file
return $GLOBALS['OCSP_MED']['CMS_WEBROOT'].
"getfile.php?MEF_ID=".
$this->getId();
* returns the download url of the file
return $GLOBALS['MED']['CMS_WEBROOT'].
"download.php?MEF_ID=".
$this->getId().
($asZip ?
"&ASZIP=1" :
"");
* returns the filesize of the media file
// ###################################################################
// ###################################################################
* gets the mime type string from T_MED_MIMETYPES
* if no mimetype is set 'application/octet-stream'
// if (!empty($this->MEF_MIMETYPE)) return $this->MEF_MIMETYPE;
$query=
"SELECT * FROM T_MED_MIMETYPES WHERE MIM_ID=".
intval($this->MIM_ID);
if ($mime=
$GLOBALS[$this->get_gDBIDX()]->quickQuery($query)) {
return $mime['MIM_MIMETYPE'];
return "application/octet-stream";
* tries to get mimetype from file extension
if ($debug) echo
"<p><b>MED_FILE::setMIMEfromExtension($aName,$debug)</b> (".
get_class($this).
")</p><blockquote>";
if (is_array($fa)) $ext=
$fa[sizeof($fa)-
1]; // just the last elem in the array
$query=
"SELECT MIM_ID,MIM_MIMETYPE FROM T_MED_MIMETYPES WHERE MIM_EXTENSIONS LIKE ".
$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue("%".
$ext.
"%");
if ($debug) echo
"<p>$query</p>";
if (!empty($ext) &&
($type=
$GLOBALS[$this->get_gDBIDX()]->quickQuery($query))) {
$this->MIM_ID=
$type['MIM_ID'];
$this->MEF_MIMETYPE=
$type['MEF_MIMETYPE'];
$this->MIM_ID=
intval($this->MIM_ID);
if ($debug) echo
"<p>TYPE: ".
$this->MIM_ID.
"</p></blockquote>";
* checks if the current class is the best for the mimetype
* if not a new object is returned with the class from the mime table
echo
"<p><b>MED_FILE::chkObjectClass($debug)</b> (".
get_class($this).
")</p>";
if (!intval($this->MIM_ID)) return $this;
$query=
"SELECT MIM_OBJCLASS FROM T_MED_MIMETYPES WHERE MIM_ID=".
intval($this->MIM_ID);
if ($debug) {echo
"<blockquote><p>$query</p></blockquote>"; }
if ($objClass=
$GLOBALS[$this->get_gDBIDX()]->quickQuery($query,0,0)) {
if ($debug) echo
"<blockquote><p>$objClass -- ".
strtoupper(get_class($this)).
"</p></blockquote>";
if (!empty($GLOBALS['MED']['OBJECTCLASS'][$objClass]['CLASSFILE'])) {
require_once $GLOBALS['MED']['OBJECTCLASS'][$objClass]['CLASSFILE'];
$cmd=
"\$obj=new $objClass();";
if ($debug) echo
"<blockquote><pre>$cmd</pre></blockquote>";
// ###################################################################
// ###################################################################
* returns if the current user can open the file
$this->getCategory(); // ensure $this->myCategory is set
Documentation generated on Thu, 08 Jan 2009 17:44:55 +0100 by phpDocumentor 1.4.0a2