Source for file MED_CATEGORY_NODE.phpclass
Documentation is available at MED_CATEGORY_NODE.phpclass
* Class file MED_CATEGORY_NODE.phpclass
* @project Open CSP-Management
* @category category-tree
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: MED_CATEGORY_NODE.phpclass,v 1.3 2008/06/27 13:59:23 pitlinz Exp $
require_once __OCSP_PHPINCPATH__.
"default_config" .
_OCSP_DIRSEP_ .
"media.conf.phpinc";
require_once __OCSP_PHPINCPATH__.
'common/pcf_file.phpinc';
require_once __OCSP_PHPINCPATH__.
'common/pcf_directory.phpinc';
require_once __OCSP_PHPINCPATH__.
'db/DBMS_TREE_NODE.phpclass';
require_once __OCSP_PHPINCPATH__.
"media/MED_MIMETYPE.phpclass";
* media category tree node
* @project Open CSP-Management
* @category category-tree
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: MED_CATEGORY_NODE.phpclass,v 1.3 2008/06/27 13:59:23 pitlinz Exp $
* @var string $myGlobalTreeKey index in $GLOABLS['DBMS_TREE'][]
* @staticvar string $myTable
* @staticvar string $myIdFld id column = root
* @staticvar string $myParentFld name of the parent column
* @staticvar string $mySortFld name of the sort field
* @var string $myChildClass
* @var double $hasChildrenToShowTS
* @var boolean $offPath the category dir is not under $GLOBALS['MEDIA']['ROOTPATH']
* @var int $projId CMS_PROJECT (-1 == all)
* @var boolean $addDefaultProj show project and default project (PROJ_ID=0)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @param int $aId id of the node (if set the node is poplulated)
* @param string $dDBIDX index of the database connection in $GLOBALS
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::MED_CATEGORY_NODE($aId,$debug)</b> (".
get_class($this).
")</p>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// object var access methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns if we have set a projId
if ($this->projId > -
1) return TRUE;
* @param boolean $onOff on TRUE off =FALSE
* @param &DBMS_TREE_NODE $child
$child->set_projId($this->projId);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// database access methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* inserts a new category and creates the category directory
* @param string $gDBIDX Index of $GLOBALS to the db object
* @param bool $debug show debug info
* @return int returns the autoIncFld ID if exists or 1 on success
echo
"<hr><p><b>MED_CATEGORY_NODE::dbInsert($gDBIDX,$debug)</b></p>";
$this->MEC_PATH=
trim($this->MEC_PATH);
if (($this->MEC_PATH==
trim($GLOBALS['MED']['ROOTPATH'])) ||
($this->MEC_PATH==
"/")) {
if (!$GLOBALS['MED']['ALLOW_ROOTPATH']) {
if ((!empty($this->MEC_PATH)) &&
(is_dir($this->MEC_PATH)) &&
(!strstr($this->MEC_PATH,$GLOBALS['MED']['ROOTPATH']))) {
if ($this->MEC_ID=
parent::dbInsert($debug)) { // insert row and set id
if ((!empty($this->MEC_PATH)) &&
(is_dir($this->getRootDir($debug)))) { // we already have a valid category directory
if (empty($this->MEC_WEBDIR)) { // we need to update the webpath
if (strstr($this->MEC_PATH,$_SERVER['DOCUMENT_ROOT'])) { // path is in DOCUMENT_ROOT direct access possible
$this->MEC_WEBDIR=
str_replace($_SERVER['DOCUMENT_ROOT'],"",$this->MEC_PATH);
$this->dbReplace($gDBIDX,$debug); // update database values
} else if ($GLOBALS['MED']['WEBDIR']) {
$this->MEC_WEBDIR=
$GLOBALS['MED']['WEBDIR'].
$this->getId().
"/";
$this->dbReplace($debug); // update database values
if (!$this->offPath ||
empty($this->MEC_PATH)) { // <pk-05-10-13>
if ($debug) echo
"<blockquote>MEC_PATH: $path</blockquote>";
$this->MEC_PATH=
str_replace($GLOBALS['PROJECT']['PATH'],"\$@PROJECT|PATH\$",$path.
"/"); // </pk-05-10-13>
if ($GLOBALS['MED']['WEBDIR']) {
$this->MEC_WEBDIR=
$GLOBALS['MED']['WEBDIR'].
$this->getId().
"/";
$GLOBALS[$gDBIDX]->executeCmd($cmd);
* echos a tree intend called by write children
if ($debug) echo
"<p><b>DBMS_TREE_NODE::getChildQueryString($cols)</b> (".
get_class($this).
")</p>\n";
$query =
"SELECT ".
$cols.
" FROM ".
$this->myTable;
$query.=
" WHERE ".
$this->myParentFld.
"=".
$this->getId(); // IDs are integer COLUMNS and VALUES
foreach($keyCols as $kcol) {
$query.=
" AND ".
$kcol.
" = ".
$GLOBALS[$this->gDBIDX]->qs_getSlashedValue($this->getKey($kcol));
$s_query.=
" OR PROJ_ID=0";
echo
"<tr><td><table width='90%' align='right' border='0'>";
$GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$id]->writeTableRowThis($debug);
$GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$id]->writeTableRowChildren($expandLevel-
1,$useCache,$debug);
echo
"</table></td></tr>";
if ($debug) echo
"<blockquote><p>ChildQuery: <br /><nobr>$query</nobr></p></blockquote>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns if the current user can open the category
* (is group member of MEC_DWNLGRP or has higher rights)
} else if ($GLOBALS['USER']->isGroupMember(intval($this->getDBField('MEC_DWNLGRP')))) {
* returns if the current user can upload a file to the category
* (is group member of MEC_UPLOADGRP or has higher rights)
} else if ($GLOBALS['USER']->isGroupMember(intval($this->getDBField('MEC_UPLOADGRP')))) {
* returns if the current user is admin of the category
* (is group member of MEC_ADMINGRP or has higher rights)
return ($GLOBALS['USER']->isGroupMember(intval($this->getDBField('MEC_ADMINGRP'))));
* returns if current user can add subcategories or files (checks MEC_UPLOADGRP)
if ($GLOBALS['USER']->isAdmin()) return TRUE;
if ($GLOBALS['USER']->isGroupMember($this->MEC_ADMINGRP)) return TRUE;
if ($GLOBALS['USER']->isGroupMember($this->MEC_UPLOADGRP)) return TRUE;
if (intval($this->PROJ_ID) &&
($GLOBALS['USER']->isProjectAdmin($this->PROJ_ID))) return TRUE;
// #############################################
// #############################################
* returns the state id of the node (MEC_STATE)
* checks if the node is on
* @param boolean $checkState
* @param boolean $checkDate
* @param boolean $checkGroup
function isToShow($checkState=
TRUE,$checkDate=
TRUE,$checkGroup=
TRUE,$debug=
FALSE) {
if (!$GLOBALS['OCSP_MED']['CATSTATES'][$this->getStateId()]['SHOW']) {
if ($debug) echoDebug(__FILE__
,"<p>state not to show</p>");
if ($debug) echoDebug(__FILE__
,"<p>outdated</p>");
if ($debug) echoDebug(__FILE__
,"<p>no rights</p>");
* checks if the node has children which are on
* @param boolean $checkState
* @param boolean $checkDate
* @param boolean $checkGroup
function hasChildrenToShow($checkState=
TRUE,$checkDate=
TRUE,$checkGroup=
TRUE,$debug=
FALSE){
if ($debug) echoDebug(__FILE,"<blockquote>Cached</blockquote>\n");
foreach($childArr as $child) {
if ($child->isToShow($checkState,$checkDate,$checkGroup,$debug)) {
if ($debug) echoDebug(__FILE__
,"<blockquote style=\"background-color: green;\">MED_CATEGORY_NODE::hasChildrenToShow returns TRUE</blockquote>");
* checks if the menu is to show from date
* - 0: showtill is outdate
* - -2: showfrom is not reached
$now=
new pcf_Date(time());
$aDate->setDateStr($this->MEC_SHOWFROM);
if ($aDate->getLinuxTime() >
$now->getLinuxTime()) return -
2;
$aDate->setDateStr($this->MEC_SHOWTILL);
if ($aDate->getLinuxTime() <
$now->getLinuxTime()) return 0;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// media directory methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the root dir of this category
* - if none has been set till now (MEC_PATH is empty) and we have an id a new one is set
* - replace MEC_PATH absolute pathes with template values for
* -- $GLOBALS[OCSP_MED][ROOTPATH]
* -- $GLOBALS[PROJECT][PATH]
* -- $_SERVER[DOCUMENT_ROOT]
* by calling setRootDir()
* @return string (NULL in case of an error)
if (strlen($s_mecPath)>
2) { // avoid "/" to be checked
// we have a template -> parse it
require_once($GLOBALS['PROJECT']['PHPINCPATH'].
"common/pcf_templates.phpinc");
if (substr($s_mecPath,-
1) ==
"/") $s_mecPath=
substr($s_mecPath,0,-
1); // cut final slash as it will be returned later
// the template failed or we do not have a template
if (is_dir($GLOBALS['OCSP_MED']['ROOTPATH'].
$s_mecPath)) {
$s_mecPath=
$GLOBALS['OCSP_MED']['ROOTPATH'].
$s_mecPath;
if (!($this->setRootDir($s_mecPath,FALSE,FALSE,$debug))) {
// ensure we use a template to be able to copy the database to another location by calling setRootDir
// if this fails we are in truble
if ($debug) echoDebug(__FILE__
,"<p style=\"padding-left:20px;\">ERROR setting RootDir from MEDIA ROOT <br/>to $s_mecPath</p>");
} else if (is_dir($GLOBALS['PROJECT']['PATH'].
$s_mecPath)) {
$s_mecPath=
$GLOBALS['PROJECT']['PATH'].
$s_mecPath;
if (!($this->setRootDir($s_mecPath,FALSE,FALSE,$debug))) {
// ensure we use a template to be able to copy the database to another location by calling setRootDir
// if this fails we are in truble
if ($debug) echoDebug(__FILE__
,"<p style=\"padding-left:20px;\">ERROR setting RootDir from PROJECT-PATH <br/>to $s_mecPath</p>");
} else if (is_dir($_SERVER['DOCUMENT_ROOT'].
"/".
$s_mecPath)) {
$s_mecPath=
$_SERVER['DOCUMENT_ROOT'].
"/".
$s_mecPath;
if (!($this->setRootDir($s_mecPath,FALSE,FALSE,$debug))) {
// ensure we use a template to be able to copy the database to another location by calling setRootDir
// if this fails we are in truble
if ($debug) echoDebug(__FILE__
,"<p style=\"padding-left:20px;\">ERROR setting RootDir from DOCUMENT_ROOT <br/>to $s_mecPath</p>");
if ($debug) echoDebug(__FILE__
,"<p style=\"padding-left:20px;\">ERROR ROOTDIR not found</p>");
// we do not have a root dir set right now
if (!empty($GLOBALS['OCSP_MED']['ROOTPATH']) &&
intval($this->getId())) {
require_once($GLOBALS['PROJECT']['PHPINCPATH'].
"common/pcf_templates.phpinc");
$GLOBALS['OCSP_MED']['ROOTPATH']=
trim($GLOBALS['OCSP_MED']['ROOTPATH']);
if (substr(trim($GLOBALS['OCSP_MED']['ROOTPATH']),-
1) !=
"/") $GLOBALS['OCSP_MED']['ROOTPATH'].=
"/";
$s_mecPath=
$GLOBALS['PROJECT']['PATH'].
"media/".
$this->getId();
if (!$this->setRootDir($s_mecPath,TRUE,FALSE,$debug)) {
$s_mecPath=
trim($s_mecPath);
if (substr($s_mecPath,-
1) !=
"/") $s_mecPath.=
"/";
if (strstr($this->MEC_PATH,"$") !== FALSE) {
require_once($GLOBALS['PROJECT']['PHPINCPATH']."common/pcf_templates.phpinc");
$ret = pcf_tmpl_parse($this->MEC_PATH,$this->getDBVal(),$debug);
if (is_dir($this->MEC_PATH)) {
if (!strstr($this->MEC_PATH,$GLOBALS['MED']['ROOTPATH'])) {
$ret = $GLOBALS['MED']['ROOTPATH'].$this->MEC_PATH;
$ret=trim(str_replace("//","/",$ret));
if (substr($ret,-1) != "/") $ret.="/";
if ($debug) echo "<blockquote>Returns: $ret</blockquote>";
* sets the root dir an returns if the
* @param string $absPath including Project Root
* @param boolean $create create the directory if not exists
* @param boolean $noCheck
function setRootDir($absPath,$create=
FALSE,$noCheck=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::setRootDir($absPath,".
($create ?
"CREATE" :
"").
")</b> (".
get_class($this).
"</p>\n";
if (empty($absPath) ||
($absPath==
"/")) return FALSE; // error no path
// replace pathes by global settings
$s_mecPath=
str_replace($GLOBALS['OCSP_MED']['ROOTPATH'],"\$@OCSP_MED|ROOTPATH\$",$absPath);
$s_mecPath=
str_replace($GLOBALS['PROJECT']['PATH'],"\$@PROJECT|PATH\$",$s_mecPath);
$s_mecPath=
str_replace($_SERVER['DOCUMENT_ROOT'],"\$�DOCUMENT_ROOT\$",$s_mecPath);
if ($debug) echoDebug(__FILE__
,"<blockquote><p>DIR (".
$s_mecPath.
")<br />EXISTS -> RETURN TRUE</p></blockquote>\n");
return $this->setRootDir($absPath,FALSE,$noCheck,$debug);
if ($noCheck &&
(strlen($absPath) >
1)) { // avoid "/" with strlen(>1)
$s_mecPath=
str_replace($GLOBALS['OCSP_MED']['ROOTPATH'],"\$@OCSP_MED|ROOTPATH\$",$absPath);
$s_mecPath=
str_replace($GLOBALS['PROJECT']['PATH'],"\$@PROJECT|PATH\$",$s_mecPath);
$s_mecPath=
str_replace($_SERVER['DOCUMENT_ROOT'],"\$�DOCUMENT_ROOT\$",$s_mecPath);
if ($debug) echoDebug(__FILE__
,"<blockquote><p>DIR (".
$s_mecPath.
")<br /><b>DOES NOT EXISTS</b> -> RETURN TRUE</p></blockquote>\n");
return FALSE; // as the dir does not exist otherwise is_dir($absPath) would have been tree
* returns the path where to place upload files
// #############################################
// #############################################
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns a file name which is not used
* @param string $fileName
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::getNewFileName($fileName,$debug)</b></p><blockquote>";
$nameParts=
expolode(".",$fileName);
$retName=
$nameParts[0].
"_".
$i.
".".
$nameParts[1];
$retName=
$fileName.
"_".
$i;
* function adds a file to the category
* @param string $file path to the file
* @param bool $asLink link the file instead of copy it to the media directory
* @todo handle add if $file not already in media dir
function addNewFile($file,$asLink=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::addNewFile($file,$asLink,$debug)</b></p><blockquote>";
require_once $GLOBALS['MED']['PHPINCPATH'].
"MED_FILE.phpclass";
if (is_array($fa)) $ext=
$fa[sizeof($fa)-
1]; else $ext=
""; // just the last elem in the array
if ((!empty($ext)) &&
(!is_array($this->tmpMimeClasses[$ext]))) {
$query=
"SELECT * FROM T_MED_MIMETYPES WHERE MIM_EXTENSIONS LIKE ".
$GLOBALS[$this->get_gDBIDX()]->qs_getSlashedValue("%".
$ext.
"%");
if ($debug) echo
"<p>$query</p>";
$this->tmpMimeClasses[$ext]=
$GLOBALS[$this->get_gDBIDX()]->quickQuery($query);
if ($GLOBALS['MED']['OBJECTCLASS'][$this->tmpMimeClasses[$ext]['MIM_OBJCLASS']]) {
require_once $GLOBALS['MED']['OBJECTCLASS'][$this->tmpMimeClasses[$ext]['MIM_OBJCLASS']]['CLASSFILE'];
$cmd=
"\$fileObj=new ".
$this->tmpMimeClasses[$ext]['MIM_OBJCLASS'].
"(0,\"".
$this->tmpMimeClasses[$ext]['MIM_MIMETYPE'].
"\",\$debug);";
if ($debug) echo
"<pre>ObjCmd: \n$cmd</pre>";
if ($debug) {echo
"<p>";print_r($this->tmpMimeClasses[$ext]);echo
"</p>";}
$fileObj=
new MED_FILE(0,$this->tmpMimeClasses[$ext]['MIM_MIMETYPE'],$debug);
$fileObj->setCatId($this->getId());
$fileObj->setMIMEType($this->tmpMimeClasses[$ext]['MIM_ID']);
if ($debug) echo
"<p>FILE $aName ALLREADY IN DIRECTORY</p>";
$fileObj->setCatId($this->MEC_ID);
$fileObj->setFile($file,FALSE,$debug);
$fileObj->dbSave($this->get_gDBIDX(),$debug);
if ($debug) echo
"</blockquote>";
if ($debug) echo
"<p>RETURNS NULL</p></blockquote>";
* adds a file submitted with post
* @param boolean $autoSave if true the object is stored to the db
* @var MED_FILE $o_mefObj
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::addUploadFile()</b> (".
get_class($this).
")</p><blockquote><pre>".
print_r($uplFArr,TRUE).
"</pre></blockquote>";
// see http://www.php.net/manual/en/function.is-uploaded-file.php
if ($debug) echo
"<p>ERROR: </p><pre>".
print_r($uplFArr,TRUE).
"</pre><p>is not uploaded</p>";
require_once dirname(__FILE__
).
"/MED_FILE.phpclass";
$o_mefObj=
new MED_FILE(0,$uplFArr['type'],$debug);
$o_mefObj->setDefaults();
$o_mefObj->setCatId($this->getId());
$s_fName=
sprintf("%04d%s",$i,"_".
$s_oriFName);
if ($o_mefObj->setFile($s_fName,FALSE,$debug)) { // ($aName,$isTmp=FALSE,$debug=FALSE)
$o_ret=
$o_mefObj->chkObjectClass($debug);
if ($autoSave) $o_ret->dbSave();
if ($debug) echo
"<p>RETURNS NULL</p></blockquote>";
* adds a sub directory of $this->getRootDir() as child to the node
* all files in the direcotry are added to files
* @param string $childName
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::addSubDirAsChild($dirName,$childName ..)</b> (".
get_class($this).
")</p>";
$child->MEC_PARENT=
$this->getId();
$child->MEC_PATH=
$this->getRootDir().
$dirName.
"/";
$child->MEC_WEBDIR=
$this->MEC_WEBDIR.
$dirName.
"/";
$child->MEC_NAME=
$dirName;
$child->MEC_NAME=
$childName;
$child->dbSave($this->gDBIDX,$debug);
$child->checkDir(TRUE,$debug);
* scans the category directory for files not in the database
* if $autoAdd the files are added to the database
* a array with ['NEW'] and ['BROKEN']
* @todo only unique key in db prevents from inserting the same file twice
function checkDir($autoAdd=
FALSE,$debug=
TRUE) {
if ($debug) echo
"<p><b>MED_CATEGORY_NODE::checkDir($autoAdd,$debug)</b></p><blockquote>";
$retArr=
array('NEW'=>
array(),'BROKEN'=>
array());
$query=
"SELECT * FROM T_MED_FILES WHERE MEC_ID=".
$this->getId();
if ($cursor=
$GLOBALS[$this->get_gDBIDX()]->query($query)) {
while($row=
$cursor->fetchArrayFld()) {
$retArr['BROKEN'][]=
$row;
$retArr['NEW']=
$fileList;
foreach($fileList as $file) {
if ($debug) echo
"</blockquote>";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* echos a the row in a table OVERRIDE IN SUB CLASS to change layout
* echos a tree intend called by write children
* @param int $expandLevel
echo
"<tr><td><table width='90%' align='right' border='0'>";
$GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$id]->writeTableRowThis($debug);
$GLOBALS['DBMS_TREE'][$this->getGlobalTreeKey()][$id]->writeTableRowChildren($expandLevel-
1,$useCache,$debug);
echo
"</table></td></tr>";
// #############################################
// #############################################
Documentation generated on Thu, 08 Jan 2009 17:44:47 +0100 by phpDocumentor 1.4.0a2