Source for file MED_FILE.phpclass

Documentation is available at MED_FILE.phpclass

  1. <?php
  2. /**
  3.   * Class file MED_FILE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    media
  7.   *
  8.   * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  9.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @since pk-03-12-18
  13.   *
  14.   ***/
  15.  
  16. require_once __OCSP_PHPINCPATH__."default_config/media.conf.phpinc";
  17. require_once $GLOBALS['MED']['PHPINCPATH']."MED_TABLEOBJ.phpclass";
  18.  
  19. require_once $GLOBALS['PROJECT']['PHPINCPATH'].'common/pcf_file.phpinc';
  20.  
  21. define("MEF_FILE_NOT_FOUND","FILE_NOT_FOUND");
  22.  
  23. /**
  24.   * Class MED_FILE
  25.   *
  26.   * Handels medias which consists only of one single file
  27.   *
  28.   * @project    Open CSP-Management
  29.   * @package    media
  30.   *
  31.   * @author     Peter Krebs (pk) <p.krebs@lvus.at>
  32.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  33.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  34.   *
  35.   * @since pk-03-12-18
  36.   *
  37.   ***/
  38. class MED_FILE extends MED_TABLEOBJ {
  39.     /**
  40.       * name of the db table
  41.       * @staticvar string $myTable 
  42.       ***/
  43.     var $myTable ="T_MED_FILES";
  44.     /**
  45.       * fields in $this->myTable starts with
  46.       * @staticvar string $colPrevix 
  47.       ***/
  48.     var $colPrevix = "MEF_";
  49.  
  50.     /**
  51.       * @staticvar stirng $myClassSrcFile 
  52.       * @since pk-05-09-13
  53.       ***/
  54.     var $myClassSrcFile=__FILE__;
  55.  
  56.     /**
  57.       * @param int  $aId 
  58.       * @param string $mimeType 
  59.       * @param bool $debug 
  60.       *
  61.       ***/
  62.     function MED_FILE($aId=0,$mimeType="",$debug=FALSE{
  63.         if ($debugecho "<p><b>MED_FILE::MED_FILE($aId,$mimeType,$debug)</b> (".get_class($this).")</p>";
  64.         $this->init();
  65.         if (empty($mimeType)) $this->MEF_MIMETYPE="application/octet-stream";
  66.         else $this->MEF_MIMETYPE=$mimeType;
  67.         if (intval($aId)) {
  68.             $this->db_SetKey($this->colPrevix."ID",$aId);
  69.             $this->dbPopulate($debug);
  70.         }
  71.     }
  72.  
  73.     /**
  74.       * @returns int
  75.       ***/
  76.     function getId({
  77.         return intval($this->getDBField('MEF_ID'));
  78.     }
  79.  
  80.     /**
  81.       * @returns int
  82.       * @since pk-06-11-13
  83.       ***/
  84.     function getStateId({
  85.         return intval($this->getDBField('MEF_STATE'));
  86.     }
  87.  
  88.     /**
  89.       * @returns string
  90.       * @since pk-06-11-13
  91.       ***/
  92.     function getTitle({
  93.         $s_name=$this->getDBField('MEF_NAME');
  94.         if (!empty($s_name)) return $s_name;
  95.         return basename($this->getDBField('MEF_FILE'));
  96.     }
  97.  
  98.     // ###################################################################
  99.     // data manipulation
  100.     // ###################################################################
  101.  
  102.     /**
  103.       * returns a field => value array
  104.       *
  105.       * @param bool $withoutNull  null values are not added to the array
  106.       * @param bool $debug        show debug info?
  107.       *
  108.       * @return array 
  109.       *
  110.       ***/
  111.     function getDBRow($withoutNull=TRUE,$debug=FALSE{
  112.         if ($debugecho "<p><b>MED_FILE::getDBRow($withoutNull,$debug)</b> (".get_class($this).")</p>";
  113.         $objArr=array();
  114.         if (is_array($this->myObjVars)) {
  115.             foreach($this->myObjVars as $key{
  116.                 $objArr[$key]=serialize($this->{$key});
  117.             }
  118.         }
  119.         if (file_exists($GLOBALS['MED']['PHPINCPATH'].strtoupper(get_class($this)).".phpclass")) {
  120.             $this->setDBField("MEF_OBJCLASS",strtoupper(get_class($this)));
  121.         }
  122.         $this->setDBField("MEF_OBJVARS",serialize($objArr));
  123.         return parent::getDBRow($withoutNull,$debug);
  124.     }
  125.  
  126.     /**
  127.       * sets a database row to the object fields
  128.       *
  129.       * sets each key (=columname) value
  130.       *
  131.       * @param  array $row            the row form a select * from DBMS_TABLEOBJ::myTable
  132.       * @param  bool $asPopulated    set populateTS as if the object has been populated
  133.       * @param  bool $debug 
  134.       *
  135.       * @return bool 
  136.       *
  137.       ***/
  138.     function setDBRow($row,$asPopulated=TRUE,$debug=FALSE{
  139.         if ($debugecho "<p><b>MED_FILE::setDBRow($row,$asPopulated,$debug)</b> (".get_class($this).")</p><blockquote>";
  140.         if (parent::setDBRow($row,$asPopulated,$debug)) {
  141.             if (!empty($this->MEF_OBJVARS)) {
  142.                 $arr=unserialize($this->MEF_OBJVARS);
  143.                 if (is_array($arr)) {
  144.                     foreach($arr as $key => $objVar{
  145.                         $this->{$key}=unserialize($objVar);
  146.                     }
  147.                 }
  148.             }
  149.             if ($debugecho "</blockquote>";
  150.             return TRUE;
  151.         }
  152.         if ($debugecho "<p>RETURNS FALSE</blockquote>";
  153.         return FALSE;
  154.     }
  155.  
  156.     /**
  157.       * inserts a new file
  158.       *
  159.       * @param string $gDBIDX 
  160.       * @param boolean $debug 
  161.       *
  162.       * @return int 
  163.       *
  164.       * @since pk-05-09-13
  165.       *
  166.       ***/
  167.     function dbInsert($gDBIDX="USRDB",$debug=FALSE{
  168.         if ($debugecho "<p><b>MED_FILE::dbInsert()</b> (".get_class($this).")</p>";
  169.  
  170.         if (!intval($this->MEF_UPLUSR))  $this->setDBField("MEF_UPLUSR",$GLOBALS['USER']->getId());
  171.         if (empty($this->MEF_UPLHOST))   $this->setDBField("MEF_UPLHOST",$_SERVER['REMOTE_ADDR']);
  172.         if (!intval($this->MEF_UPLPROJ)) $this->setDBField("MEF_UPLPROJ",intval($_GET['PROJ_ID']));
  173.         $this->setDBField("MEF_UPLTIME",$GLOBALS[$gDBIDX]->quickQuery("SELECT NOW()",0));
  174.  
  175.         return parent::dbInsert($gDBIDX,$debug);
  176.     }
  177.  
  178.     /**
  179.       * deletes the file
  180.       *
  181.       * if $backupData is true the file is not deleted
  182.       * and remains in the category directory.
  183.       *
  184.       * @param string $gDBIDX 
  185.       * @param boolean $backupData 
  186.       * @param boolean $debug 
  187.       *
  188.       * @return boolean 
  189.       *
  190.       * @since pk-05-04-29
  191.       *
  192.       ***/
  193.     function dbDelete($gDBIDX="USRDB",$backupData=FALSE,$debug=FALSE{
  194.         if ($debugecho "<p><b>MED_FILE::dbDelete(...)</b> (".get_class($this).")</p>";
  195.  
  196.         if (parent::dbDelete($gDBIDX,$backupData,$debug)) {
  197.             if (!$backupData{
  198.                 if ($debugecho "<p>unlink ".$this->MEF_FILE."</p>";
  199.                 unlink($this->MEF_FILE);
  200.             }
  201.         }
  202.     }
  203.  
  204.     /**
  205.       * sets post array with form checks
  206.       *
  207.       * @param  DBMS_FORM $frmObj      a formObj as ref
  208.       * @param  array     $dbVal       array with data
  209.       * @param  bool      $debug 
  210.       *
  211.       * @return bool 
  212.       *
  213.       * @version pk-03-12-13
  214.       *
  215.       ***/
  216.     function setFORMPOST(&$frmObj,$dbval,$debug=FALSE{
  217.         if ($debugecho "<hr><p><b>MED_FILE::setFORMPOST($frmObj,$dbval,$debug)</b> (".get_class($this).")</p>";
  218.         if (intval($dbval['MEF_ID']&& (!$this->isPopulated())) {
  219.             if ($debugecho "<blockquote>";
  220.             $this->MEF_ID=intval($dbval['MEF_ID']);
  221.             $this->MEC_ID=intval($dbval['MEC_ID']);
  222.             $this->dbPopulate();
  223.             if ($debugecho "</blockquote>";
  224.         }
  225.         if (empty($dbval['MEF_FILE'])) {
  226.             $dbval['MEF_FILE']=MEF_FILE_NOT_FOUND;
  227.         }
  228.         return parent::setFORMPOST($frmObj,$dbval,$debug);
  229.     }
  230.  
  231.     /**
  232.       * returns a database form
  233.       *
  234.       * @param int    $mode       dbms form show mode
  235.       * @param string $frmName    dbms form name
  236.       * @param boolean $debug 
  237.       *
  238.       * @return DBMS_FORM 
  239.       *
  240.       ***/
  241.     function &dbGetForm($mode,$frmName="",$debug=FALSE)  {
  242.         if ($debugecho "<p><b>MED_FILE::dbGetForm($mode,$frmName)</b> (".get_class($this).")</p>\n";
  243.         if ($frmObj=parent::dbGetForm($mode,$frmName,$debug)) {
  244.             if ($mode==FRM_MODE_NEW{
  245.                if (!$frmObj->fieldExists("CHKCLASS",DBMS_NO_DBFIELD)) {
  246.                     $fld=&$frmObj->addNoDbField("CHKCLASS","Anzeigeklasse ï¿½berpr�fen",DBMS_FLDTYPE_CHECKBOX,DBMS_NO_DBFIELD);
  247.                 }
  248.             }
  249.             return $frmObj;
  250.         else {
  251.             return FALSE;
  252.         }
  253.     }
  254.  
  255.     // ###################################################################
  256.     //  FILE METHODS
  257.     // ###################################################################
  258.  
  259.     /**
  260.       * returns the file name (used for downloads,online views ...)
  261.       *
  262.       * @returns string
  263.       *
  264.       * @since pk-07-02-08
  265.       *
  266.       ***/
  267.     function getFileName({
  268.         $s_name=$this->getDBField('MEF_ID');
  269.         if (!empty($s_name)) return $s_name;
  270.  
  271.         $s_name=$this->getFilePath();
  272.         if (!empty($s_name)) return $s_name;
  273.  
  274.         return MEF_FILE_NOT_FOUND;
  275.     }
  276.  
  277.  
  278.  
  279.     /**
  280.       * returns the absolute system file path
  281.       *
  282.       * @param boolean $debug 
  283.       *
  284.       * @returns string
  285.       *
  286.       * @since pk-07-02-08
  287.       *
  288.       *
  289.       ***/
  290.     function getFilePath($debug=FALSE{
  291.         if ($debugechoDebugMethod(__FILE__,get_class($this),"MED_FILE::getFilePath()");
  292.  
  293.         $s_fileName=$this->getDBField('MEF_FILE');
  294.         if (empty($s_fileName)) {
  295.             return NULL;
  296.         }
  297.  
  298.         if ((substr($s_fileName,0,1)=="/"&& file_exists($s_fileName)) {
  299.             // old style file
  300.             return $s_fileName;
  301.         }
  302.  
  303.         $s_dirPath=$this->getCatRootDir();
  304.         if (file_exists($s_dirPath.basename($s_fileName)))              return $s_dirPath.basename($s_fileName);
  305.         if (file_exists($s_dirPath.$s_fileName))                        return $s_dirPath.basename($s_fileName);
  306.  
  307.         if (file_exists($GLOBALS['PROJECT']['PATH']."/".$s_fileName))   return $GLOBALS['PROJECT']['PATH']."/".$s_fileName;
  308.         if (file_exists($_SERVER['DOCUMENTROOT']."/".$s_fileName))      return $_SERVER['DOCUMENTROOT']."/".$s_fileName;
  309.  
  310.         require_once($GLOBALS['PROJECT']['PHPINCPATH']."common/pcf_templates.phpinc");
  311.         $s_medPath=pcf_tmpl_parse($GLOBALS['OCSP_MED']['ROOTPATH'],$this->getDBRow());
  312.         if (file_exists($s_medPath."/".$s_fileName)) return $s_medPath."/".$s_fileName;
  313.  
  314.         if (file_exists($s_fileName)) return $s_fileName;
  315.         return NULL;
  316.  
  317.     }
  318.  
  319.     /**
  320.       * sets file with attribs
  321.       *
  322.       * @param string $aName 
  323.       * @param bool $isTmp 
  324.       * @param bool $debug 
  325.       *
  326.       ***/
  327.     function setFile($aName,$isTmp=FALSE,$debug=FALSE{
  328.         if ($debugecho "<p><b>MED_FILE::setFile($aName,$isTmp,$debug)</b>  (".get_class($this).")</p>";
  329.         if (!$isTmp{
  330.             if (!$this->getCategory($debug)) {      // to make sure category is populated
  331.                 echo "could not get category";
  332.                 die();
  333.             }
  334.             $file=$this->getCatRootDir().basename($aName);
  335.         else {
  336.             $file=$aName;
  337.         }
  338.         if (pcf_fileExists($file,$debug)) {
  339.             if (!$isTmp$this->setDBField("MEF_FILE",str_replace("//","",$file));
  340.             $this->setDBField("MEF_SIZE",pcf_fileSize($file,$debug));
  341.             $this->setMIMEfromExtension($aName,$debug);
  342.             return TRUE;
  343.         else {
  344.             if ($debugecho "<blockquote><p>FILE NOT FOUND$aName -> $file</p></blockquote>";
  345.             return FALSE;
  346.         }
  347.     }
  348.  
  349.     /**
  350.       * moves the file from a source on the server to the category dir
  351.       * returns the full path to the file
  352.       *
  353.       * @param string $source 
  354.       * @param bool $overwrite 
  355.       * @param bool $link           link the file instead of moving
  356.       * @param bool $debug 
  357.       *
  358.       * @return string 
  359.       *
  360.       ***/
  361.     function setFileFromSource($source,$overwrite=FALSE,$link=FALSE,$debug=FALSE{
  362.         if ($debugecho "<p><b>MED_FILE::setFileFromSource($source,overwrite=$overwrite,link=$link,$debug)</b> (".get_class($this).")</p><blockquote>";
  363.         if (pcf_fileExists($source,$debug)) {
  364.             if ($debugecho "<p>SOURCE FOUND</p>";
  365.  
  366.             if (!$this->getCategory($debug)) {      // to make sure category is populated
  367.                 echo "could not get category";
  368.                 die();
  369.             }
  370.  
  371.             // first get the file name
  372.             $dDir=$this->getCatRootDir($debug);     // now we also have set $this->myCategory :-)
  373.  
  374.             if ((empty($this->MEF_FILE)) || ($this->MEF_FILE==MEF_FILE_NOT_FOUND)) {
  375.                 $dest=$dDir."/".$this->myCategory->getNewFileName($this->MEF_NAME);
  376.             else if (pcf_fileExists($dDir."/".$this->MEF_FILE,$debug)) {
  377.                 if (!$overwrite{
  378.                     $dest=$dDir."/".$this->myCategory->getNewFileName($this->MEF_NAME);
  379.                 else {
  380.                     $dest=$dDir."/".$this->MEF_FILE;
  381.                 }
  382.             }
  383.             $dest=str_replace('//','/',$dest);
  384.  
  385.             if ($debugecho "<p>DEST$dest</p>";
  386.             if ($link{
  387.                 if (pcf_flieLink($source,$dest,$debug)) {
  388.                     $this->setDBField("MEF_FILE",$dest);
  389.                     if ($debugecho "<p>FILE $source linked to $dest</p>";
  390.                     return $dest;
  391.                 }
  392.             else if (pcf_fileMove($source,$dest,$debug)) {
  393.                 $this->setDBField("MEF_UPLUSR",$_SESSION['USER_ID']);
  394.                 if (empty($this->MEF_UPLTIME)) $this->setDBField("MEF_UPLTIME",$GLOBALS['USRDB']->qs_getNowStmt());
  395.                 $this->setDBField("MEF_UPLHOST",$_SERVER['REMOTE_ADDR']);
  396.                 if ($this->setFile($dest,$debug)) {
  397.                     if ($debugecho "<p>FILE $source moved to $dest</p>";
  398.                     $this->setDBField("MEF_FILE",$dest);
  399.                     return $dest;
  400.                 }
  401.                 return NULL;
  402.             }
  403.             if ($debugecho "<p>NOTHING DONE WITH$source</p>";
  404.         }
  405.         if ($debugecho "<p>FILE NOT FOUND</p>";
  406.         return NULL;
  407.     }
  408.     /**
  409.       * sets the file values from a php $_FILES array by
  410.       * setting MEF_NAME and calling setFileFromSource() and finaly
  411.       * calling setMIMEfromExtension
  412.       *
  413.       * @note class is not changed according to the mimetype of
  414.       *  the uploaded file please call chkObjectClass afterwords
  415.       *  to ensure that you work with the right class
  416.       *
  417.       * @param array $uplFile 
  418.       * @param boolean $overwrite 
  419.       * @param boolean $debug 
  420.       *
  421.       * @return string 
  422.       *
  423.       * @since pk-05-04-19
  424.       *
  425.       ***/
  426.     function setFileFromUpload($uplFile,$overwrite=FALSE,$debug=FALSE{
  427.         if ($debugecho "<p><b>MED_FILE::setFileFromUpload(...)</b> (".get_class($this).")</p><blockquote><pre>".print_r($uplFile)."</pre>";
  428.  
  429.         $this->MEF_NAME=basename($uplFile['name']);
  430.         $this->MEF_FILE=basename($uplFile['name']);
  431.         $asLink=FALSE// do not link temp files !!
  432.         $ret=$this->setFileFromSource($uplFile['tmp_name'],$overwrite,$asLink,$debug);
  433.         if (!empty($ret)) {
  434.             $this->setMIMEfromExtension($uplFile['name']);
  435.         }
  436.         if ($debugecho "</blockquote>";
  437.         return $ret;
  438.     }
  439.  
  440.  
  441.  
  442.     /**
  443.       * creates a zip file from the file
  444.       *
  445.       * @param string $dest 
  446.       * @param boolean $debug 
  447.       *
  448.       * @returns string zip file path
  449.       *
  450.       * @since pk-04-08-10
  451.       * @version pk-07-02-08
  452.       *
  453.       ***/
  454.     function createZip($dest="",$debug=FALSE{
  455.         if ($debugechoDebugMethod(__FILE__,get_class($this),"MED_FILE::createZip()",$dest);
  456.  
  457.         if (!($s_file=$this->getFilePath($debug))) {
  458.             return NULL;
  459.         }
  460.  
  461.         if (empty($dest)) {
  462.             $dest=$GLOBALS['OCSP_MED']['CACHE']."zip/".intval($this->getCatId()).str_replace(".","_",basename($s_file).".zip");
  463.         }
  464.  
  465.         require_once $GLOBALS['PROJECT']['PHPINCPATH'].'common/pcf_directory.phpinc';
  466.         pcf_checkDir(dirname($dest),TRUE);
  467.         if (file_exists($dest)) {
  468.             if (filemtime($destfilemtime($s_file)) {
  469.                 return $dest;
  470.             else {
  471.                 @unlink($dest);
  472.             }
  473.         }
  474.         $cmd=$GLOBALS['OCSP_MED']['ZIP']['CMD']." ".$GLOBALS['OCSP_MED']['ZIP']['ARGS'];
  475.         $cmd str_replace("$*SOURCE$",$s_file,$cmd);
  476.         $cmd str_replace("$*TARGET$",$dest,$cmd);
  477.  
  478.         system($cmd);
  479.         if (file_exists($dest)) {
  480.             return $dest;
  481.         else {
  482.             return NULL;
  483.         }
  484.     }
  485.  
  486.     /**
  487.       * echos the file with header information to force browser
  488.       * saving the file
  489.       *
  490.       * @param boolean $checkRights    check if user has rights
  491.       * @param boolean $ziped 
  492.       *
  493.       * @todo check rights
  494.       *
  495.       ***/
  496.     function sendHttpDownload($checkRights=FALSE,$ziped=FALSE{
  497.         $b_canDownload=TRUE;$s_errMsg="";
  498.  
  499.         if ($checkRights && !$this->curUserCanOpen()) {
  500.             $b_canDownload=FALSE;
  501.             $s_errMsg="Sie sind nicht berechtigt diese Datei herunter zu laden.";
  502.         }
  503.  
  504.         if (!$s_filePath=$this->getFilePath()) {
  505.             $b_canDownload=FALSE;
  506.             $s_errMsg="Fehler: Datei nicht gefunden!";
  507.         }
  508.  
  509.         if (!$b_canDownload{
  510.             echo "<html><script type=\"text/javascript\" language=\"javascript\"><--\n";
  511.             echo "alert('".$s_errMsg."');\n";
  512.             echo "if (history.length) {history.back()}\nelse {self.close()}\n";
  513.             echo "//--></script></html>";
  514.         }
  515.  
  516.         header("Pragma: public");
  517.         header("Expires: 0");
  518.         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  519.         header("Content-Type: application/force-download");
  520.         if (($ziped&& ($fPath=$this->createZip())) {
  521.             header("Content-Type: application/zip");
  522.             header("Content-Length: ".filesize($fPath));
  523.             $fName=basename($fPath);
  524.         else {
  525.             header("Content-Type: application/octet-stream");
  526.             header("Content-Length: ".$this->getFileSize());
  527.             $fName=$this->getFileName();
  528.         }
  529.         header("Content-Type: application/download");
  530.         header("Content-Transfer-Encoding: binary");
  531.         $user_agent strtolower ($_SERVER["HTTP_USER_AGENT"]);
  532.         if ((is_integer (strpos($user_agent"msie"))) && (is_integer (strpos($user_agent"win")))) {
  533.             header"Content-Disposition: filename=".$fName);
  534.         else {
  535.             header"Content-Disposition: attachment; filename=".$fName);
  536.         }
  537.         $fp=fopen($s_filePath"rb");
  538.         fpassthru($fp);
  539.         fclose($fp);
  540.         return TRUE;
  541.     }
  542.  
  543.     /**
  544.       * sets header and passthru the file
  545.       *
  546.       * @param bool $checkRights    check if user has rights
  547.       *
  548.       * @version pk-07-02-08
  549.       *
  550.       ***/
  551.     function sendHttpFile($checkRights=TRUE{
  552.  
  553.         $b_canDownload=TRUE;
  554.  
  555.         if ($checkRights && !$this->curUserCanOpen()) {
  556.             $b_canDownload=FALSE;
  557.             $s_errMsg="Sie sind nicht berechtigt diese Datei herunter zu laden.";
  558.         }
  559.  
  560.         if (!$s_filePath=$this->getFilePath()) {
  561.             $b_canDownload=FALSE;
  562.             $s_errMsg="Datei nicht gefunden!";
  563.         }
  564.  
  565.         if (!$b_canDownload{
  566.             echo "<html><head><title>Fehler</title><script type=\"text/javascript\" language=\"javascript\">\n<--\n";
  567.             echo "alert('Fehler: ".$s_errMsg."');\n";
  568.             echo "if (history.length) {history.back()}\nelse {self.close()}\n";
  569.             echo "//-->\n</script></head><body><h1 align=\"center\">Fehler: <br />".$s_errMsg."</h1></html>";
  570.             return FALSE;
  571.         else {
  572.             header ("Content-Type: ".$this->getMIMEType());
  573.             header ("Content-Disposition: filename=".$this->getFileName());
  574.             $fp=fopen($s_filePath"rb");
  575.             fpassthru($fp);
  576.             fclose($fp);
  577.             return TRUE;
  578.         }
  579.     }
  580.  
  581.     /**
  582.       * gets the html list tag representing the file
  583.       *
  584.       * @param array $argArr 
  585.       * @param boolean $debug 
  586.       *
  587.       * @returns string
  588.       *
  589.       * @since pk-04-08-10
  590.       * @version pk-06-11-13 use $this->getMyLink()
  591.       *
  592.       ***/
  593.     function getHTMLListTag($argArr=NULL,$debug=FALSE{
  594.         if ($debugechoDebugMethod(__FILE__,get_class($this),"MED_FILE::getHTMLListTag()",print_r($argArr,TRUE)."</pre></blockquote>...)");
  595.  
  596.         $ret ="<a href=\"".$this->getMyLink()."\" target=\"_blank\">";
  597.         $ret.=$this->MEF_NAME;
  598.         $ret.="</a>";
  599.  
  600.         return $ret;
  601.     }
  602.  
  603.     /**
  604.       * retuns the link url to the file
  605.       *
  606.       * @returns string
  607.       *
  608.       * @since pk-06-11-13
  609.       *
  610.       ***/
  611.     function getMyLink({
  612.         return $GLOBALS['OCSP_MED']['CMS_WEBROOT']."getfile.php?MEF_ID=".$this->getId();
  613.     }
  614.  
  615.     /**
  616.       * returns the download url of the file
  617.       *
  618.       * @param boolean $asZip 
  619.       *
  620.       * @returns string
  621.       *
  622.       * @since pk-06-11-13
  623.       *
  624.       ***/
  625.     function getDownlaodLink($asZip{
  626.         return $GLOBALS['MED']['CMS_WEBROOT']."download.php?MEF_ID=".$this->getId().($asZip "&ASZIP=1" "");
  627.     }
  628.  
  629.     /**
  630.       * returns the filesize of the media file
  631.       *
  632.       * @param boolean $debug 
  633.       *
  634.       * @returns int
  635.       *
  636.       * @version pk-07-02-09
  637.       *
  638.       ***/
  639.     function getFileSize($debug=FALSE{
  640.         return pcf_fileSize($this->getFilePath(),$debug);
  641.     }
  642.  
  643.     // ###################################################################
  644.     // MIME-TYPE METHODS
  645.     // ###################################################################
  646.  
  647.     /**
  648.       * sets dem MIME-Type Id
  649.       *
  650.       * @param int $aTypeId 
  651.       *
  652.       ***/
  653.     function setMIMEType($aTypeId{
  654.         $this->setDBField("MIM_ID",$aTypeId);
  655.         $this->setDBField("MEF_MIMETYPE",$this->getMIMEType());
  656.     }
  657.  
  658.     /**
  659.       * gets the mime type string from T_MED_MIMETYPES
  660.       * if no mimetype is set 'application/octet-stream'
  661.       * is returned
  662.       *
  663.       * @return string 
  664.       *
  665.       ***/
  666.     function getMIMEType({
  667.         // if (!empty($this->MEF_MIMETYPE)) return $this->MEF_MIMETYPE;
  668.         $query="SELECT * FROM T_MED_MIMETYPES WHERE MIM_ID=".intval($this->MIM_ID);
  669.         if ($mime=$GLOBALS[$this->get_gDBIDX()]->quickQuery($query)) {
  670.             return $mime['MIM_MIMETYPE'];
  671.         else {
  672.             return "application/octet-stream";
  673.         }
  674.     }
  675.     /**
  676.       * tries to get mimetype from file extension
  677.       *
  678.       * @param string $aName 
  679.       * @param bool $debug 
  680.       *
  681.       * @return int 
  682.       *
  683.       ***/
  684.     function setMIMEfromExtension($aName,$debug=FALSE{
  685.         if ($debugecho "<p><b>MED_FILE::setMIMEfromExtension($aName,$debug)</b> (".get_class($this).")</p><blockquote>";
  686.         $aName=basename($aName);
  687.         $fa=explode(".",$aName);
  688.         if (is_array($fa)) $ext=$fa[sizeof($fa)-1];  // just the last elem in the array
  689.         else $ext="";
  690.         $query="SELECT MIM_ID,MIM_MIMETYPE FROM T_MED_MIMETYPES WHERE MIM_EXTENSIONS LIKE ".$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue("%".$ext."%");
  691.         if ($debugecho "<p>$query</p>";
  692.         if (!empty($ext&& ($type=$GLOBALS[$this->get_gDBIDX()]->quickQuery($query))) {
  693.             $this->MIM_ID=$type['MIM_ID'];
  694.             $this->MEF_MIMETYPE=$type['MEF_MIMETYPE'];
  695.         else {
  696.             $this->MIM_ID=intval($this->MIM_ID);
  697.             $this->MEF_MIMETYPE=$this->getMIMEType();
  698.         }
  699.  
  700.         if ($debugecho "<p>TYPE: ".$this->MIM_ID."</p></blockquote>";
  701.     }
  702.  
  703.     /**
  704.       * checks if the current class is the best for the mimetype
  705.       * if not a new object is returned with the class from the mime table
  706.       *
  707.       * @return MED_FILE 
  708.       *
  709.       ***/
  710.     function &chkObjectClass($debug=FALSE{
  711.         if ($debug{
  712.             echo "<p><b>MED_FILE::chkObjectClass($debug)</b> (".get_class($this).")</p>";
  713.             echo "<blockquote><pre style=\"font-size: 8px;\">";echo htmlspecialchars(print_r($this->getDBRow(),TRUE));echo "</pre></blockquote>";
  714.         }
  715.  
  716.         if (!intval($this->MIM_ID)) return $this;
  717.  
  718.         $query="SELECT MIM_OBJCLASS FROM T_MED_MIMETYPES WHERE MIM_ID=".intval($this->MIM_ID);
  719.         if ($debug{echo "<blockquote><p>$query</p></blockquote>"}
  720.         if ($objClass=$GLOBALS[$this->get_gDBIDX()]->quickQuery($query,0,0)) {
  721.             if ($debugecho "<blockquote><p>$objClass -- ".strtoupper(get_class($this))."</p></blockquote>";
  722.             if ($objClass!=strtoupper(get_class($this))) {
  723.                 if (!empty($GLOBALS['MED']['OBJECTCLASS'][$objClass]['CLASSFILE'])) {
  724.                     require_once $GLOBALS['MED']['OBJECTCLASS'][$objClass]['CLASSFILE'];
  725.                     $cmd="\$obj=new $objClass();";
  726.                     if ($debugecho "<blockquote><pre>$cmd</pre></blockquote>";
  727.                     eval($cmd);
  728.                     if (is_object($obj)) {
  729.                         $obj->setDBRow($this->getDBRow(),($this->populateTS $this->valChangeTS TRUE FALSE),FALSE);    // no debugigng
  730.                         $obj->setDBField("MEF_OBJCLASS",$objClass);
  731.                         if ($debugecho "<blockquote><pre style=\"font-size: 8px;\">";echo htmlspecialchars(print_r($this->getDBRow(),TRUE));echo "</pre></blockquote>"}
  732.                         return $obj;
  733.                     }
  734.                 }
  735.             }
  736.         }
  737.         return $this;
  738.     }
  739.  
  740.     // ###################################################################
  741.     // RIGHT METHODS
  742.     // ###################################################################
  743.  
  744.     /**
  745.       * returns if the current user can open the file
  746.       *
  747.       * @param boolean $debug 
  748.       *
  749.       * @since pk-06-11-13
  750.       *
  751.       ***/
  752.     function curUserCanOpen($debug=FALSE{
  753.         if ($debugechoDebugMethod(__FILE__,get_class($this),"MED_FILE::curUserCanOpen()");
  754.  
  755.         if ($GLOBALS['USER']->getId()==$this->getDBField('MEF_UPLUSR')) {
  756.             // owner always can open
  757.             return TRUE;
  758.         }
  759.         $this->getCategory()// ensure $this->myCategory is set
  760.         return $this->myCategory->curUserCanOpen($debug);
  761.     }
  762.  
  763.  
  764. }
  765. ?>

Documentation generated on Thu, 08 Jan 2009 17:44:55 +0100 by phpDocumentor 1.4.0a2