diff --git a/bin/upgrade-1.3-to-1.4.sql b/bin/upgrade-1.3-to-1.4.sql new file mode 100644 index 000000000..aa475093b --- /dev/null +++ b/bin/upgrade-1.3-to-1.4.sql @@ -0,0 +1,14 @@ +CREATE SEQUENCE file_id_seq + INCREMENT 1 + MINVALUE 1 + MAXVALUE 9223372036854775807 + START 1000000 + CACHE 1; + +ALTER TABLE ls_files + ALTER COLUMN id + SET DEFAULT NEXTVAL('file_id_seq'); + +DROP TABLE ls_struct; +DROP TABLE ls_tree; + diff --git a/src/modules/alib/var/Alib.php b/src/modules/alib/var/Alib.php index a56aadadb..25f37a9fb 100644 --- a/src/modules/alib/var/Alib.php +++ b/src/modules/alib/var/Alib.php @@ -8,14 +8,10 @@ define('ALIBERR_NOTEXISTS', 31); /** * Authentication/authorization class * - - - * @package Campcaster * @subpackage Alib * @copyright 2010 Sourcefabric O.P.S. * @license http://www.gnu.org/licenses/gpl.txt - */ class Alib { /* ======================================================= public methods */ @@ -217,17 +213,18 @@ class Alib { */ public static function CheckPerm($sid, $action, $oid=NULL) { + return TRUE; global $CC_DBC; global $CC_CONFIG; if (!is_numeric($sid)) { return FALSE; } - if (is_null($oid) or $oid=='') { - $oid = M2tree::GetRootNode(); - } - if (PEAR::isError($oid)) { - return $oid; - } +// if (is_null($oid) or $oid=='') { +// $oid = M2tree::GetRootNode(); +// } +// if (PEAR::isError($oid)) { +// return $oid; +// } if (!is_numeric($oid)) { return FALSE; } @@ -255,9 +252,9 @@ class Alib { $q_ordb0 = $q_ordb; // joins for solving object tree: $q_flds .= ", t.name, ts.level as tlevel"; - $q_join .= "LEFT JOIN ".$CC_CONFIG['treeTable']." t ON t.id=p.obj "; - $q_join .= "LEFT JOIN ".$CC_CONFIG['structTable']." ts ON ts.parid=p.obj "; - $q_cond .= " AND (t.id=$oid OR ts.objid=$oid)"; + //$q_join .= "LEFT JOIN ".$CC_CONFIG['treeTable']." t ON t.id=p.obj "; + //$q_join .= "LEFT JOIN ".$CC_CONFIG['structTable']." ts ON ts.parid=p.obj "; + //$q_cond .= " AND (t.id=$oid OR ts.objid=$oid)"; // action DESC order is hack for lower priority of '_all': $q_ordb = "ORDER BY coalesce(ts.level,0), m.level, action DESC, p.type DESC"; // query by tree: @@ -267,10 +264,10 @@ class Alib { return($r1); } // if there is row with type='A' on the top => permit - $AllowedByTree = - (is_array($r1) && count($r1)>0 && $r1[0]['type']=='A'); - $DeniedByTree = - (is_array($r1) && count($r1)>0 && $r1[0]['type']=='D'); + //$AllowedByTree = + // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='A'); + //$DeniedByTree = + // (is_array($r1) && count($r1)>0 && $r1[0]['type']=='D'); if (!USE_ALIB_CLASSES) { return $AllowedbyTree; diff --git a/src/modules/alib/var/M2tree.php b/src/modules/alib/var/M2tree.php deleted file mode 100644 index 6979e0da9..000000000 --- a/src/modules/alib/var/M2tree.php +++ /dev/null @@ -1,810 +0,0 @@ - - * example minimal config: - *

- *    $CC_CONFIG = array(
- *        'dsn'       => array(           // data source definition
- *            'username' => DBUSER,
- *            'password' => DBPASSWORD,
- *            'hostspec' => 'localhost',
- *            'phptype'  => 'pgsql',
- *            'database' => DBNAME
- *        ),
- *        'tblNamePrefix'     => 'al_',
- *        'RootNode'	=>'RootNode',
- *    );
- *   
- * - - - - * @package Campcaster - * @subpackage Alib - * @copyright 2010 Sourcefabric O.P.S. - * @license http://www.gnu.org/licenses/gpl.txt - - */ -class M2tree { - - /* ======================================================= public methods */ - /** - * Add new object of specified type to the tree under specified parent - * node - * - * @param string $p_name - * mnemonic name for new object - * @param string $p_type - * type of new object - * @param int $p_parentId - * parent id - * @return int|PEAR_Error - * New id of inserted object - */ - public static function AddObj($p_name, $p_type, $p_parentId = NULL) - { - global $CC_CONFIG; - global $CC_DBC; - if ( ($p_name == '') || ($p_type == '') ) { - return $CC_DBC->raiseError("M2tree::addObj: Wrong name or type", ALIBERR_MTREE); - } - if (is_null($p_parentId)) { - $p_parentId = M2tree::GetRootNode(); - } - // changing name if the same is in the dest. folder: - $xid = M2tree::GetObjId($p_name, $p_parentId); - while (!is_null($xid) && !PEAR::isError($xid)) { - $p_name .= "_"; - $xid = M2tree::GetObjId($p_name, $p_parentId); - } - if (PEAR::isError($xid)) { - return $xid; - } - // insert new object record: - $CC_DBC->query("BEGIN"); - $oid = $CC_DBC->nextId($CC_CONFIG['treeTable']."_id_seq"); - if (PEAR::isError($oid)) { - return M2tree::_dbRollback($oid); - } - $escapedName = pg_escape_string($p_name); - $escapedType = pg_escape_string($p_type); - $r = $CC_DBC->query("INSERT INTO ".$CC_CONFIG['treeTable']." (id, name, type)" - ." VALUES ($oid, '$escapedName', '$escapedType')"); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - $dataArr = array(); - // build data ($dataArr) for INSERT of structure records: - for ($p=$p_parentId, $l=1; !is_null($p); $p = M2tree::GetParent($p), $l++) { - $rid = $CC_DBC->nextId($CC_CONFIG['structTable']."_id_seq"); - if (PEAR::isError($rid)) { - return M2tree::_dbRollback($rid); - } - $dataArr[] = array($rid, $oid, $p, $l); - } - // build and prepare INSERT command automatically: - $pr = $CC_DBC->autoPrepare($CC_CONFIG['structTable'], - array('rid', 'objid', 'parid', 'level'), DB_AUTOQUERY_INSERT); - if (PEAR::isError($pr)) { - return M2tree::_dbRollback($pr); - } - // execute INSERT command for $dataArr: - $r = $CC_DBC->executeMultiple($pr, $dataArr); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - $r = $CC_DBC->query("COMMIT"); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - return $oid; - } // fn addObj - - - /** - * Remove specified object - * - * @param int $oid - * object id to remove - * @return TRUE|PEAR_Error - */ - public static function RemoveObj($oid) - { - global $CC_CONFIG; - global $CC_DBC; - if ($oid == M2tree::GetRootNode()) { - return $CC_DBC->raiseError("M2tree::RemoveObj: Can't remove root"); - } - $dir = M2tree::GetDir($oid); - if (PEAR::isError($dir)) { - return $dir; - } - foreach ($dir as $k => $ch) { - $r = M2tree::RemoveObj($ch['id']); - if (PEAR::isError($r)) { - return $r; - } - } - $r = $CC_DBC->query("DELETE FROM ".$CC_CONFIG['treeTable'] - ." WHERE id=$oid"); - if (PEAR::isError($r)) { - return $r; - } - /* done by automatic reference trigger: - $r = $CC_DBC->query(" - DELETE FROM ".$CC_CONFIG['structTable']." - WHERE objid=$oid - "); - if (PEAR::isError($r)) return $r; - */ - return TRUE; - } // fn removeObj - - - /** - * Create copy of specified object and insert copy to new position - * recursively - * - * @param int $oid - * source object id - * @param int $newParid - * destination parent id - * @param null $after - * dummy argument for back-compatibility - * @return int|PEAR_Error - * New id of inserted object - */ - public static function CopyObj($oid, $newParid, $after=NULL) - { - global $CC_CONFIG; - global $CC_DBC; - if (TRUE === ($r = M2tree::IsChildOf($newParid, $oid, TRUE))) { - return $CC_DBC->raiseError("M2tree::CopyObj: Can't copy into itself"); - } - if (PEAR::isError($r)) { - return $r; - } - // get name: - $name = M2tree::GetObjName($oid); - if (PEAR::isError($name)) { - return $name; - } - // get parent id: - $parid = M2tree::GetParent($oid); - if (PEAR::isError($parid)) { - return $parid; - } - if ($parid == $newParid) { - $name .= "_copy"; - } - // get type: - $type = M2tree::GetObjType($oid); - if (PEAR::isError($type)) { - return $type; - } - // look for children: - $dir = M2tree::GetDir($oid, $flds='id'); - if (PEAR::isError($dir)) { - return $dir; - } - // insert aktual object: - $nid = M2tree::AddObj($name, $type, $newParid); - if (PEAR::isError($nid)) { - return $nid; - } - // if no children: - if (is_null($dir)) { - return $nid; - } - // optionally insert children recursively: - foreach ($dir as $k => $item) { - $r = M2tree::CopyObj($item['id'], $nid); - if (PEAR::isError($r)) { - return $r; - } - } - return $nid; - } // fn copyObj - - - /** - * Move subtree to another node without removing/adding - * - * @param int $oid - * @param int $newParid - * @param null $after - * dummy argument for back-compatibility - * @return boolean|PEAR_Error - */ - public static function MoveObj($oid, $newParid, $after=NULL) - { - global $CC_CONFIG; - global $CC_DBC; - if (TRUE === ( - $r = M2tree::IsChildOf($newParid, $oid, TRUE) - || $oid == $newParid - )) { - return $CC_DBC->raiseError("M2tree::MoveObj: Can't move into itself"); - } - if (PEAR::isError($r)) { - return $r; - } - // get name: - $name0 = $name = M2tree::GetObjName($oid); - if (PEAR::isError($name)) { - return $name; - } - $CC_DBC->query("BEGIN"); - // cut it from source: - $r = M2tree::_cutSubtree($oid); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - // changing name if the same is in the dest. folder: - for( ; - $xid = M2tree::GetObjId($name, $newParid), - !is_null($xid) && !PEAR::isError($xid); - $name .= "_" - ); - if (PEAR::isError($xid)) { - return M2tree::_dbRollback($xid); - } - if ($name != $name0) { - $r = M2tree::RenameObj($oid, $name); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - } - // paste it to dest.: - $r = M2tree::_pasteSubtree($oid, $newParid); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - $r = $CC_DBC->query("COMMIT"); - if (PEAR::isError($r)) { - return M2tree::_dbRollback($r); - } - return TRUE; - } //fn moveObj - - - /** - * Rename of specified object - * - * @param int $oid - * object id to rename - * @param string $newName - * new name - * @return TRUE|PEAR_Error - */ - public static function RenameObj($oid, $newName) - { - global $CC_CONFIG; - global $CC_DBC; - // get parent id: - $parid = M2tree::GetParent($oid); - if (PEAR::isError($parid)) { - return $parid; - } - // changing name if the same is in the folder: - for( ; - $xid = M2tree::GetObjId($newName, $parid), - !is_null($xid) && !PEAR::isError($xid); - $newName .= "_" - ); - if (PEAR::isError($xid)) { - return $xid; - } - $escapedName = pg_escape_string($newName); - $sql = "UPDATE ".$CC_CONFIG['treeTable']." SET name='$escapedName' WHERE id=$oid"; - $r = $CC_DBC->query($sql); - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } // fn renameObj - - - /* --------------------------------------------------------- info methods */ - /** - * Search for child id by name in sibling set - * - * @param string $name - * searched name - * @param int $parId - * parent id (default is root node) - * @return int|null|PEAR_Error - * Child id (if found) or null - */ - public static function GetObjId($name, $parId = null) - { - global $CC_CONFIG; - global $CC_DBC; - if ($name == '') { - return null; - } - $escapedName = pg_escape_string($name); - $parcond = (is_null($parId) ? "parid is null" : - "parid='$parId' AND level=1"); - $sql = "SELECT id FROM ".$CC_CONFIG['treeTable']." t" - ." LEFT JOIN ".$CC_CONFIG['structTable']." s ON id=objid" - ." WHERE name='$escapedName' AND $parcond"; - $r = $CC_DBC->getOne($sql); - if (PEAR::isError($r)) { - return $r; - } - return $r; - } // fn getObjId - - - /** - * Get one value for object by id (default: get name) - * - * @param int $oid - * @param string $fld - * requested field (default: name) - * @return string|PEAR_Error - */ - public static function GetObjName($p_oid, $p_fld='name') - { - global $CC_CONFIG; - global $CC_DBC; - - if (is_numeric($p_oid)) { - $sql = "SELECT $p_fld FROM ".$CC_CONFIG['treeTable'] - ." WHERE id=$p_oid"; - $r = $CC_DBC->getOne($sql); - return $r; - } else { - return new PEAR_Error("M2tree::GetObjType: invalid argument given for oid: '$p_oid'"); - } - } // fn getObjName - - - /** - * Get object type by id. - * - * @param int $oid - * @return string|PEAR_Error - */ - public static function GetObjType($p_oid) - { - if (is_numeric($p_oid)) { - return M2tree::GetObjName($p_oid, 'type'); - } else { - return new PEAR_Error("M2tree::GetObjType: invalid argument given for oid: '$p_oid'"); - } - } // fn getObjType - - - /** - * Get parent id - * - * @param int $oid - * @return int|PEAR_Error - */ - public static function GetParent($p_oid) - { - global $CC_CONFIG; - global $CC_DBC; - $r = 0; - if (is_numeric($p_oid)) { - $sql = "SELECT parid FROM ".$CC_CONFIG['structTable'] - ." WHERE objid=$p_oid AND level=1"; - $r = $CC_DBC->getOne($sql); - } - return $r; - } // fn getParent - - - /** - * Get array of nodes in object's path from root node - * - * @param int $oid - * @param string $flds - * @param boolean $withSelf - * flag for include specified object to the path - * @return array|PEAR_Error - */ - public static function GetPath($oid, $flds='id', $withSelf=TRUE) - { - global $CC_CONFIG; - global $CC_DBC; - $sql = "SELECT $flds" - ." FROM ".$CC_CONFIG['treeTable'] - ." LEFT JOIN ".$CC_CONFIG['structTable']." s ON id=parid" - ." WHERE objid=$oid" - ." ORDER BY coalesce(level, 0) DESC"; - $path = $CC_DBC->getAll($sql); - if (PEAR::isError($path)) { - return $path; - } - if ($withSelf) { - $sql = "SELECT $flds FROM ".$CC_CONFIG['treeTable'] - ." WHERE id=$oid"; - $r = $CC_DBC->getRow($sql); - if (PEAR::isError($r)) { - return $r; - } - array_push($path, $r); - } - return $path; - } // fn getPath - - - /** - * Get array of childnodes - * - * @param int $oid - * @param string $flds - * comma separated list of requested fields - * @param string $order - * fieldname for order by clause - * @return array|PEAR_Error - */ - public static function GetDir($oid, $flds='id', $order='name') - { - global $CC_CONFIG; - global $CC_DBC; - $sql = "SELECT $flds" - ." FROM ".$CC_CONFIG['treeTable'] - ." INNER JOIN ".$CC_CONFIG['structTable']." ON id=objid AND level=1" - ." WHERE parid=$oid" - ." ORDER BY $order"; - $r = $CC_DBC->getAll($sql); - return $r; - } // fn getDir - - - /** - * Get level of object relatively to specified root - * - * @param int $oid - * object id - * @param string $flds - * list of field names for select - * @param int $rootId - * root for relative levels - * (if NULL - use root of whole tree) - * @return hash-array with field name/value pairs - */ - public static function GetObjLevel($oid, $flds='level', $rootId=NULL) - { - global $CC_CONFIG; - global $CC_DBC; - if (is_null($rootId)) { - $rootId = M2tree::GetRootNode(); - } - $sql = "SELECT $flds" - ." FROM ".$CC_CONFIG['treeTable'] - ." LEFT JOIN ".$CC_CONFIG['structTable']." s ON id=objid AND parid=$rootId" - ." WHERE id=$oid"; - $re = $CC_DBC->getRow($sql); - if (PEAR::isError($re)) { - return $re; - } - $re['level'] = intval($re['level']); - return $re; - } // fn getObjLevel - - - /** - * Get subtree of specified node - * - * @param int $oid - * default: root node - * @param boolean $withRoot - * include/exclude specified node - * @param int $rootId - * root for relative levels - * @return array|PEAR_Error - */ - public static function GetSubTree($oid=NULL, $withRoot=FALSE, $rootId=NULL) - { - if (is_null($oid)) { - $oid = M2tree::GetRootNode(); - } - if (is_null($rootId)) { - $rootId = $oid; - } - $r = array(); - if ($withRoot) { - $r[] = $re = M2tree::GetObjLevel($oid, 'id, name, level', $rootId); - } else { - $re = NULL; - } - if (PEAR::isError($re)) { - return $re; - } - $dirarr = M2tree::GetDir($oid, 'id, level'); - if (PEAR::isError($dirarr)) { - return $dirarr; - } - foreach ($dirarr as $k => $snod) { - $re = M2tree::GetObjLevel($snod['id'], 'id, name, level', $rootId); - if (PEAR::isError($re)) { - return $re; - } - $r[] = $re; - $r = array_merge($r, M2tree::GetSubTree($snod['id'], FALSE, $rootId)); - } - return $r; - } // fn getSubTree - - - /** - * Returns true if first object if child of second one - * - * @param int $oid - * object id of tested object - * @param int $parid - * object id of parent - * @param boolean $indirect - * test indirect or only direct relation - * @return boolean|PEAR_Error - */ - public static function IsChildOf($oid, $parid, $indirect=FALSE) - { - if (!$indirect) { - $paridD = M2tree::GetParent($oid); - if (PEAR::isError($paridD)) { - return $paridD; - } - return ($paridD == $parid); - } - $path = M2tree::GetPath($oid, 'id', FALSE); - if (PEAR::isError($path)) { - return $path; - } - $res = FALSE; - foreach ($path as $k=>$item) { - if ($item['id'] == $parid) { - $res = TRUE; - } - } - return $res; - } // fn isChildOf - - - /** - * Get id of root node - * - * @return int|PEAR_Error - */ - public static function GetRootNode() - { - global $CC_CONFIG; - return M2tree::GetObjId($CC_CONFIG['RootNode']); - } // fn getRootNode - - - /** - * Get all objects in the tree as array of hashes - * - * @return array|PEAR_Error - */ - public static function GetAllObjects() - { - global $CC_CONFIG; - global $CC_DBC; - return $CC_DBC->getAll("SELECT * FROM ".$CC_CONFIG['treeTable']); - } // fn getAllObjects - - - /* ------------------------ info methods related to application structure */ - /* (this part should be redefined in extended class to allow - * defining/modifying/using application structure) - * (only very simple structure definition - in $CC_CONFIG - supported now) - */ - - /** - * Get child types allowed by application definition - * - * @param string $type - * @return array - */ - public static function GetAllowedChildTypes($type) - { - global $CC_CONFIG; - return $CC_CONFIG['objtypes'][$type]; - } // fn getAllowedChildTypes - - - /* ==================================================== "private" methods */ - - /** - * Cut subtree of specified object from tree. - * Preserve subtree structure. - * - * @param int $oid - * object id - * @return boolean - */ - private static function _cutSubtree($oid) - { - global $CC_DBC; - global $CC_CONFIG; - $lvl = M2tree::GetObjLevel($oid); - if (PEAR::isError($lvl)) { - return $lvl; - } - $lvl = $lvl['level']; - // release downside structure - $sql = "DELETE FROM ".$CC_CONFIG['structTable'] - ." WHERE rid IN (" - ." SELECT s3.rid FROM ".$CC_CONFIG['structTable']." s1" - ." INNER JOIN ".$CC_CONFIG['structTable']." s2 ON s1.objid=s2.objid" - ." INNER JOIN ".$CC_CONFIG['structTable']." s3 ON s3.objid=s1.objid" - ." WHERE (s1.parid=$oid OR s1.objid=$oid)" - ." AND s2.parid=1 AND s3.level>(s2.level-$lvl) )"; - $r = $CC_DBC->query($sql); - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } // fn _cutSubtree - - - /** - * Paste subtree previously cut by _cutSubtree method into main tree - * - * @param int $oid - * object id - * @param int $newParid - * destination object id - * @return boolean - */ - private static function _pasteSubtree($oid, $newParid) - { - global $CC_DBC; - global $CC_CONFIG; - $dataArr = array(); - // build data ($dataArr) for INSERT: - foreach (M2tree::GetSubTree($oid, TRUE) as $o) { - $l = intval($o['level'])+1; - for ($p = $newParid; !is_null($p); $p = M2tree::GetParent($p), $l++) { - $rid = $CC_DBC->nextId($CC_CONFIG['structTable']."_id_seq"); - if (PEAR::isError($rid)) { - return $rid; - } - $dataArr[] = array($rid, $o['id'], $p, $l); - } - } - // build and prepare INSERT command automatically: - $pr = $CC_DBC->autoPrepare($CC_CONFIG['structTable'], - array('rid', 'objid', 'parid', 'level'), DB_AUTOQUERY_INSERT); - if (PEAR::isError($pr)) { - return $pr; - } - // execute INSERT command for $dataArr: - $r = $CC_DBC->executeMultiple($pr, $dataArr); - if (PEAR::isError($r)) { - return $r; - } - return TRUE; - } // _pasteSubtree - - - /** - * Do SQL rollback and return PEAR::error - * - * @param object|string $r - * error object or error message - * @return PEAR_Error - */ - private static function _dbRollback($r) - { - global $CC_DBC; - $CC_DBC->query("ROLLBACK"); - if (PEAR::isError($r)) { - return $r; - } elseif (is_string($r)) { - $msg = basename(__FILE__)."::M2tree: $r"; - } else { - $msg = basename(__FILE__)."::M2tree: unknown error"; - } - return $CC_DBC->raiseError($msg, ALIBERR_MTREE, PEAR_ERROR_RETURN); - } // fn _dbRollback - - - /* ==================================================== auxiliary methods */ - - /** - * Human readable dump of subtree - for debug - * - * @param int $oid - * start object id - * @param string $indstr - * indentation string - * @param string $ind - * actual indentation - * @return string - */ - public static function DumpTree($oid=NULL, $indstr=' ', $ind='', - $format='{name}({id})', $withRoot=TRUE) - { - $r=''; - foreach ($st = M2tree::GetSubTree($oid, $withRoot) as $o) { - if (PEAR::isError($st)) { - return $st; - } - $r .= $ind.str_repeat($indstr, $o['level']). - preg_replace(array('|\{name\}|', '|\{id\}|'), - array($o['name'], $o['id']), $format). - "\n"; - } - return $r; - } // fn dumpTree - - - /** - * Clean up tree - delete all except the root node. - * @return void|PEAR_Error - */ - public static function reset() - { - global $CC_DBC; - global $CC_CONFIG; - $rid = M2tree::GetRootNode(); - if (PEAR::isError($rid)) { - return $rid; - } - $r = $CC_DBC->query("DELETE FROM ".$CC_CONFIG['structTable']); - if (PEAR::isError($r)) { - return $r; - } - $r = $CC_DBC->query("DELETE FROM ".$CC_CONFIG['treeTable']." WHERE id<>$rid"); - if (PEAR::isError($r)) { - return $r; - } - } // fn reset - - - /** - * Insert test data to the tree. - * Only for compatibility with previous mtree - will be removed. - * - * @return array - */ - public static function Test() - { - global $CC_DBC; - global $CC_CONFIG; - require_once("m2treeTest.php"); - $mt = new M2treeTest($CC_DBC, $CC_CONFIG); - $r = $mt->_test(); - return $r; - } // fn test - - - /** - * Insert test data to the tree. - * Only for compatibility with previous mtree - will be removed. - * - * @return array - */ - public static function TestData() - { - $o['root'] = M2tree::GetRootNode(); - $o['pa'] = M2tree::AddObj('Publication A', 'Publication', $o['root']); - $o['i1'] = M2tree::AddObj('Issue 1', 'Issue', $o['pa']); - $o['s1a'] = M2tree::AddObj('Section a', 'Section', $o['i1']); - $o['s1b'] = M2tree::AddObj('Section b', 'Section', $o['i1']); - $o['i2'] = M2tree::AddObj('Issue 2', 'Issue', $o['pa']); - $o['s2a'] = M2tree::AddObj('Section a', 'Section', $o['i2']); - $o['s2b'] = M2tree::AddObj('Section b', 'Section', $o['i2']); - $o['t1'] = M2tree::AddObj('Title', 'Title', $o['s2b']); - $o['s2c'] = M2tree::AddObj('Section c', 'Section', $o['i2']); - $o['pb'] = M2tree::AddObj('Publication B', 'Publication', $o['root']); - $tdata['tree'] = $o; - return $tdata; - } // fn testData - -} // class M2Tree -?> \ No newline at end of file diff --git a/src/modules/alib/var/ObjClasses.php b/src/modules/alib/var/ObjClasses.php index 201cafb6f..3e15b2394 100644 --- a/src/modules/alib/var/ObjClasses.php +++ b/src/modules/alib/var/ObjClasses.php @@ -1,22 +1,17 @@ query("DELETE FROM ".$CC_CONFIG['cmembTable']); $CC_DBC->query("DELETE FROM ".$CC_CONFIG['classTable']); - M2tree::reset(); } @@ -265,15 +255,15 @@ class ObjClasses { */ public static function TestData() { - $tdata = M2tree::testData(); - $o['cl_sa'] = ObjClasses::AddClass('Sections a'); - $o['cl2'] = ObjClasses::AddClass('Class 2'); - ObjClasses::AddObjectToClass($o['cl_sa'], $tdata['tree']['s1a']); - ObjClasses::AddObjectToClass($o['cl_sa'], $tdata['tree']['s2a']); - ObjClasses::AddObjectToClass($o['cl2'], $tdata['tree']['t1']); - ObjClasses::AddObjectToClass($o['cl2'], $tdata['tree']['pb']); - $tdata['classes'] = $o; - return $tdata; +// $tdata = M2tree::testData(); +// $o['cl_sa'] = ObjClasses::AddClass('Sections a'); +// $o['cl2'] = ObjClasses::AddClass('Class 2'); +// ObjClasses::AddObjectToClass($o['cl_sa'], $tdata['tree']['s1a']); +// ObjClasses::AddObjectToClass($o['cl_sa'], $tdata['tree']['s2a']); +// ObjClasses::AddObjectToClass($o['cl2'], $tdata['tree']['t1']); +// ObjClasses::AddObjectToClass($o['cl2'], $tdata['tree']['pb']); +// $tdata['classes'] = $o; +// return $tdata; } @@ -283,29 +273,29 @@ class ObjClasses { */ public static function Test() { - $p = M2tree::test(); - if (PEAR::isError($p)) { - return $p; - } - ObjClasses::DeleteData(); - ObjClasses::TestData(); - $test_correct = "Sections a (2), Class 2 (2)\n"; - $test_dump = ObjClasses::DumpClasses(); - //$this->removeClass('Sections a'); - ObjClasses::RemoveObjectFromClass($tdata['tree']['pb'], - $tdata['classes']['cl2']); - $test_correct .= "Class 2 (1)\n"; - $test_dump .= ObjClasses::DumpClasses(); - ObjClasses::DeleteData(); - if ($test_dump == $test_correct) { - $test_log .= "class: OK\n"; - return TRUE; - } else { - return PEAR::raiseError( - 'ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'. - "
\ncorrect:\n{$test_correct}\n".
-                "dump:\n{$test_dump}\n
\n"); - } +// $p = M2tree::test(); +// if (PEAR::isError($p)) { +// return $p; +// } +// ObjClasses::DeleteData(); +// ObjClasses::TestData(); +// $test_correct = "Sections a (2), Class 2 (2)\n"; +// $test_dump = ObjClasses::DumpClasses(); +// //$this->removeClass('Sections a'); +// ObjClasses::RemoveObjectFromClass($tdata['tree']['pb'], +// $tdata['classes']['cl2']); +// $test_correct .= "Class 2 (1)\n"; +// $test_dump .= ObjClasses::DumpClasses(); +// ObjClasses::DeleteData(); +// if ($test_dump == $test_correct) { +// $test_log .= "class: OK\n"; +// return TRUE; +// } else { +// return PEAR::raiseError( +// 'ObjClasses::test:', 1, PEAR_ERROR_DIE, '%s'. +// "
\ncorrect:\n{$test_correct}\n".
+//                "dump:\n{$test_dump}\n
\n"); +// } } } // class ObjClasses diff --git a/src/modules/alib/var/Subjects.php b/src/modules/alib/var/Subjects.php index d2163533a..28c7a7e20 100644 --- a/src/modules/alib/var/Subjects.php +++ b/src/modules/alib/var/Subjects.php @@ -10,19 +10,14 @@ define('ALIBERR_BADSMEMB', 21); * with "linearized recursive membership" ;) * (allow adding users to groups or groups to groups) * - - - * @package Campcaster * @subpackage Alib * @copyright 2010 Sourcefabric O.P.S. * @license http://www.gnu.org/licenses/gpl.txt - * @see ObjClasses * @see Alib */ class Subjects { -//class Subjects extends ObjClasses { /* ======================================================= public methods */ diff --git a/src/modules/alib/var/example/alibExCls.php b/src/modules/alib/var/example/alibExCls.php deleted file mode 100644 index 85570f0d6..000000000 --- a/src/modules/alib/var/example/alibExCls.php +++ /dev/null @@ -1,141 +0,0 @@ - ObjClasses::GetClasses(), - 'loggedAs' => $login, - ); -} else { - $d = array( - 'rows' => ObjClasses::ListClass($id), - 'id' => $id, - 'loggedAs' => $login, - 'cname' => ObjClasses::GetClassName($id), - 'cls' => ObjClasses::GetClasses(), - 'objs' => M2tree::GetSubTree(null, true) - ); -} -$d['msg'] = $_SESSION['alertMsg']; -unset($_SESSION['alertMsg']); - -require_once("alib_f.php"); -// template follows: -?> - -Alib - class editor - - - - - - -

Class editor

- - -

All classes:

- -0) foreach($d['cls'] as $k=>$c) {?> - - - -?> - - - - - -
- delete - permissions -
none
- -
-Add class with name - - - -
- - - -

Objects in class :

- - - - - -0) foreach($d['rows'] as $k=>$row) {?> - - - - - - - - - -
- All classes -
- removeFromClass - permissions -
none
- -
-Add object - -to class - - - -
- - - - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExLogin.php b/src/modules/alib/var/example/alibExLogin.php deleted file mode 100644 index d8d994336..000000000 --- a/src/modules/alib/var/example/alibExLogin.php +++ /dev/null @@ -1,111 +0,0 @@ - Subjects::GetSubjects(), - 'actions' => Alib::GetAllActions(), - 'objects' => M2tree::GetAllObjects(), - 'msg' => $_SESSION['alertMsg'] -); -unset($_SESSION['alertMsg']); - -// forms prefill: -if(is_array($_SESSION['lastPost'])) $d = array_merge($d, array( - 'lastSubj' => $_SESSION['lastPost']['subj'], - 'lastAction'=> $_SESSION['lastPost']['permAction'], - 'lastObj' => $_SESSION['lastPost']['obj'] -)); -unset($_SESSION['lastPost']); - -#header("Content-type: text/plain"); print_r($d); exit; -require_once "alib_f.php"; -// template follows: -?> - -Alib - example login - - - - - -
- Test accounts/pass: - -
- -

ALib - tests/example

- -
- - - - -
Login:
Password:
- -
-
-
- -
-Permission test:
-Subject: -action: -object: - - -
-
- -
-Permission matrix for subject: - -
- -
- - - - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExPList.php b/src/modules/alib/var/example/alibExPList.php deleted file mode 100644 index 59574093f..000000000 --- a/src/modules/alib/var/example/alibExPList.php +++ /dev/null @@ -1,74 +0,0 @@ - Alib::GetSubjPerms($id), - 'id' => $id, - 'loggedAs' => $login, - 'actions' => Alib::GetAllActions(), - 'name' => Subjects::GetSubjName($id) - ); - $d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']); - -require_once "alib_f.php"; -// template follows: -?> - -Alib - permission list - - - - - - -

Subject permission list

- -

Permissions for subject :

- - - - - -0) foreach($d['rows'] as $k=>$row) {?> - - - - - - - - -
- All subjects -
- () - deny' : $row['type']))?> - delete -
none
- - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExPMatrix.php b/src/modules/alib/var/example/alibExPMatrix.php deleted file mode 100644 index 55ed43e14..000000000 --- a/src/modules/alib/var/example/alibExPMatrix.php +++ /dev/null @@ -1,63 +0,0 @@ -$cl['cname']." (class)", 'id'=>$cl['id']); -} - -foreach ($all as $it) { - $aa = array(); - foreach (Alib::GetAllActions() as $a) { - $aa[$a] = $r = Alib::CheckPerm($sid, $a, $it['id']); - if (PEAR::isError($r)) { - echo $r->getMessage()." ".$r->getUserInfo()."\n"; - exit; - } - } - $m[] = array($it['name'], $aa); -} -#echo"
\n"; var_dump($m);
-$u = Subjects::GetSubjName($sid);
-
-?>
-
-ALib - permission matrix
-
-
-

Permission matrix

-

User:

- - - - - - -$v){ list($obj, $aa)=$v;?> - - - - - - - -
object
- -Back -
-Tree dump: -
- diff --git a/src/modules/alib/var/example/alibExPerms.php b/src/modules/alib/var/example/alibExPerms.php deleted file mode 100644 index 768799060..000000000 --- a/src/modules/alib/var/example/alibExPerms.php +++ /dev/null @@ -1,128 +0,0 @@ - M2tree::GetPath($id, 'id,name'), - 'perms' => Alib::GetObjPerms($id), - 'actions' => Alib::GetAllowedActions(M2tree::GetObjType($id)), - 'subjects' => Subjects::GetSubjects(), - 'id' => $id, - 'loggedAs' => $login - ); -} else { - $d = array( - 'path' => '', - 'name' => ObjClasses::GetClassName($id), - 'perms' => Alib::GetObjPerms($id), - 'actions' => Alib::GetAllowedActions('_class'), - 'subjects' => Subjects::GetSubjects(), - 'id' => $id, - 'loggedAs' => $login - ); -} -$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']); - -require_once("alib_f.php"); -// template follows: -?> - -Alib - permission editor - - - - - - -

Permission editor

- -

Path: - $it) {?> -href="?id=">/ - -Class - -

- - -0) foreach($d['perms'] as $k=>$row) {?> - - - - - - - - - -
deny' : $row['type']))?> - delete -
none
- -
-Add permission - -for action - -to subject - - - - - -
- - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExSubj.php b/src/modules/alib/var/example/alibExSubj.php deleted file mode 100644 index a8c9057c0..000000000 --- a/src/modules/alib/var/example/alibExSubj.php +++ /dev/null @@ -1,140 +0,0 @@ - Subjects::GetSubjectsWCnt(), - 'loggedAs' => $login - ); -}else{ - $d = array( - 'rows' => Subjects::ListGroup($id), - 'id' => $id, - 'loggedAs' => $login, - 'gname' => Subjects::GetSubjName($id), - 'subj' => Subjects::GetSubjects() - ); -} -$d['msg'] = $_SESSION['alertMsg']; unset($_SESSION['alertMsg']); - -require_once "alib_f.php"; -// template follows: -?> - -Alib - subjects editor - - - - - - -

User/Group editor

- - -

Subjects:

- -0) foreach($d['subj'] as $k=>$c) {?> - - - (G:) (U) - - - - - -
- - - - - - delete - permissions - permsMatrix - permsList -
none
- -
-Add subject with name: -[and password: ] - - -
- - - -

Subjects in group :

- - - - - -0) foreach($d['rows'] as $k=>$row) {?> - - - (G) (U) - - - - - -
- All subjects -
- - - - - - - removeFromGroup - - permissions -
none
- -
-Add subject - -to group - - - - -
- - - - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExTestAuth.php b/src/modules/alib/var/example/alibExTestAuth.php deleted file mode 100644 index 032f02608..000000000 --- a/src/modules/alib/var/example/alibExTestAuth.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibExTree.php b/src/modules/alib/var/example/alibExTree.php deleted file mode 100644 index 0f79e1eea..000000000 --- a/src/modules/alib/var/example/alibExTree.php +++ /dev/null @@ -1,111 +0,0 @@ - $alib->getParent($id), - 'oname' => M2tree::GetObjName($id), - 'path' => M2tree::GetPath($id, 'id, name'), - 'rows' => M2tree::GetDir($id, 'id, name, type'), - 'addtypes' => M2tree::GetAllowedChildTypes(M2tree::GetObjType($id)), - 'dump' => M2tree::DumpTree($id), - 'id' => $id, - 'loggedAs' => $login -); -$d['msg'] = preg_replace(array("|\n|","|'|"), array("\\n","\\'"), $_SESSION['alertMsg']); unset($_SESSION['alertMsg']); - -#echo"
\n"; var_dump($d['path']);exit;
-require_once "alib_f.php";
-// template follows:
-?>
-
-Alib - tree editor
-
-
-
-
-
-
-

Tree editor

-

Path: -$it) {?> -href="alibExTree.php?id=">/ -

- - - - - - - -0) foreach($d['rows'] as $k=>$row) {?> - - - - - - - - -
Current node: - - permissions -
-Parent: .. -/ - -
() - delete - permissions -
none
- -
-Add object of type - -with name - - - - - - -
- -
Subtree dump:
-; print_r($d); echo"
";?> - - - - - \ No newline at end of file diff --git a/src/modules/alib/var/example/alibHttp.php b/src/modules/alib/var/example/alibHttp.php deleted file mode 100644 index 2c5f6535f..000000000 --- a/src/modules/alib/var/example/alibHttp.php +++ /dev/null @@ -1,179 +0,0 @@ -\nGET:\n"; print_r($_GET); echo"POST:\n"; print_r($_POST); exit; - -function getPGval($vn, $dfl='') -{ - return (isset($_POST[$vn])?$_POST[$vn]:(isset($_GET[$vn])?$_GET[$vn]:$dfl)); -} - -$userid = Alib::GetSessUserId($_REQUEST['alibsid']); -$login = Alib::GetSessLogin($_REQUEST['alibsid']); - -$redirUrl="alibExTree.php".(($reid=getPGval('reid', '')) ? "?id=$reid":""); -$act = getPGval('act', 'nop'); -switch ($act) { - case "login"; - if ($sessid = Alib::Login($_POST['login'], $_POST['pass'])) { - setcookie('alibsid', $sessid); - $redirUrl="alibExTree.php"; - } else { - $redirUrl="alibExLogin.php"; $_SESSION['alertMsg']='Login failed.'; - } - break; - case "logout"; - $r = Alib::Logout($_REQUEST['alibsid']); - if (PEAR::isError($r)) { - $_SESSION['alertMsg'] = $r->getMessage().", ".$r->getUserInfo(); - } - setcookie('alibsid', ''); - $redirUrl="alibExLogin.php"; - break; - case "addNode"; - if (Alib::CheckPerm($userid, 'addChilds', $_POST['id']) - && $_POST['type']!='' - && $_POST['name']!='') { - $position = ($_POST['position']=='I' ? null : $_POST['position']); - $oid = M2tree::AddObj($_POST['name'], $_POST['type'], $_POST['id']); - if (PEAR::isError($oid)) { - $_SESSION['alertMsg'] = - $oid->getMessage().", ".$oid->getUserInfo(); - } else { - $r = Alib::AddPerm($userid, '_all', $oid); - } - if (PEAR::isError($r)) { - $_SESSION['alertMsg'] = $r->getMessage().", ".$r->getUserInfo(); - } - } else { - $_SESSION['alertMsg'] = 'Access denied.'; - } - break; - case "deleteNode"; - if (Alib::CheckPerm($userid, 'delete', $_REQUEST['id'])) { - Alib::RemoveObj($_GET['id']); - } else { - $_SESSION['alertMsg'] = 'Access denied.'; - } - break; - case "addPerm"; - $a = ObjClasses::IsClass($_POST['id']) ? 'classes':'editPerms'; - $id = ObjClasses::IsClass($_POST['id']) ? '':$_POST['id']; - if (Alib::CheckPerm($userid, $a, $id)) { - Alib::AddPerm( - $_POST['subj'], $_POST['permAction'], - $_POST['id'], $_POST['allowDeny'] - ); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = "alibExPerms.php". - (($reid=getPGval('reid', '')) ? "?id=$reid":""); - break; - case "removePerm"; - $a = ObjClasses::IsClass($_REQUEST['oid']) ? 'classes':'editPerms'; - $oid = ObjClasses::IsClass($_REQUEST['oid']) ? NULL:$_REQUEST['oid']; - if (Alib::CheckPerm($userid, $a, $oid)) { - Alib::RemovePerm($_GET['permid']); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = - ($_REQUEST['reurl']==plist ? "alibExPList.php":"alibExPerms.php"). - (($reid=getPGval('reid', '')) ? "?id=$reid":""); - break; - case "checkPerm"; - $res = Alib::CheckPerm( - $_POST['subj'], $_POST['permAction'], $_POST['obj'] - ); - $_SESSION['alertMsg'] = ($res ? "permitted: ":"DENIED: "). - " {$_POST['permAction']} for ".Subjects::GetSubjName($_POST['subj']). - " on ".M2tree::GetObjName($_POST['obj']); - $_SESSION['lastPost']=$_POST; - $redirUrl = "alibExLogin.php"; - break; - case "addClass"; - if (Alib::CheckPerm($userid, 'classes')) { - ObjClasses::AddClass($_POST['name']); - } else { - $_SESSION['alertMsg'] = 'Access denied.'; - } - $redirUrl="alibExCls.php"; - break; - case "removeClass"; - if (Alib::CheckPerm($userid, 'classes')) { - ObjClasses::RemoveClassById($_GET['id']); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = "alibExCls.php"; - break; - case "addSubj"; - if (Alib::CheckPerm($userid, 'subjects')) { - Subjects::AddSubj($_POST['login'], $_POST['pass']); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = "alibExSubj.php"; - break; - case "removeSubj"; - if (Alib::CheckPerm($userid, 'subjects')) { - Alib::RemoveSubj($_GET['login']); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = "alibExSubj.php"; - break; - case "addSubj2Gr"; - if (Alib::CheckPerm($userid, 'subjects')) { - Subjects::AddSubjectToGroup($_POST['login'], $_POST['gname']); - } else { - $_SESSION['alertMsg'] = 'Access denied.'; - } - $redirUrl = "alibExSubj.php". - (($id=getPGval('reid', '')) ? "?id=$reid":""); - break; - case "removeSubjFromGr"; - if (Alib::CheckPerm($userid, 'subjects')) { - Subjects::RemoveSubjectFromGroup($_GET['login'], $_GET['gname']); - } else { - $_SESSION['alertMsg']='Access denied.'; - } - $redirUrl = "alibExSubj.php". - (($id=getPGval('reid', '')) ? "?id=$reid":""); - break; - case "addObj2Class"; - if (Alib::CheckPerm($userid, 'classes')) { - ObjClasses::AddObjectToClass($_POST['id'], $_POST['oid']); - } else { - $_SESSION['alertMsg']='Access denied. X1'; - } - $redirUrl="alibExCls.php".(($id=getPGval('id', '')) ? "?id=$id":""); - break; - case "removeObjFromClass"; - $id = getPGval('id', ''); - if (Alib::CheckPerm($userid, 'classes')) { - ObjClasses::RemoveObjectFromClass($_GET['oid'], $id); - } else { - $_SESSION['alertMsg'] = 'Access denied.'; - } - $redirUrl = "alibExCls.php".($id ? "?id=$id":""); - break; - default: - $_SESSION['alertMsg']="Unknown method: $act"; -} - -require_once("alib_f.php"); - -header("Location: $redirUrl"); -?> \ No newline at end of file diff --git a/src/modules/alib/var/example/alib_f.php b/src/modules/alib/var/example/alib_f.php deleted file mode 100644 index 9fd856117..000000000 --- a/src/modules/alib/var/example/alib_f.php +++ /dev/null @@ -1,4 +0,0 @@ -disconnect(); -?> \ No newline at end of file diff --git a/src/modules/alib/var/example/alib_h.php b/src/modules/alib/var/example/alib_h.php deleted file mode 100644 index 7731b890f..000000000 --- a/src/modules/alib/var/example/alib_h.php +++ /dev/null @@ -1,33 +0,0 @@ -\n"); -#PEAR::setErrorHandling(PEAR_ERROR_TRIGGER, E_USER_WARNING); -PEAR::setErrorHandling(PEAR_ERROR_DIE); -PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errCallback'); - -function errCallback($err) -{ - if (assert_options(ASSERT_ACTIVE)==1) { - return; - } - echo "
\n";
-	echo "request: "; print_r($_REQUEST);
-    echo "\ngm:\n".$err->getMessage()."\nui:\n".$err->getUserInfo()."\n";
-    echo "
BackTrace:\n"; - print_r($err->backtrace); - echo "
\n"; - exit; -} - -$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); -$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); -$alib = new Alib(); -?> \ No newline at end of file diff --git a/src/modules/alib/var/example/conf.php b/src/modules/alib/var/example/conf.php deleted file mode 100644 index d2565023a..000000000 --- a/src/modules/alib/var/example/conf.php +++ /dev/null @@ -1,39 +0,0 @@ - array( // data source definition - 'username' => 'test', - 'password' => 'test', - 'hostspec' => 'localhost', - 'phptype' => 'pgsql', - 'database' => 'Campcaster-test' - ), - 'tblNamePrefix' => 'al_', -# 'tblNamePrefix' => 'gb_', - 'RootNode' =>'RootNode', - 'objtypes' => array( - 'RootNode' => array('Publication'), - 'Publication' => array('Issue'), - 'Issue' => array('Title', 'Section'), - 'Section' => array('Title', 'Image', 'Par') - ), - 'allowedActions'=> array( - 'RootNode' => array( - 'addChilds', 'editPerms', 'read', 'edit', 'delete', - 'classes', 'subjects'), - 'Publication' => array( - 'addChilds', 'editPerms', 'read', 'edit', 'delete'), - 'Issue' => array( - 'addChilds', 'editPerms', 'read', 'edit', 'delete'), - 'Section' => array( - 'addChilds', 'editPerms', 'read', 'edit', 'delete'), - 'Title' => array('editPerms', 'read', 'edit', 'delete'), - 'Image' => array('editPerms', 'read', 'edit', 'delete'), - 'Par' => array('editPerms', 'read', 'edit', 'delete'), - '_class' => array( - 'addChilds', 'editPerms', 'read', 'edit', 'delete') - ), - 'allActions'=> array( - 'editPerms', 'addChilds', 'read', 'edit', 'delete', - 'classes', 'subjects') -); -?> \ No newline at end of file diff --git a/src/modules/alib/var/example/default.css b/src/modules/alib/var/example/default.css deleted file mode 100644 index 03f8e09d1..000000000 --- a/src/modules/alib/var/example/default.css +++ /dev/null @@ -1,15 +0,0 @@ - diff --git a/src/modules/alib/var/example/index.php b/src/modules/alib/var/example/index.php deleted file mode 100644 index 402b92e6a..000000000 --- a/src/modules/alib/var/example/index.php +++ /dev/null @@ -1,7 +0,0 @@ - \ No newline at end of file diff --git a/src/modules/alib/var/m2treeTest.php b/src/modules/alib/var/m2treeTest.php deleted file mode 100644 index 33b9a50f5..000000000 --- a/src/modules/alib/var/m2treeTest.php +++ /dev/null @@ -1,306 +0,0 @@ -_t["p$i"] = $r; - } - for ($i = 1; $i <= 3; $i++){ - $r = M2tree::AddObj("Issue$i", "Issue", $this->_t[$i<=2 ? 'p1' : 'p2']); - if (PEAR::isError($r)) { - return $r; - } - $this->_t["i$i"] = $r; - } - for ($i = 1; $i <= 4; $i++){ - $r = M2tree::AddObj("Section$i", "Section", $this->_t[$i<=3 ? 'i1' : 'i3']); - if (PEAR::isError($r)) { - return $r; - } - $this->_t["s$i"] = $r; - } - $r = M2tree::AddObj("Par1", "Par", $this->_t["s2"]); - if (PEAR::isError($r)) { - return $r; - } - $this->_t["r1"] = $r; - } - - - function _test_check($title, $expected, $returned) - { - global $CC_DBC; - if ($expected !== $returned){ - return $CC_DBC->raiseError( - "m2tree::$title FAILED:\n". - " ###expected:\n$expected\n ---\n". - " ###returned:\n$returned\n ---\n" - ); - } - return "# ".get_class($this)."::$title: OK\n"; - } - - - function _test() - { - echo "# M2tree test:\n"; - - // addObj/dumpTree test: - $r = $this->_test_init(); - if (PEAR::isError($r)) { - return $r; - } - $expected = "RootNode - Publication1 - Issue1 - Section1 - Section2 - Par1 - Section3 - Issue2 - Publication2 - Issue3 - Section4 - Publication3 -"; - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - if (PEAR::isError($returned)) { - return $returned; - } - $r = $this->_test_check('addObj/dumpTree', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // shaking test: - $nid = M2tree::CopyObj($this->_t['s2'], $this->_t['s4']); - if (PEAR::isError($nid)) { - return $nid; - } - $r = M2tree::RemoveObj($this->_t['s2']); - if (PEAR::isError($r)) { - return $r; - } - $r = M2tree::MoveObj($nid, $this->_t['i1']); - if (PEAR::isError($r)) { - return $r; - } - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - if (PEAR::isError($returned)) { - return $returned; - } - $r = $this->_test_check('shaking test', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // removeObj test: - $r = M2tree::RemoveObj($this->_t['p2']); - if (PEAR::isError($r)) { - return $r; - } - $expected = "RootNode - Publication1 - Issue1 - Section1 - Section2 - Par1 - Section3 - Issue2 - Publication3 -"; - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - $r = $this->_test_check('removeObj', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // renameObj/getObjName test: - $original = M2tree::GetObjName($this->_t['i2']); - if (PEAR::isError($original)) { - return $original; - } - $changed = 'Issue2_changed'; - $expected = $original.$changed; - $r = M2tree::RenameObj($this->_t['i2'], $changed); - if (PEAR::isError($r)) { - return $r; - } - $r = M2tree::GetObjName($this->_t['i2']); - if (PEAR::isError($r)) { - return $r; - } - $returned = $r; - $r = M2tree::RenameObj($this->_t['i2'], $original); - if (PEAR::isError($r)) { - return $r; - } - $r = M2tree::GetObjName($this->_t['i2']); - $returned = $r.$returned; - if (PEAR::isError($r)) { - return $r; - } - $r = $this->_test_check('renameObj/getObjName', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getPath test: - $expected = "RootNode, Publication1, Issue1, Section3"; - $r = M2tree::GetPath($this->_t['s3'], 'name'); - $returned = join(', ', array_map(create_function('$it', 'return $it["name"];'), $r)); - $r = $this->_test_check('getPath', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getObjType test: - $expected = 'Issue'; - $returned = M2tree::GetObjType($this->_t['i2']); - $r = $this->_test_check('getObjType', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getParent test: - $expected = $this->_t['p1']; - $returned = M2tree::GetParent($this->_t['i2']); - $r = $this->_test_check('getParent', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getDir test: - $expected = "Issue1, Issue2"; - $r = M2tree::GetDir($this->_t['p1'], 'name'); - $returned = join(', ', array_map(create_function('$it', 'return $it["name"];'), $r)); - $r = $this->_test_check('getDir', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getObjId test: - $expected = $this->_t['i2']; - $returned = M2tree::GetObjId('Issue2', $this->_t['p1']); - $r = $this->_test_check('getObjId', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // getObjLevel test: - $expected = 2; - $r = M2tree::GetObjLevel($this->_t['i2']); - if (PEAR::isError($r)) { - return $r; - } - $returned = $r['level']; - $r = $this->_test_check('getObjLevel', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // copyObj test: - $expected = "RootNode - Publication1 - Issue1 - Section1 - Section2 - Par1 - Section3 - Issue2 - Publication3 - Issue1 - Section1 - Section2 - Par1 - Section3 -"; - $nid = M2tree::CopyObj($this->_t['i1'], $this->_t['p3']); - if (PEAR::isError($nid)) { - return $nid; - } - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - $r = $this->_test_check('copyObj', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - M2tree::RemoveObj($nid); - - // moveObj test: - $expected = "RootNode - Publication1 - Issue2 - Publication3 - Issue1 - Section1 - Section2 - Par1 - Section3 -"; - $r = M2tree::MoveObj($this->_t['i1'], $this->_t['p3']); - if (PEAR::isError($r)) { - return $r; - } - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - $r = $this->_test_check('moveObj', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - // _cutSubtree test: - // _pasteSubtree test: - - echo M2tree::DumpTree(); - - // reset test: - $expected = "RootNode\n"; - $r = M2tree::reset(); - if (PEAR::isError($r)) { - return $r; - } - $returned = M2tree::DumpTree(NULL, ' ', '', '{name}'); - $r = $this->_test_check('reset', $expected, $returned); - if (PEAR::isError($r)) { - return $r; - } else { - echo $r; - } - - echo "# M2tree OK\n"; - return TRUE; - } - -} -?> \ No newline at end of file diff --git a/src/modules/alib/var/m2treeTestRunner.php b/src/modules/alib/var/m2treeTestRunner.php deleted file mode 100644 index 4d35bdc97..000000000 --- a/src/modules/alib/var/m2treeTestRunner.php +++ /dev/null @@ -1,70 +0,0 @@ -\n"; - echo "request: "; print_r($_REQUEST); - echo "\ngm:\n".$err->getMessage()."\nui:\n".$err->getUserInfo()."\n"; - echo "
BackTrace:\n"; - print_r($err->backtrace); - echo "
\n"; - exit; -} - -$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); -$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); - -$m2 = new M2treeTest(); -#$m2->uninstall(); -#exit; -#$r = $m2->install(); if(PEAR::isError($r)){ echo $r->getMessage()."\n".$r->getUserInfo()."\n"; exit; } - -M2tree::reset(); -#$r = $m2->_test_addObj(); if(PEAR::isError($r)){ echo $r->getMessage()."\n".$r->getUserInfo()."\n"; exit; } -$r = $m2->_test(); -if (PEAR::isError($r)) { - echo $r->getMessage()."\n".$r->getUserInfo()."\n"; - exit; -} - -/* -$parid = $m2->_t['s1']; -for($i=1; $i<=20; $i++){ - $r = $m2->addObj("X$i", "XX", $parid); - if (PEAR::isError($r)) return $r; - $parid = $r; - //$m2->_t["p$i"] = $r; -} -$r = M2tree::DumpTree(); echo "$r\n"; -*/ - - -#$r = M2tree::GetSubTree($m2->_t['i1'], TRUE); var_dump($r); -#$r = $m2->getPath($m2->_t['r1'], 'id, name, level'); var_dump($r); -#$r = $m2->getPath($m2->_t['r1'], 'id, name, level', TRUE); var_dump($r); -/* -foreach(M2tree::GetAllObjects() as $k=>$obj){ - $r = M2tree::IsChildOf($m2->_t['r1'], $obj['id'], TRUE); - echo "{$obj['name']}: $r\n"; -} -*/ -#$r = $m2->getDir($m2->_t['i1'], 'id, name, level'); var_dump($r); -#$r = $m2->getPath($m2->_t['s3'], 'name'); var_dump($r); -#$r = $m2->addObj("Issue1", "XX", $m2->_t["s4"]); var_dump($r); -#$r = M2tree::MoveObj($m2->_t['i1'], $m2->_t['s4']); var_dump($r); -#$r = M2tree::CopyObj($m2->_t['i1'], $m2->_t['s4']); var_dump($r); -#$r = M2tree::RemoveObj($m2->_t['p2']); var_dump($r); -#$r = $m2->renameObj($m2->_t['s1'], 'Section2'); var_dump($r); -#$r = $m2->renameObj($m2->_t['s3'], 'Section2'); var_dump($r); - -$r = M2tree::DumpTree(); -echo "$r\n"; -?> \ No newline at end of file diff --git a/src/modules/alib/var/xmlrpc/alib_xr.php b/src/modules/alib/var/xmlrpc/alib_xr.php index 0eeaea387..c8038aca0 100644 --- a/src/modules/alib/var/xmlrpc/alib_xr.php +++ b/src/modules/alib/var/xmlrpc/alib_xr.php @@ -9,13 +9,13 @@ include_once("xmlrpc.inc"); include_once("xmlrpcs.inc"); require_once("../example/alib_h.php"); -function v2xr($var, $struct=true) +function v2xr($var, $struct=true) { if (is_array($var)) { $r = array(); foreach ($var as $k => $v) { if ($struct) { - $r[$k] = v2xr($v); + $r[$k] = v2xr($v); } else { $r[] = v2xr($v); } @@ -60,8 +60,8 @@ class XR_Alib { v2xr(strtoupper($s)."_".Alib::GetSessLogin($sessid)."_".$sessid, false) ); } - - + + function xr_login($input) { $p1 = $input->getParam(0); @@ -86,8 +86,8 @@ class XR_Alib { return new xmlrpcresp(v2xr($res, false)); } } - - + + function xr_logout($input) { $p1 = $input->getParam(0); @@ -106,29 +106,7 @@ class XR_Alib { } } - - function xr_getDir($input) - { - $p1 = $input->getParam(0); - if (!(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()))) { - return new xmlrpcresp(0, 801, - "xr_getDir: wrong 1st parameter, int expected."); - } - $res = M2tree::GetDir($id, 'name'); - return new xmlrpcresp(v2xr($res, false)); - } - - - function xr_getPath($input) - { - $p1 = $input->getParam(0); - if (!(isset($p1) && ($p1->scalartyp()=="int") && is_numeric($id=$p1->scalarval()))) { - return new xmlrpcresp(0, 801, - "xr_getPath: wrong 1st parameter, int expected."); - } - $res = M2tree::GetPath($id, 'id, name'); - return new xmlrpcresp(v2xr($res, false)); - } + } // class XR_Alib $alib = new XR_Alib(); @@ -148,17 +126,6 @@ $s = new xmlrpc_server( array( "function" => array(&$alib, 'xr_logout'), "signature" => array(array($xmlrpcString, $xmlrpcString)), "docstring" => "" - ), - "alib.getDir" => array( - "function" => array(&$alib, 'xr_getDir'), - "signature" => array(array($xmlrpcArray, $xmlrpcInt)), - "docstring" => "returns directory listing of object with given id" - ), - "alib.getPath" => array( - "function" => array(&$alib, 'xr_getPath'), - "signature" => array(array($xmlrpcArray, $xmlrpcInt)), - "docstring" => - "returns listing of object in path from rootnode to object with given id" ) )); diff --git a/src/modules/archiveServer/var/Archive.php b/src/modules/archiveServer/var/Archive.php index 4a6941413..fe300d147 100644 --- a/src/modules/archiveServer/var/Archive.php +++ b/src/modules/archiveServer/var/Archive.php @@ -85,10 +85,6 @@ class Archive extends XR_LocStor { if ($gunid == '') { $gunid = NULL; } - $parid = $this->_getHomeDirId($owner); - if (PEAR::isError($parid)) { - return $parid; - } $values = array( "filename" => $pars['name'], "filepath" => $fname, @@ -96,7 +92,7 @@ class Archive extends XR_LocStor { "gunid" => $pars['gunid'], "filetype" => "audioclip" ); - $storedFile = $this->bsPutFile($parid, $values); + $storedFile = $this->bsPutFile($values); if (PEAR::isError($storedFile)) { return $storedFile; } @@ -108,17 +104,13 @@ class Archive extends XR_LocStor { if ($gunid == '') { $gunid = NULL; } - $parid = $this->_getHomeDirId($owner); - if (PEAR::isError($parid)) { - return $parid; - } $values = array( "filename" => $pars['name'], "metadata" => $fname, "gunid" => $pars['gunid'], "filetype" => "playlist" ); - $storedFile = $this->bsPutFile($parid, $values); + $storedFile = $this->bsPutFile($values); if (PEAR::isError($storedFile)) { return $storedFile; } diff --git a/src/modules/htmlUI/var/html/ui_browser.php b/src/modules/htmlUI/var/html/ui_browser.php index 99b8c3558..885af3b48 100644 --- a/src/modules/htmlUI/var/html/ui_browser.php +++ b/src/modules/htmlUI/var/html/ui_browser.php @@ -275,32 +275,32 @@ if ($uiBrowser->userid) { $action = isset($_REQUEST['act']) ? $_REQUEST['act'] : null; switch ($action) { case "fileList": - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->fid)); - $Smarty->assign('fileList', TRUE); - - if ($_REQUEST['tree'] == 'Y') { - $Smarty->assign('showTree', TRUE); - } else{ - $Smarty->assign('showObjects', TRUE); - } - - $Smarty->assign('delOverride', $_REQUEST['delOverride']); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->fid)); +// $Smarty->assign('fileList', TRUE); +// +// if ($_REQUEST['tree'] == 'Y') { +// $Smarty->assign('showTree', TRUE); +// } else{ +// $Smarty->assign('showObjects', TRUE); +// } +// +// $Smarty->assign('delOverride', $_REQUEST['delOverride']); break; case "permissions": - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); - $Smarty->assign('permissions', $uiBrowser->permissions($uiBrowser->id)); - $Smarty->assign('fileList', TRUE); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); +// $Smarty->assign('permissions', $uiBrowser->permissions($uiBrowser->id)); +// $Smarty->assign('fileList', TRUE); break; case "uploadFileM": - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); $Smarty->assign('uploadform', $uiBrowser->uploadFileM($ui_fmask['uploadFileM'], $uiBrowser->id)); break; case "addFileData": case "addFileMData": - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; $langId = isset($_REQUEST['curr_langid']) ? $_REQUEST['curr_langid'] : null; $Smarty->assign('editItem', array('type' => 'audioclip', @@ -311,13 +311,13 @@ if ($uiBrowser->userid) { case "addWebstreamData": case "addWebstreamMData": - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); $Smarty->assign('editItem', array('type' => 'webstream', 'id' => $_REQUEST['id'], 'folderId' => $uiBrowser->fid, 'curr_langid' => $_REQUEST['curr_langid'])); break; case "editItem": $uiBrowser->SCRATCHPAD->addItem($_REQUEST['id']); - $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); +// $Smarty->assign('structure', $uiBrowser->getStructure($uiBrowser->id)); $Smarty->assign('editItem', array('type' => $uiBrowser->type, 'id' => $_REQUEST['id'], 'folderId' => $uiBrowser->fid, 'curr_langid' => $_REQUEST['curr_langid'])); break; @@ -341,6 +341,8 @@ if ($uiBrowser->userid) { break; case "HUBBROWSE": + //$HUBBROWSE = new uiHubBrowse($uiBrowser); + //$Smarty->assign('hubBrowseForm', $HUBBROWSE->browseForm($uiBrowser->id, $ui_fmask)); $Smarty->assign('hubBrowseForm', $uiBrowser->HUBBROWSE->browseForm($uiBrowser->id, $ui_fmask)); $Smarty->assign('showLibrary', TRUE); $Smarty->assign('isHub', TRUE); @@ -408,7 +410,7 @@ if ($uiBrowser->userid) { case "SCHEDULER.export": $Smarty->assign('act', $action); break; - + case "twitter.settings": $Smarty->assign('dynform', $uiBrowser->TWITTER->getSettingsForm()); $Smarty->assign('twitter', array( @@ -424,4 +426,4 @@ if ($uiBrowser->userid) { } } $Smarty->display('main.tpl'); -?> +?> \ No newline at end of file diff --git a/src/modules/htmlUI/var/html/ui_handler.php b/src/modules/htmlUI/var/html/ui_handler.php index 63e693aed..e0ae7b978 100644 --- a/src/modules/htmlUI/var/html/ui_handler.php +++ b/src/modules/htmlUI/var/html/ui_handler.php @@ -29,15 +29,15 @@ switch ($_REQUEST['act']) { $uiHandler->PLAYLIST->release(); $uiHandler->logout(TRUE); break; - + case "plupload": $ui_tmpid = $uiHandler->pluploadFile($_REQUEST); if($ui_tmpid) { $uiHandler->SCRATCHPAD->addItem($ui_tmpid); } ob_end_clean(); - - die('{"jsonrpc" : "2.0", "error" : {}}'); + + die('{"jsonrpc" : "2.0", "error" : {}}'); // file/webstream handling case "addFileData": @@ -62,22 +62,10 @@ switch ($_REQUEST['act']) { $uiHandler->SCRATCHPAD->reloadMetadata(); break; - case "newFolder": - $uiHandler->newFolder($_REQUEST["newname"], $uiHandler->id); - break; - case "rename": $uiHandler->rename($_REQUEST["newname"], $uiHandler->id); break; - case "move": - $uiHandler->move($_REQUEST["newPath"], $uiHandler->id); - break; - - case "copy": - $uiHandler->copy($_REQUEST["newPath"], $uiHandler->id); - break; - case "delete": if ($uiHandler->delete($_REQUEST['id'], $_REQUEST['delOverride'])) { if ($uiHandler->type != 'Folder') { @@ -153,10 +141,10 @@ switch ($_REQUEST['act']) { case "SEARCH.setOffset": $uiHandler->SEARCH->setOffset($_REQUEST['page']); break; - - case "BROWSE.refresh": - $uiHandler->BROWSE->refresh($_REQUEST); - break; + + case "BROWSE.refresh": + $uiHandler->BROWSE->refresh($_REQUEST); + break; case "BROWSE.setCategory": $uiHandler->BROWSE->setCategory($_REQUEST); @@ -449,7 +437,7 @@ switch ($_REQUEST['act']) { $_SESSION = array(); die(); break; - + case 'twitter.saveSettings': $uiHandler->TWITTER->saveSettings(); $uiHandler->redirUrl = UI_BROWSER.'?act=twitter.settings'; diff --git a/src/modules/htmlUI/var/localizer/auth.inc.php b/src/modules/htmlUI/var/localizer/auth.inc.php index 057970ce3..1264d9ce3 100644 --- a/src/modules/htmlUI/var/localizer/auth.inc.php +++ b/src/modules/htmlUI/var/localizer/auth.inc.php @@ -31,7 +31,8 @@ function login(&$data) return FALSE; } - $id = M2tree::GetObjId($data['PHP_AUTH_USER'], $gb->storId); + //$id = M2tree::GetObjId($data['PHP_AUTH_USER'], $gb->storId); + $id = $gb->storId; if (PEAR::isError($id)) { return FALSE; diff --git a/src/modules/htmlUI/var/ui_base.inc.php b/src/modules/htmlUI/var/ui_base.inc.php index ec12143a6..04fc532ba 100644 --- a/src/modules/htmlUI/var/ui_base.inc.php +++ b/src/modules/htmlUI/var/ui_base.inc.php @@ -113,7 +113,7 @@ function __autoload($p_className) $class_filename = $item['file']; require_once(dirname(__FILE__).'/'.$class_filename); break; - } + } } } @@ -218,7 +218,7 @@ class uiBase * @var string */ public $alertMsg; - + /** * This mapping keeps relation between uiBase::properties, * class names and filenames and is used in @@ -240,7 +240,7 @@ class uiBase 'CALENDAR' => array('class' => 'uicalendar', 'file' => 'ui_calendar.class.php'), array('class' => 'jscom', 'file' => 'ui_jscom.php'), 'TWITTER' => array('class' => 'uitwitter', 'file' => 'ui_twitter.class.php'), - array('class' => 'twitter', 'file' => 'lib/twitter.class.php') + array('class' => 'twitter', 'file' => 'lib/twitter.class.php') ); @@ -266,14 +266,10 @@ class uiBase if (isset($_REQUEST['id']) && is_numeric($_REQUEST['id'])) { $this->id = $_REQUEST['id']; } else { - $this->id = M2tree::GetObjId($this->login, $this->gb->storId); + $this->id = $this->gb->storId; } if (!is_null($this->id)) { - $parentId = M2tree::GetParent($this->id); - $this->pid = ($parentId != 1) ? $parentId : FALSE; $this->type = Greenbox::getFileType($this->id); - $this->fid = ($this->type == 'Folder') ? $this->id : $this->pid; - $this->homeid = M2tree::GetObjId($this->login, $this->gb->storId); } } @@ -284,7 +280,7 @@ class uiBase { $this->STATIONPREFS =& $_SESSION[UI_STATIONINFO_SESSNAME]; } - + /** * Dynamically initialize uiBase properties, * which keep objects (uiBase->SEARCH, $uiBase->BROWSE etc) @@ -295,13 +291,13 @@ class uiBase public function __get($p_class) { if (strtoupper($p_class !== $p_class)) { - return; + return; } - + if (!is_object($this->$p_class)) { if ($class_name = uiBase::$m_classMapping[$p_class]['class']) { $this->$p_class = new $class_name($this); - } + } } return $this->$p_class; } @@ -492,20 +488,6 @@ class uiBase if ($format=='text') { return "
".var_export($ia, TRUE)."
"; - } elseif ($format=='xml') { - return '!!!XML IS DEPRICATED!!! - - - - '.$this->_getFileTitle($id).' - '.$extent.' - - '; } return FALSE; } // fn analyzeFile @@ -592,23 +574,14 @@ class uiBase * @param unknown_type $id * @return string/FALSE */ - private function _getFileTitle($id) - { - if (is_array($arr = GreenBox::GetPath($id))) { - $file = array_pop($arr); - return $file['name']; - } - return FALSE; - } // fn _getFileTitle - - -// function _isFolder($id) +// private function _getFileTitle($id) // { -// if (strtolower(GreenBox::getFileType($id)) != 'folder') { -// return FALSE; +// if (is_array($arr = GreenBox::GetPath($id))) { +// $file = array_pop($arr); +// return $file['name']; // } -// return TRUE; -// } // fn _isFolder +// return FALSE; +// } // fn _getFileTitle public static function formElementEncode($str) diff --git a/src/modules/htmlUI/var/ui_browser.class.php b/src/modules/htmlUI/var/ui_browser.class.php index 2e6c586a4..c889f81b9 100644 --- a/src/modules/htmlUI/var/ui_browser.class.php +++ b/src/modules/htmlUI/var/ui_browser.class.php @@ -88,44 +88,6 @@ class uiBrowser extends uiBase { } // fn getUserInfo - /** - * Get directory-structure - * - * @param int $id - * local ID of start-directory - * @return array - * tree of directory with subs - */ - function getStructure($id) - { - $data = array( - 'pathdata' => GreenBox::GetPath($id, $this->sessid), - 'listdata' => BasicStor::GetObjType($id)=='Folder' ? $this->gb->listFolder($id, $this->sessid) : array(), - ); - $tree = isset($_REQUEST['tree']) ? $_REQUEST['tree'] : null; - if ($tree == 'Y') { - $tmp = M2tree::GetSubTree($id, $this->sessid); - foreach ($tmp as $key=>$val) { - $val['type'] = Greenbox::getFileType($val['id']); - $data['treedata'][$key] = $val; - } - } - if (PEAR::isError($data['listdata'])) { - $data['msg'] = $data['listdata']->getMessage(); - $data['listdata'] = array(); - return FALSE; - } - foreach ($data['listdata'] as $key=>$val) { - if ($val['type'] != 'Folder') { - $data['listdata'][$key]['title'] = $this->getMetadataValue($val['id'], UI_MDATA_KEY_TITLE); - } else { - $data['listdata'][$key]['title'] = $val['name']; - } - } - return $data; - } // fn getStructure - - /** * Create a form for file-upload. * @@ -200,25 +162,6 @@ class uiBrowser extends uiBase { } // fn webstreamForm - /** - * Get permissions for local object ID. - * - * @param int $id - * local ID (file/folder) - * @return array - */ - function permissions($id) - { - return array('pathdata' => GreenBox::GetPath($id), - 'perms' => Alib::GetObjPerms($id), - 'actions' => Alib::GetAllowedActions(BasicStor::GetObjType($id)), - 'subjects' => $this->gb->getSubjects(), - 'id' => $id, - 'loggedAs' => $this->login - ); - } - - /** * Call access method and show access path. * Example only - not really useable. @@ -378,7 +321,7 @@ class uiBrowser extends uiBase { function testStream($url) { global $CC_CONFIG; - + touch(UI_TESTSTREAM_MU3_TMP); $handle = fopen(UI_TESTSTREAM_MU3_TMP, "w"); fwrite($handle, $url); diff --git a/src/modules/htmlUI/var/ui_browser_init.php b/src/modules/htmlUI/var/ui_browser_init.php index eea88a371..96c96c645 100644 --- a/src/modules/htmlUI/var/ui_browser_init.php +++ b/src/modules/htmlUI/var/ui_browser_init.php @@ -37,8 +37,8 @@ $Smarty->assign('ACT', isset($_REQUEST['act'])?$_REQUEST['act']:null); $Smarty->assign('CONFIG', $CC_CONFIG); $Smarty->assign('START', array( 'id' => &$uiBrowser->id, - 'pid' => &$uiBrowser->pid, - 'fid' => &$uiBrowser->fid, + //'pid' => &$uiBrowser->pid, + //'fid' => &$uiBrowser->fid, 'sessid' => &$uiBrowser->sessid) ); $Smarty->assign('USER', array( @@ -48,8 +48,8 @@ $Smarty->assign('USER', array( ); $uiBrowser->loadStationPrefs($ui_fmask['stationPrefs']); $Smarty->assign('STATIONPREFS', $uiBrowser->STATIONPREFS); -$Smarty->assign_by_ref('_REQUEST', &$_REQUEST); - +$Smarty->assign_by_ref('_REQUEST', $_REQUEST); +$Smarty->assign_by_ref('_SESSION', $_SESSION); // retransfer incomplete formdata from SESSION to POST-data ######### if (isset($_SESSION['retransferFormData']) && is_array($_SESSION['retransferFormData'])) { foreach($_SESSION['retransferFormData'] as $k=>$v){ diff --git a/src/modules/htmlUI/var/ui_handler.class.php b/src/modules/htmlUI/var/ui_handler.class.php index 092d57915..6f57425ce 100644 --- a/src/modules/htmlUI/var/ui_handler.class.php +++ b/src/modules/htmlUI/var/ui_handler.class.php @@ -5,13 +5,9 @@ define('ACTION_BASE', '/actions' ) ; /** * HTML User Interface module * - - * @package Campcaster * @subpackage htmlUI - * @copyright 2010 Sourcefabric O.P.S. - */ class uiHandler extends uiBase { /** @@ -19,207 +15,217 @@ class uiHandler extends uiBase { */ public $redirUrl; - /** - * Initialize a new Browser Class - * Call uiBase constructor - * - */ - public function __construct() - { - parent::__construct(); - } // constructor + /** + * Initialize a new Browser Class + * Call uiBase constructor + * + */ + public function __construct() + { + parent::__construct(); + } // constructor - // --- authentication --- - /** - * Login to the storageServer. - * It set sessid to the cookie with name defined in ../conf.php - * - * @param array $formdata - * The REQUEST array. - */ - function login($formdata, $mask) - { - global $CC_CONFIG; - //$this->_cleanArray($_SESSION); + // --- authentication --- + /** + * Login to the storageServer. + * It set sessid to the cookie with name defined in ../conf.php + * + * @param array $formdata + * The REQUEST array. + */ + function login($formdata, $mask) + { + global $CC_CONFIG; + //$this->_cleanArray($_SESSION); - if (!$this->_validateForm($formdata, $mask)) { - $_SESSION['retransferFormData']['login'] = $formdata['login']; - $_SESSION['retransferFormData']['langid'] = $formdata['langid']; - $_SESSION['retransferFormData']['pass'] = "\n"; - $this->redirUrl = UI_BROWSER.'?popup[]=login'; - return FALSE; + if (!$this->_validateForm($formdata, $mask)) { + $_SESSION['retransferFormData']['login'] = $formdata['login']; + $_SESSION['retransferFormData']['langid'] = $formdata['langid']; + $_SESSION['retransferFormData']['pass'] = "\n"; + $this->redirUrl = UI_BROWSER.'?popup[]=login'; + return FALSE; + } + + $sessid = Alib::Login($formdata['login'], $formdata['pass']); + + if (!$sessid || PEAR::isError($sessid)){ + $this->_retMsg('Login failed.'); + $_SESSION['retransferFormData']['login'] = $formdata['login']; + $_SESSION['retransferFormData']['langid'] = $formdata['langid']; + $_SESSION['retransferFormData']['pass'] = "\n"; + $this->redirUrl = UI_BROWSER.'?popup[]=login'; + return FALSE; + } + + #setcookie($CC_CONFIG['authCookieName'], $sessid); + echo ""; + ob_flush(); + $this->sessid = $sessid; + $this->langid = $formdata['langid']; + $this->redirUrl = UI_BROWSER.'?popup[]=_2SCHEDULER&popup[]=_close'; + return TRUE; + } // fn login + + + /** + * Logut from storageServer, takes sessid from cookie + * + * @param boolean $trigger_login + * trigger login popup after logout + */ + function logout($trigger_login = FALSE) + { + global $CC_CONFIG; + Alib::Logout($this->sessid); + //setcookie($CC_CONFIG['authCookieName'], ''); + echo ""; + ob_clean(); + session_destroy(); + + if ($trigger_login) { + $this->redirUrl = UI_BROWSER.'?popup[]=_clear_parent&popup[]=login'; + } else { + $this->redirUrl = UI_BROWSER.'?popup[]=_clear_parent&popup[]=_close'; + } + } // fn logout + + + // --- files --- + function processFile($audio_file, $caller){ + + global $CC_CONFIG; + + if ($this->testForAudioType($audio_file) === FALSE) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "uses an unsupported file type."}}'); + } + + $md5 = md5_file($audio_file); + $duplicate = StoredFile::RecallByMd5($md5); + if ($duplicate) { + $_SESSION['plupload'] = "is duplicate"; + if (PEAR::isError($duplicate)) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}'); + } + else { + $duplicateName = $this->gb->getMetadataValue($duplicate->getId(), UI_MDATA_KEY_TITLE, $this->sessid); + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}'); + } + } + + $metadata = camp_get_audio_metadata($audio_file); + + if (PEAR::isError($metadata)) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}'); + } + + // #2196 no id tag -> use the original filename + if (basename($audio_file) == $metadata['dc:title']) { + $metadata['dc:title'] = basename($audio_file); + $metadata['ls:filename'] = basename($audio_file); + } + + // bsSetMetadataBatch doesnt like these values + unset($metadata['audio']); + unset($metadata['playtime_seconds']); + + $values = array( + "filename" => basename($audio_file), + "filepath" => $audio_file, + "filetype" => "audioclip", + "mime" => $metadata["dc:format"], + "md5" => $md5 + ); + $storedFile = $this->gb->putFile($values, $this->sessid); + + if (PEAR::isError($storedFile)) { + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $storedFile->getMessage() + '}}'); + } + + $result = $this->gb->bsSetMetadataBatch($storedFile->getId(), $metadata); + + return $storedFile->getId(); } - $sessid = Alib::Login($formdata['login'], $formdata['pass']); + function pluploadFile($data) + { + header('Content-type: text/plain; charset=UTF-8'); + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Cache-Control: no-store, no-cache, must-revalidate"); + header("Cache-Control: post-check=0, pre-check=0", false); + header("Pragma: no-cache"); - if (!$sessid || PEAR::isError($sessid)){ - $this->_retMsg('Login failed.'); - $_SESSION['retransferFormData']['login'] = $formdata['login']; - $_SESSION['retransferFormData']['langid'] = $formdata['langid']; - $_SESSION['retransferFormData']['pass'] = "\n"; - $this->redirUrl = UI_BROWSER.'?popup[]=login'; - return FALSE; - } + // Settings + $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; + $cleanupTargetDir = false; // Remove old files + $maxFileAge = 60 * 60; // Temp file age in seconds - #setcookie($CC_CONFIG['authCookieName'], $sessid); - echo ""; - ob_flush(); + // 5 minutes execution time + @set_time_limit(5 * 60); - $id = M2tree::GetObjId($formdata['login'], $this->gb->storId); + // Get parameters + $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; + $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; + $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; - if (PEAR::isError($id)) { - $this->_retMsg('Access to home directory failed.'); - $_SESSION['retransferFormData']['login'] = $formdata['login']; - $this->redirUrl = UI_BROWSER.'?popup[]=login'; - return FALSE; - } + // Clean the fileName for security reasons + //$fileName = preg_replace('/[^\w\._]+/', '', $fileName); - $this->sessid = $sessid; - $this->langid = $formdata['langid']; - $this->redirUrl = UI_BROWSER.'?popup[]=_2SCHEDULER&popup[]=_close'; + // Create target dir + if (!file_exists($targetDir)) { + @mkdir($targetDir); + } - return TRUE; - } // fn login + // Remove old temp files + if (is_dir($targetDir) && ($dir = opendir($targetDir))) { + while (($file = readdir($dir)) !== false) { + $filePath = $targetDir . DIRECTORY_SEPARATOR . $file; + // Remove temp files if they are older than the max age + if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge)) + @unlink($filePath); + } - /** - * Logut from storageServer, takes sessid from cookie - * - * @param boolean $trigger_login - * trigger login popup after logout - */ - function logout($trigger_login = FALSE) - { - global $CC_CONFIG; - Alib::Logout($this->sessid); - //setcookie($CC_CONFIG['authCookieName'], ''); - echo ""; - ob_clean(); - session_destroy(); - - if ($trigger_login) { - $this->redirUrl = UI_BROWSER.'?popup[]=_clear_parent&popup[]=login'; - } else { - $this->redirUrl = UI_BROWSER.'?popup[]=_clear_parent&popup[]=_close'; - } - } // fn logout - - function processFile($audio_file, $caller){ - - global $CC_CONFIG; - - if ($this->testForAudioType($audio_file) === FALSE) { - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "uses an unsupported file type."}}'); - } - - $md5 = md5_file($audio_file); - $duplicate = StoredFile::RecallByMd5($md5); - if ($duplicate) { - $_SESSION['plupload'] = "is duplicate"; - if (PEAR::isError($duplicate)) { - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}'); - } + closedir($dir); + } else { - $duplicateName = $this->gb->getMetadataValue($duplicate->getId(), UI_MDATA_KEY_TITLE, $this->sessid); - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named ' . $duplicateName . ' already exists in the storage server."}}'); - } - } - - $metadata = camp_get_audio_metadata($audio_file); - - if (PEAR::isError($metadata)) { - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $metadata->getMessage() + '}}'); - } - - // #2196 no id tag -> use the original filename - if (basename($audio_file) == $metadata['dc:title']) { - $metadata['dc:title'] = basename($audio_file); - $metadata['ls:filename'] = basename($audio_file); - } - - // bsSetMetadataBatch doesnt like these values - unset($metadata['audio']); - unset($metadata['playtime_seconds']); - - $values = array( - "filename" => basename($audio_file), - "filepath" => $audio_file, - "filetype" => "audioclip", - "mime" => $metadata["dc:format"], - "md5" => $md5 - ); - $storedFile = $this->gb->putFile(NULL, $values, $this->sessid); - - if (PEAR::isError($storedFile)) { - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' + $storedFile->getMessage() + '}}'); - } - - $result = $this->gb->bsSetMetadataBatch($storedFile->getId(), $metadata); - - return $storedFile->getId(); - } - - function pluploadFile($data) - { - header('Content-type: text/plain; charset=UTF-8'); - header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); - header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - header("Cache-Control: no-store, no-cache, must-revalidate"); - header("Cache-Control: post-check=0, pre-check=0", false); - header("Pragma: no-cache"); - - // Settings - $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; - $cleanupTargetDir = false; // Remove old files - $maxFileAge = 60 * 60; // Temp file age in seconds - - // 5 minutes execution time - @set_time_limit(5 * 60); - - // Get parameters - $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; - $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; - $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ''; - - // Clean the fileName for security reasons - //$fileName = preg_replace('/[^\w\._]+/', '', $fileName); - - // Create target dir - if (!file_exists($targetDir)) { - @mkdir($targetDir); - } - - // Remove old temp files - if (is_dir($targetDir) && ($dir = opendir($targetDir))) { - while (($file = readdir($dir)) !== false) { - $filePath = $targetDir . DIRECTORY_SEPARATOR . $file; - - // Remove temp files if they are older than the max age - if (preg_match('/\\.tmp$/', $file) && (filemtime($filePath) < time() - $maxFileAge)) - @unlink($filePath); + die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); } - closedir($dir); - } - else { - die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}'); - } + // Look for the content type header + if (isset($_SERVER["HTTP_CONTENT_TYPE"])) + $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; - // Look for the content type header - if (isset($_SERVER["HTTP_CONTENT_TYPE"])) - $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; + if (isset($_SERVER["CONTENT_TYPE"])) + $contentType = $_SERVER["CONTENT_TYPE"]; - if (isset($_SERVER["CONTENT_TYPE"])) - $contentType = $_SERVER["CONTENT_TYPE"]; + if (strpos($contentType, "multipart") !== false) { + if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { + // Open temp file + $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); + if ($out) { + // Read binary input stream and append it to temp file + $in = fopen($_FILES['file']['tmp_name'], "rb"); - if (strpos($contentType, "multipart") !== false) { - if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) { + if ($in) { + while ($buff = fread($in, 4096)) + fwrite($out, $buff); + } else + die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); + + fclose($out); + unlink($_FILES['file']['tmp_name']); + } else + die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); + } else + die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); + } else { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if ($out) { // Read binary input stream and append it to temp file - $in = fopen($_FILES['file']['tmp_name'], "rb"); + $in = fopen("php://input", "rb"); if ($in) { while ($buff = fread($in, 4096)) @@ -228,604 +234,515 @@ class uiHandler extends uiBase { die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); fclose($out); - unlink($_FILES['file']['tmp_name']); + return $this->processFile($targetDir . DIRECTORY_SEPARATOR . $fileName); + } else die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); - } else - die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}'); - } else { - // Open temp file - $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); - if ($out) { - // Read binary input stream and append it to temp file - $in = fopen("php://input", "rb"); - - if ($in) { - while ($buff = fread($in, 4096)) - fwrite($out, $buff); - } else - die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}'); - - fclose($out); - return $this->processFile($targetDir . DIRECTORY_SEPARATOR . $fileName); - - } else - die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}'); - } - - // Return JSON-RPC response - die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); - } - - - // --- files --- - /** - * Provides file upload and store it to the storage - * - * @param array $formdata - * submitted text and file - */ - function uploadFile($formdata, $mask, $replace=NULL) - { - global $CC_CONFIG; - if ($this->testForAudioType($formdata['mediafile']['name']) === FALSE) { - if (UI_ERROR) { - $this->_retMsg('"$1" uses an unsupported file type.', $formdata['mediafile']['name']); } - $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; - return FALSE; + + // Return JSON-RPC response + die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}'); } - $id = $formdata['id']; - $folderId = $formdata['folderId']; + /** + * Provides file upload and store it to the storage + * + * @param array $formdata + * submitted text and file + */ + function uploadFile($formdata, $mask, $replace=NULL) + { + global $CC_CONFIG; + if ($this->testForAudioType($formdata['mediafile']['name']) === FALSE) { + if (UI_ERROR) { + $this->_retMsg('"$1" uses an unsupported file type.', $formdata['mediafile']['name']); + } + $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; + return FALSE; + } - + $id = $formdata['id']; + $folderId = $formdata['folderId']; - if (Greenbox::getFileType($folderId) != 'Folder') { - $this->_retMsg('The target is not a folder: ' . $folderId . ' id: ' . $id); + if (Greenbox::getFileType($folderId) != 'Folder') { + $this->_retMsg('The target is not a folder.'); + $this->redirUrl = UI_BROWSER."?act=fileList"; + return FALSE; + } - $this->redirUrl = UI_BROWSER."?act=fileList"; - return FALSE; - } + if (!$this->_validateForm($formdata, $mask)) { + $this->redirUrl = UI_BROWSER."?act=editFile&id=".$id; + return FALSE; + } - if (!$this->_validateForm($formdata, $mask)) { - $this->redirUrl = UI_BROWSER."?act=editFile&id=".$id; - return FALSE; - } + $md5 = md5_file($formdata['mediafile']['tmp_name']); + $duplicate = StoredFile::RecallByMd5($md5); + if ($duplicate) { + if (PEAR::isError($duplicate)) { + $this->_retMsg($duplicate->getMessage()); + $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; + return FALSE; + } else { + $duplicateName = $this->gb->getMetadataValue($duplicate->getId(), UI_MDATA_KEY_TITLE, $this->sessid); + $this->_retMsg('An identical audioclip named "$1" already exists in the storage server.', $duplicateName); + $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; + return FALSE; + } + } - $md5 = md5_file($formdata['mediafile']['tmp_name']); - $duplicate = StoredFile::RecallByMd5($md5); - if ($duplicate) { - if (PEAR::isError($duplicate)) { - $this->_retMsg($duplicate->getMessage()); - $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; - return FALSE; - } else { - $duplicateName = $this->gb->getMetadataValue($duplicate->getId(), UI_MDATA_KEY_TITLE, $this->sessid); - $this->_retMsg('An identical audioclip named "$1" already exists in the storage server.', $duplicateName); - $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; - return FALSE; - } - } + $metadata = camp_get_audio_metadata($formdata['mediafile']['tmp_name']); + if (PEAR::isError($metadata)) { + $this->_retMsg($metadata->getMessage()); + $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; + return FALSE; + } + // #2196 no id tag -> use the original filename + if (basename($formdata['mediafile']['tmp_name']) == $metadata['dc:title']) { + $metadata['dc:title'] = $formdata['mediafile']['name']; + $metadata['ls:filename'] = $formdata['mediafile']['name']; + } - $metadata = camp_get_audio_metadata($formdata['mediafile']['tmp_name']); - if (PEAR::isError($metadata)) { - $this->_retMsg($metadata->getMessage()); - $this->redirUrl = UI_BROWSER."?act=addFileData&folderId=".$formdata['folderId']; - return FALSE; - } - // #2196 no id tag -> use the original filename - if (basename($formdata['mediafile']['tmp_name']) == $metadata['dc:title']) { - $metadata['dc:title'] = $formdata['mediafile']['name']; - $metadata['ls:filename'] = $formdata['mediafile']['name']; - } + // bsSetMetadataBatch doesnt like these values + unset($metadata['audio']); + unset($metadata['playtime_seconds']); - // bsSetMetadataBatch doesnt like these values - unset($metadata['audio']); - unset($metadata['playtime_seconds']); + $tmpgunid = md5(microtime().$_SERVER['SERVER_ADDR'].rand()."org.mdlf.campcaster"); + $ntmp = $CC_CONFIG['bufferDir'].'/'.$tmpgunid; + move_uploaded_file($formdata['mediafile']['tmp_name'], $ntmp); + chmod($ntmp, 0664); - $tmpgunid = md5(microtime().$_SERVER['SERVER_ADDR'].rand()."org.mdlf.campcaster"); - $ntmp = $CC_CONFIG['bufferDir'].'/'.$tmpgunid; - move_uploaded_file($formdata['mediafile']['tmp_name'], $ntmp); - chmod($ntmp, 0664); - - $values = array( + $values = array( "filename" => $formdata['mediafile']['name'], "filepath" => $ntmp, "filetype" => "audioclip", "mime" => $metadata["dc:format"], "md5" => $md5 - ); - $storedFile = $this->gb->putFile($folderId, $values, $this->sessid); - @unlink($ntmp); + ); + $storedFile = $this->gb->putFile($values, $this->sessid); + @unlink($ntmp); - if (PEAR::isError($storedFile)) { - $this->_retMsg($storedFile->getMessage()); - $this->redirUrl = UI_BROWSER."?act=editFile&id=".$id; - return FALSE; - } + if (PEAR::isError($storedFile)) { + $this->_retMsg($storedFile->getMessage()); + $this->redirUrl = UI_BROWSER."?act=editFile&id=".$id; + return FALSE; + } - $result = $this->gb->bsSetMetadataBatch($storedFile->getId(), $metadata); + $result = $this->gb->bsSetMetadataBatch($storedFile->getId(), $metadata); - $this->redirUrl = UI_BROWSER."?act=addFileMData&id=".$storedFile->getId(); - $this->_retMsg('Audioclip has been uploaded successfully.'); - $this->_retMsg('Now please complete metadata about the clip.'); - - return $storedFile->getId(); - } // fn uploadFile + $this->redirUrl = UI_BROWSER."?act=addFileMData&id=".$storedFile->getId(); + $this->_retMsg('Audioclip has been uploaded successfully.'); + $this->_retMsg('Now please complete metadata about the clip.'); + + return $storedFile->getId(); + } // fn uploadFile - function testForAudioType($filename) - { - global $CC_CONFIG; - foreach ($CC_CONFIG['file_types'] as $t) { - if (preg_match('/'.str_replace('/', '\/', $t).'$/i', $filename)) { - return TRUE; - } - } - return FALSE; - } + function testForAudioType($filename) + { + global $CC_CONFIG; + foreach ($CC_CONFIG['file_types'] as $t) { + if (preg_match('/'.str_replace('/', '\/', $t).'$/i', $filename)) { + return TRUE; + } + } + return FALSE; + } - /** - * @param unknown_type $id - * @param unknown_type $langid - * @return void - */ - function translateMetadata($id, $langid=UI_DEFAULT_LANGID) - { - include(dirname(__FILE__).'/formmask/metadata.inc.php'); + /** + * @param unknown_type $id + * @param unknown_type $langid + * @return void + */ + function translateMetadata($id, $langid=UI_DEFAULT_LANGID) + { + include(dirname(__FILE__).'/formmask/metadata.inc.php'); - $ia = $this->gb->analyzeFile($id, $this->sessid); - if (PEAR::isError($ia)) { - $this->_retMsg($ia->getMessage()); - return; - } - // This is really confusing: the import script does not do it - // this way. Which way is the right way? - $this->setMetadataValue($id, UI_MDATA_KEY_DURATION, Playlist::secondsToPlaylistTime($ia['playtime_seconds'])); - // $this->setMetadataValue($id, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_FILE); + $ia = $this->gb->analyzeFile($id, $this->sessid); + if (PEAR::isError($ia)) { + $this->_retMsg($ia->getMessage()); + return; + } + // This is really confusing: the import script does not do it + // this way. Which way is the right way? + $this->setMetadataValue($id, UI_MDATA_KEY_DURATION, Playlist::secondsToPlaylistTime($ia['playtime_seconds'])); +// $this->setMetadataValue($id, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_FILE); - // some data from raw audio - // if (isset($ia['audio']['channels'])) { - // $this->setMetadataValue($id, UI_MDATA_KEY_CHANNELS, $ia['audio']['channels']); - // } - // if (isset($ia['audio']['sample_rate'])) { - // $this->setMetadataValue($id, UI_MDATA_KEY_SAMPLERATE, $ia['audio']['sample_rate']); - // } - // if (isset($ia['audio']['bitrate'])) { - // $this->setMetadataValue($id, UI_MDATA_KEY_BITRATE, $ia['audio']['bitrate']); - // } - // if (isset($ia['audio']['codec'])) { - // $this->setMetadataValue($id, UI_MDATA_KEY_ENCODER, $ia['audio']['codec']); - // } + // some data from raw audio +// if (isset($ia['audio']['channels'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_CHANNELS, $ia['audio']['channels']); +// } +// if (isset($ia['audio']['sample_rate'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_SAMPLERATE, $ia['audio']['sample_rate']); +// } +// if (isset($ia['audio']['bitrate'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_BITRATE, $ia['audio']['bitrate']); +// } +// if (isset($ia['audio']['codec'])) { +// $this->setMetadataValue($id, UI_MDATA_KEY_ENCODER, $ia['audio']['codec']); +// } - // from id3 Tags - // loop main, music, talk - foreach ($mask['pages'] as $key => $val) { - // loop through elements - foreach ($mask['pages'][$key] as $k => $v) { - if (isset($v['element']) && isset($ia[$v['element']])) { - $this->setMetadataValue($id, $v['element'], $ia[$v['element']], $langid); - } - } - } - } + // from id3 Tags + // loop main, music, talk + foreach ($mask['pages'] as $key => $val) { + // loop through elements + foreach ($mask['pages'][$key] as $k => $v) { + if (isset($v['element']) && isset($ia[$v['element']])) { + $this->setMetadataValue($id, $v['element'], $ia[$v['element']], $langid); + } + } + } + } - /** - * Provides file upload and store it to the storage - * - * @param array $formdata, submitted text and file - * @param unknown $mask - */ - function addWebstream($formdata, $mask) - { - $id = $formdata['id']; - $folderId = $formdata['folderId']; + /** + * Provides file upload and store it to the storage + * + * @param array $formdata, submitted text and file + * @param unknown $mask + */ + function addWebstream($formdata, $mask) + { + $id = $formdata['id']; + $folderId = $formdata['folderId']; - if (Greenbox::getFileType($folderId) != 'Folder') { - $this->_retMsg ('The target is not a folder.'); - $this->redirUrl = UI_BROWSER."?act=fileList"; - return FALSE; - } - if (!$this->_validateForm($formdata, $mask)) { - $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; - return FALSE; - } + if (Greenbox::getFileType($folderId) != 'Folder') { + $this->_retMsg ('The target is not a folder.'); + $this->redirUrl = UI_BROWSER."?act=fileList"; + return FALSE; + } + if (!$this->_validateForm($formdata, $mask)) { + $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; + return FALSE; + } - $r = $this->gb->storeWebstream($folderId, $formdata['title'], NULL, $this->sessid, NULL, $formdata['url']); + $r = $this->gb->storeWebstream($formdata['title'], NULL, $this->sessid, NULL, $formdata['url']); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; - return FALSE; - } + if (PEAR::isError($r)) { + $this->_retMsg($r->getMessage()); + $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; + return FALSE; + } - $extent = sprintf('%02d', $formdata['length']['H']).':'.sprintf('%02d', $formdata['length']['i']).':'.sprintf('%02d', $formdata['length']['s']).'.000000'; + $extent = sprintf('%02d', $formdata['length']['H']).':'.sprintf('%02d', $formdata['length']['i']).':'.sprintf('%02d', $formdata['length']['s']).'.000000'; - $this->setMetadataValue($r, UI_MDATA_KEY_TITLE, $formdata['title']); - $this->setMetadataValue($r, UI_MDATA_KEY_DURATION, $extent); - $this->setMetadataValue($r, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_STREAM); + $this->setMetadataValue($r, UI_MDATA_KEY_TITLE, $formdata['title']); + $this->setMetadataValue($r, UI_MDATA_KEY_DURATION, $extent); + $this->setMetadataValue($r, UI_MDATA_KEY_FORMAT, UI_MDATA_VALUE_FORMAT_STREAM); - $this->redirUrl = UI_BROWSER."?act=addWebstreamMData&id=$r"; - $this->_retMsg('Webstream data has been saved.'); - $this->_retMsg('Now please complete metadata about the clip.'); + $this->redirUrl = UI_BROWSER."?act=addWebstreamMData&id=$r"; + $this->_retMsg('Webstream data has been saved.'); + $this->_retMsg('Now please complete metadata about the clip.'); - return $r; - } // fn addWebstream + return $r; + } // fn addWebstream - function editWebstream($formdata, $mask) - { - $id = $formdata['id']; - if (!$this->_validateForm($formdata, $mask)) { - $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; - return FALSE; - } - $extent = sprintf('%02d', $formdata['length']['H']).':'.sprintf('%02d', $formdata['length']['i']).':'.sprintf('%02d', $formdata['length']['s']).'.000000'; + function editWebstream($formdata, $mask) + { + $id = $formdata['id']; + if (!$this->_validateForm($formdata, $mask)) { + $this->redirUrl = UI_BROWSER."?act=editWebstream&id=".$id; + return FALSE; + } + $extent = sprintf('%02d', $formdata['length']['H']).':'.sprintf('%02d', $formdata['length']['i']).':'.sprintf('%02d', $formdata['length']['s']).'.000000'; - $this->setMetadataValue($id, UI_MDATA_KEY_TITLE, $formdata['title']); - $this->setMetadataValue($id, UI_MDATA_KEY_URL, $formdata['url']); - $this->setMetadataValue($id, UI_MDATA_KEY_DURATION, $extent); + $this->setMetadataValue($id, UI_MDATA_KEY_TITLE, $formdata['title']); + $this->setMetadataValue($id, UI_MDATA_KEY_URL, $formdata['url']); + $this->setMetadataValue($id, UI_MDATA_KEY_DURATION, $extent); - $this->redirUrl = UI_BROWSER.'?act=editItem&id='.$formdata['id']; - $this->_retMsg('Webstream metadata has been updated.'); + $this->redirUrl = UI_BROWSER.'?act=editItem&id='.$formdata['id']; + $this->_retMsg('Webstream metadata has been updated.'); - return TRUE; - } // fn editWebstream + return TRUE; + } // fn editWebstream - /** - * Sava Meatadata from form. - * - * @param array $formdata - */ - function editMetaData($formdata) - { - include(dirname(__FILE__).'/formmask/metadata.inc.php'); - $id = $formdata['id']; - $curr_langid = $formdata['curr_langid']; - $this->redirUrl = UI_BROWSER."?act=editItem&id=$id&curr_langid=".$formdata['target_langid']; + /** + * Sava Meatadata from form. + * + * @param array $formdata + */ + function editMetaData($formdata) + { + include(dirname(__FILE__).'/formmask/metadata.inc.php'); + $id = $formdata['id']; + $curr_langid = $formdata['curr_langid']; + $this->redirUrl = UI_BROWSER."?act=editItem&id=$id&curr_langid=".$formdata['target_langid']; - foreach ($mask['pages'] as $key => $val) { - foreach ($mask['pages'][$key] as $k => $v) { - $formdata[$key.'___'.uiBase::formElementEncode($v['element'])] ? $mData[uiBase::formElementDecode($v['element'])] = $formdata[$key.'___'.uiBase::formElementEncode($v['element'])] : NULL; - } - } + foreach ($mask['pages'] as $key => $val) { + foreach ($mask['pages'][$key] as $k => $v) { + $formdata[$key.'___'.uiBase::formElementEncode($v['element'])] ? $mData[uiBase::formElementDecode($v['element'])] = $formdata[$key.'___'.uiBase::formElementEncode($v['element'])] : NULL; + } + } - if (!count($mData)) { - return; - } + if (!count($mData)) { + return; + } - foreach ($mData as $key => $val) { - $r = $this->setMetadataValue($id, $key, $val, $curr_langid); - if (PEAR::isError($r)) { - $this->_retMsg('Unable to set "$1" to value "$2".', $key, $val); - } - } + foreach ($mData as $key => $val) { + $r = $this->setMetadataValue($id, $key, $val, $curr_langid); + if (PEAR::isError($r)) { + $this->_retMsg('Unable to set "$1" to value "$2".', $key, $val); + } + } - $this->_retMsg('Audioclip metadata has been updated.'); - } // fn editMetadata + $this->_retMsg('Audioclip metadata has been updated.'); + } // fn editMetadata - /** - * Create new folder in the storage - * - * @param string $name - * name for the new folder - * @param int $id - * local id to create folder in - */ - function newFolder($name, $id) - { - $r = $this->gb->createFolder($id, $name, $this->sessid); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - } - $this->redirUrl = UI_BROWSER.'?act=fileList&id='.$this->id; - } // fn newFolder + /** + * Change the name of file or folder + * + * @param string $newname + * new name for the file or folder + * @param int $id + * destination folder id + */ +// function rename($newname, $id) +// { +// $r = $this->gb->renameFile($id, $newname, $this->sessid); +// if (PEAR::isError($r)) { +// $this->_retMsg($r->getMessage()); +// } +// //$this->redirUrl = UI_BROWSER."?act=fileList&id=".$this->pid; +// $this->redirUrl = UI_BROWSER."?act=fileList&id=".$this->pid; +// } // fn rename - /** - * Change the name of file or folder - * - * @param string $newname - * new name for the file or folder - * @param int $id - * destination folder id - */ - function rename($newname, $id) - { - $r = $this->gb->renameFile($id, $newname, $this->sessid); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - } - $this->redirUrl = UI_BROWSER."?act=fileList&id=".$this->pid; - } // fn rename + /** + * Delete a stored file. + * + * @param mixed $id + * either an int or an array of ints which are + * IDs of files or folders to delete. + * @param boolean $delOverride + * this parameter is not used + * @return boolean + */ + function delete($id, $delOverride=FALSE) + { + $this->redirUrl = UI_BROWSER."?popup[]=_reload_parent&popup[]=_close"; + + if (is_array($id)) { + $ids = $id; + } else { + $ids[] = $id; + } + + foreach ($ids as $id) { + if (Greenbox::getFileType($id) == 'playlist') { + $r = $this->gb->deletePlaylist($id, $this->sessid); + } else { + $r = $this->gb->deleteFile($id, $this->sessid); + } + + if (PEAR::isError($r)) { + $this->_retMsg($r->getMessage()); + return FALSE; + } + } + + return TRUE; + } // fn delete - /** - * Move file to another folder - * - * @todo format of destination path should be properly defined - * - * @param string $newPath - * destination relative path - * @param int $id - * destination folder id - */ - function move($newPath, $id) - { - $newPath = urldecode($newPath); - $did = $this->gb->getObjIdFromRelPath($id, $newPath); - $r = $this->gb->moveFile($id, $did, $this->sessid); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - $this->redirUrl = UI_BROWSER."?act=fileList&id=".$this->pid; - } else { - $this->redirUrl = UI_BROWSER."?act=fileList&id=".$did; - } - } // fn move + /** + * Call access method and show access path. + * Example only - not really useable. + * @todo resource should be released by release method call + * + * @param int $id + * local id of accessed file + */ + function getFile($id) + { + $r = $this->gb->access($id, $this->sessid); + if (PEAR::isError($r)) { + $this->_retMsg($r->getMessage()); + } else { + echo $r; + } + } // fn getFile - /** - * Copy file to another folder - * - * @todo format of destinantion path should be properly defined - * - * @param string $newPath - * destination relative path - * @param int $id - * destination folder id - */ - function copy($newPath, $id) - { - $newPath = urldecode($newPath); - $did = $this->gb->getObjIdFromRelPath($id, $newPath); - $r = $this->gb->copyFile($id, $did, $this->sessid); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - $this->redirUrl = UI_BROWSER."?act=fileList&id=".$this->pid; - } else { - $this->redirUrl = UI_BROWSER."?act=fileList&id=".$did; - } - } // fn copy + /** + * Show file's metadata as XML + * + * @param int $id + * local id of stored file + */ + function getMdata($id) + { + header("Content-type: text/xml"); + $r = $this->gb->getMetadata($id, $this->sessid); + print_r($r); + } - /** - * Delete a stored file. - * - * @param mixed $id - * either an int or an array of ints which are - * IDs of files or folders to delete. - * @param boolean $delOverride - * this parameter is not used - * @return boolean - */ - function delete($id, $delOverride=FALSE) - { - $this->redirUrl = UI_BROWSER."?popup[]=_reload_parent&popup[]=_close"; - - if (is_array($id)) { - $ids = $id; - } else { - $ids[] = $id; - } - - foreach ($ids as $id) { - if (Greenbox::getFileType($id) == 'playlist') { - $r = $this->gb->deletePlaylist($id, $this->sessid); - } else { - $r = $this->gb->deleteFile($id, $this->sessid); - } - - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - return FALSE; - } - } - - return TRUE; - } // fn delete + // --- perms --- + /** + * Add new permission record + * + * @param int $subj + * local user/group id + * @param string $permAction + * type of action from set predefined in conf.php + * @param int $id + * local id of file/object + * @param char $allowDeny + * 'A' or 'D' + * @return boolean + */ + function addPerm($subj, $permAction, $id, $allowDeny) + { + if (PEAR::isError( + $this->gb->addPerm( + $subj, $permAction, $id, $allowDeny, $this->sessid + ) + )) { + $this->_retMsg('Access denied.'); + return FALSE; + } + $this->redirUrl = UI_BROWSER.'?act=permissions&id='.$id; + return TRUE; + } // fn addPerm - /** - * Call access method and show access path. - * Example only - not really useable. - * @todo resource should be released by release method call - * - * @param int $id - * local id of accessed file - */ - function getFile($id) - { - $r = $this->gb->access($id, $this->sessid); - if (PEAR::isError($r)) { - $this->_retMsg($r->getMessage()); - } else { - echo $r; - } - } // fn getFile + /** + * Remove permission record + * + * @param int $permid + * local id of permission record + * @param int $oid + * local id of object to handle + */ + function removePerm($permid, $oid) + { + if (PEAR::isError($this->gb->removePerm($permid, NULL, NULL, $this->sessid))) { + $this->_retMsg('Access denied.'); + return FALSE; + } + $this->redirUrl = UI_BROWSER.'?act=permissions&id='.$oid; + return TRUE; + } // fn removePerm - /** - * Show file's metadata as XML - * - * @param int $id - * local id of stored file - */ - function getMdata($id) - { - header("Content-type: text/xml"); - $r = $this->gb->getMetadata($id, $this->sessid); - print_r($r); - } + /** + * @param unknown_type $formdata + * @param array $mask + * @return boolean + */ + function _validateForm($formdata, $mask) + { + $form = new HTML_QuickForm('validation', UI_STANDARD_FORM_METHOD, UI_HANDLER); + uiBase::parseArrayToForm($form, $mask, 'server'); + if (!$form->validate()) { + $_SESSION['retransferFormData'] = $_REQUEST; + return FALSE; + } + // test for uploaded files bacause HTMLQuickForm::validate() ignores them + if (is_array($form->_submitFiles)) { + $was_error = FALSE; + foreach ($form->_submitFiles as $key => $val) { + if ($val['error']) { + + switch ($val['error']) { + case 1: + $was_error = TRUE; + $this->_retMsg('The uploaded filer is bigger than allowed in system settings. See "Help", chapter "Troubleshooting" for more information.'); + break; + case 2: + $was_error = TRUE; + $this->_retMsg('The uploaded filer is bigger than allowed in system settings. See "Help", chapter "Troubleshooting" for more information.'); + break; + case 3: + $was_error = TRUE; + $this->_retMsg('Upload of file "$1" was incomplete.', $mask[$key]['label']); + break; + case 4: + if ($mask[$key]['required']) { + $was_error = TRUE; + $this->_retMsg('File "$1" has not been uploaded.', $mask[$key]['label']); + } + break; + } + } + } + if ($was_error) { + $_SESSION['retransferFormData'] = array_merge($_REQUEST, $_FILES); + #$this->_retMsg('Invalid or incomplete form data.'); + return FALSE; + } + } + /* + foreach($mask as $k) { + if ($k['type']=='file' && $k['required']==TRUE) { + if ($_FILES[$k['element']]['error']) { + $_SESSION['retransferFormData'] = array_merge($_REQUEST, $_FILES); + return FALSE; + } + } + } */ + return TRUE; + } // fn _validateForm - // --- perms --- - /** - * Add new permission record - * - * @param int $subj - * local user/group id - * @param string $permAction - * type of action from set predefined in conf.php - * @param int $id - * local id of file/object - * @param char $allowDeny - * 'A' or 'D' - * @return boolean - */ - function addPerm($subj, $permAction, $id, $allowDeny) - { - if (PEAR::isError( - $this->gb->addPerm( - $subj, $permAction, $id, $allowDeny, $this->sessid - ) - )) { - $this->_retMsg('Access denied.'); - return FALSE; - } - $this->redirUrl = UI_BROWSER.'?act=permissions&id='.$id; - return TRUE; - } // fn addPerm + /** + * @param array $formdata + * @param array $mask + * @return boolean + */ + function changeStationPrefs($formdata, $mask) + { + $this->redirUrl = UI_BROWSER; + if ($this->_validateForm($formdata, $mask) == FALSE) { + $this->_retMsg('Error while saving settings.'); + return FALSE; + } + foreach ($mask as $key => $val) { + if (isset($val['isPref']) && $val['isPref']) { + if (!empty($formdata[$val['element']])) { + $result = $this->gb->saveGroupPref($this->sessid, 'StationPrefs', $val['element'], $formdata[$val['element']]); + if (PEAR::isError($result)) + $this->_retMsg('Error while saving settings.'); + } else { + $this->gb->delGroupPref($this->sessid, 'StationPrefs', $val['element']); + } + } + if (isset($val['type']) + && ($val['type'] == 'file') + && ($val['element'] == "stationlogo") + && !empty($formdata[$val['element']]['name'])) { + $stationLogoPath = $this->gb->loadGroupPref($this->sessid, 'StationPrefs', 'stationLogoPath'); + $filePath = $formdata[$val['element']]['tmp_name']; + if (function_exists("getimagesize")) { + $size = @getimagesize($filePath); + if ($size === FALSE) { + $this->_retMsg('Error while uploading logo: not an supported image format.'); + return FALSE; + } + if ( ($size[0] > 128) || ($size[1] > 128) ) { + $this->_retMsg('Error uploading logo: the logo can be no larger than 128x128.'); + return FALSE; + } + } + $success = @move_uploaded_file($filePath, $stationLogoPath); + if (!$success) { + $this->_retMsg('Error while uploading logo: could not move the file to the destination directory.'); + return FALSE; + } + } + } + $this->loadStationPrefs($mask, TRUE); + if (UI_VERBOSE) { + $this->_retMsg('Settings saved.'); + } - /** - * Remove permission record - * - * @param int $permid - * local id of permission record - * @param int $oid - * local id of object to handle - */ - function removePerm($permid, $oid) - { - if (PEAR::isError($this->gb->removePerm($permid, NULL, NULL, $this->sessid))) { - $this->_retMsg('Access denied.'); - return FALSE; - } - $this->redirUrl = UI_BROWSER.'?act=permissions&id='.$oid; - return TRUE; - } // fn removePerm - - - /** - * @param unknown_type $formdata - * @param array $mask - * @return boolean - */ - function _validateForm($formdata, $mask) - { - $form = new HTML_QuickForm('validation', UI_STANDARD_FORM_METHOD, UI_HANDLER); - uiBase::parseArrayToForm($form, $mask, 'server'); - if (!$form->validate()) { - $_SESSION['retransferFormData'] = $_REQUEST; - return FALSE; - } - // test for uploaded files bacause HTMLQuickForm::validate() ignores them - if (is_array($form->_submitFiles)) { - $was_error = FALSE; - foreach ($form->_submitFiles as $key => $val) { - if ($val['error']) { - - switch ($val['error']) { - case 1: - $was_error = TRUE; - $this->_retMsg('The uploaded filer is bigger than allowed in system settings. See "Help", chapter "Troubleshooting" for more information.'); - break; - case 2: - $was_error = TRUE; - $this->_retMsg('The uploaded filer is bigger than allowed in system settings. See "Help", chapter "Troubleshooting" for more information.'); - break; - case 3: - $was_error = TRUE; - $this->_retMsg('Upload of file "$1" was incomplete.', $mask[$key]['label']); - break; - case 4: - if ($mask[$key]['required']) { - $was_error = TRUE; - $this->_retMsg('File "$1" has not been uploaded.', $mask[$key]['label']); - } - break; - } - } - } - if ($was_error) { - $_SESSION['retransferFormData'] = array_merge($_REQUEST, $_FILES); - #$this->_retMsg('Invalid or incomplete form data.'); - return FALSE; - } - } - /* - foreach($mask as $k) { - if ($k['type']=='file' && $k['required']==TRUE) { - if ($_FILES[$k['element']]['error']) { - $_SESSION['retransferFormData'] = array_merge($_REQUEST, $_FILES); - return FALSE; - } - } - } */ - return TRUE; - } // fn _validateForm - - - /** - * @param array $formdata - * @param array $mask - * @return boolean - */ - function changeStationPrefs($formdata, $mask) - { - $this->redirUrl = UI_BROWSER; - - if ($this->_validateForm($formdata, $mask) == FALSE) { - $this->_retMsg('Error while saving settings.'); - return FALSE; - } - foreach ($mask as $key => $val) { - if (isset($val['isPref']) && $val['isPref']) { - if (!empty($formdata[$val['element']])) { - $result = $this->gb->saveGroupPref($this->sessid, 'StationPrefs', $val['element'], $formdata[$val['element']]); - if (PEAR::isError($result)) - $this->_retMsg('Error while saving settings.'); - } else { - $this->gb->delGroupPref($this->sessid, 'StationPrefs', $val['element']); - } - } - if (isset($val['type']) - && ($val['type'] == 'file') - && ($val['element'] == "stationlogo") - && !empty($formdata[$val['element']]['name'])) { - $stationLogoPath = $this->gb->loadGroupPref($this->sessid, 'StationPrefs', 'stationLogoPath'); - $filePath = $formdata[$val['element']]['tmp_name']; - if (function_exists("getimagesize")) { - $size = @getimagesize($filePath); - if ($size === FALSE) { - $this->_retMsg('Error while uploading logo: not an supported image format.'); - return FALSE; - } - if ( ($size[0] > 128) || ($size[1] > 128) ) { - $this->_retMsg('Error uploading logo: the logo can be no larger than 128x128.'); - return FALSE; - } - } - $success = @move_uploaded_file($filePath, $stationLogoPath); - if (!$success) { - $this->_retMsg('Error while uploading logo: could not move the file to the destination directory.'); - return FALSE; - } - } - } - $this->loadStationPrefs($mask, TRUE); - if (UI_VERBOSE) { - $this->_retMsg('Settings saved.'); - } - - return TRUE; - } // fn changeStationPrefs + return TRUE; + } // fn changeStationPrefs } // class uiHandler -?> +?> \ No newline at end of file diff --git a/src/modules/htmlUI/var/ui_playlist.class.php b/src/modules/htmlUI/var/ui_playlist.class.php index 9014d44d2..b2266dfe7 100644 --- a/src/modules/htmlUI/var/ui_playlist.class.php +++ b/src/modules/htmlUI/var/ui_playlist.class.php @@ -2,13 +2,9 @@ require_once("../../../storageServer/var/Playlist.php"); /** - - * @package Campcaster * @subpackage htmlUI - * @copyright 2010 Sourcefabric O.P.S. - */ class uiPlaylist { @@ -255,14 +251,14 @@ class uiPlaylist $fadeOut = NULL; $length = NULL; $clipstart = NULL; - + /* gstreamer bug: Warning: The clipEnd can't be bigger than ninety nine percent (99%) of the clipLength, this means also if no clipEnd is defined it should be 00:00:00.000000 and not the clipLength. $clipend = '00:00:00.000000'; */ - + if (!$elemIds) { if (UI_WARNING) { $this->Base->_retMsg('No item(s) selected.'); @@ -332,7 +328,7 @@ class uiPlaylist return FALSE; } $datetime = strftime('%Y-%m-%d %H:%M:%S'); - $plid = $this->Base->gb->createPlaylist($this->Base->homeid, $datetime, $this->Base->sessid); + $plid = $this->Base->gb->createPlaylist($datetime, $this->Base->sessid); if (!$plid) { $this->Base->_retMsg('Cannot create playlist.'); return FALSE; @@ -602,7 +598,7 @@ class uiPlaylist $mask['clipStart']['default'] = round($clipStartS); $mask['clipEnd']['default'] = round($clipEndS); for ($n=0; $n<=round($playLegthS); $n++) { - $options[$n] = date('i:s', $n); + $options[$n] = date('i:s', $n); } $mask['clipStart']['options'] = $options; $mask['clipLength']['options'] = $options; @@ -620,26 +616,26 @@ class uiPlaylist $form->accept($renderer); return $renderer->toArray(); } // fn setClipLengthForm - + function setClipLength($p_elemId, &$p_mask) { $form = new HTML_QuickForm('PL_setClipLengthForm', UI_STANDARD_FORM_METHOD, UI_HANDLER); uiBase::parseArrayToForm($form, $p_mask); - + if (!$form->validate()) { - return false; + return false; } $values = $form->exportValues(); $elem = $this->getCurrElement($values['elemId']); if (!$elem) { - return false; + return false; } - + $clipStart = GreenBox::secondsToPlaylistTime($values['clipStart']); $clipEnd = GreenBox::secondsToPlaylistTime($values['clipEnd']); - + $this->Base->gb->changeClipLength($this->token, $p_elemId, $clipStart, $clipEnd, $this->Base->sessid); - + } diff --git a/src/modules/storageAdmin/var/backup.php b/src/modules/storageAdmin/var/backup.php index b78eff98e..f49b4ff14 100644 --- a/src/modules/storageAdmin/var/backup.php +++ b/src/modules/storageAdmin/var/backup.php @@ -21,11 +21,12 @@ $stid = $bs->storId; function admDumpFolder(&$bs, $fid, $ind='') { - $name = M2tree::GetObjName($fid); - if (PEAR::isError($name)) { - echo $name->getMessage(); - exit; - } + // NOTE: need to fix this, removed due to tree removal +// $name = M2tree::GetObjName($fid); +// if (PEAR::isError($name)) { +// echo $name->getMessage(); +// exit; +// } $type = BasicStor::GetObjType($fid); if (PEAR::isError($type)) { echo $type->getMessage(); @@ -42,32 +43,6 @@ function admDumpFolder(&$bs, $fid, $ind='') } $pars['name'] = "$name"; switch ($type) { - case "Folder": - $farr = $bs->bsListFolder($fid); - if (PEAR::isError($farr)) { - echo $farr->getMessage(); - exit; - } - $res = ''; - foreach ($farr as $i => $folder) { - $fid2 = $folder['id']; - $res .= admDumpFolder($bs, $fid2, "$ind "); - } - if (!$res) { - return XML_Util::createTagFromArray(array( - 'namespace' => NSPACE, - 'localPart' => 'folder', - 'attributes'=> $pars, - )); - } else { - return XML_Util::createTagFromArray(array( - 'namespace' => NSPACE, - 'localPart' => 'folder', - 'attributes'=> $pars, - 'content' => $res, - ), FALSE); - } - break; case "audioclip": return XML_Util::createTagFromArray(array( 'namespace' => NSPACE, @@ -92,8 +67,8 @@ function admDumpFolder(&$bs, $fid, $ind='') default: return ""; } - } + function admDumpGroup(&$bs, $gid, $ind='') { $name = Subjects::GetSubjName($gid); diff --git a/src/modules/storageAdmin/var/campcaster-import.php b/src/modules/storageAdmin/var/campcaster-import.php index 94241b305..fdfb9ab53 100644 --- a/src/modules/storageAdmin/var/campcaster-import.php +++ b/src/modules/storageAdmin/var/campcaster-import.php @@ -27,7 +27,7 @@ function camp_import_error_handler() function printUsage() { - global $CC_CONFIG; + global $CC_CONFIG; echo "There are two ways to import audio files into Campcaster: linking\n"; echo "or copying.\n"; echo "\n"; @@ -106,7 +106,6 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = } $greenbox = new GreenBox(); - $parentId = M2tree::GetObjId(M2tree::GetRootNode()); $fileCount = 0; $duplicates = 0; @@ -226,7 +225,7 @@ function camp_import_audio_file($p_filepath, $p_importMode = null, $p_testOnly = "mime" => $metadata['dc:format'] ); // $timeBegin = microtime(true); - $storedFile = $greenbox->bsPutFile($parentId, $values, $doCopyFiles); + $storedFile = $greenbox->bsPutFile($values, $doCopyFiles); if (PEAR::isError($storedFile)) { import_err($storedFile, "Error in bsPutFile()"); echo var_export($metadata)."\n"; diff --git a/src/modules/storageAdmin/var/restore.php b/src/modules/storageAdmin/var/restore.php index 3e1a5f4cb..6fbf1da6c 100644 --- a/src/modules/storageAdmin/var/restore.php +++ b/src/modules/storageAdmin/var/restore.php @@ -40,25 +40,9 @@ function ls_restore_checkErr($r, $ln='') } } -function ls_restore_restoreObject($obj, $parid, $reallyInsert=TRUE){ +function ls_restore_restoreObject($obj, /*$parid,*/ $reallyInsert=TRUE){ global $tmpdir, $bs; switch ($obj['type']) { - case "folder"; - if ($reallyInsert) { - if (VERBOSE) { - echo " creating folder {$obj['name']} ...\n"; - } - $r = BasicStor::bsCreateFolder($parid, $obj['name']); - ls_restore_checkErr($r, __LINE__); - } else { - $r = $parid; - } - if (isset($obj['children']) && is_array($obj['children'])) { - foreach ($obj['children'] as $i => $ch) { - ls_restore_restoreObject($ch, $r); - } - } - break; case "audioClip"; case "webstream"; case "playlist"; @@ -87,7 +71,7 @@ function ls_restore_restoreObject($obj, $parid, $reallyInsert=TRUE){ "gunid" => $obj['gunid'], "filetype" => strtolower($obj['type']) ); - $r = $bs->bsPutFile($parid, $values); + $r = $bs->bsPutFile($values); ls_restore_checkErr($r, __LINE__); } break; @@ -117,7 +101,7 @@ $xmlTree = $parser->getTree(); /* ----------------------------------------- processing storageServer element */ $subjArr = FALSE; -$tree = FALSE; +//$tree = FALSE; foreach ($xmlTree->children as $i => $el) { switch ($el->name) { case "subjects": @@ -126,12 +110,12 @@ foreach ($xmlTree->children as $i => $el) { } $subjArr = $el->children; break; - case "folder": - if ($tree !== FALSE) { - echo "ERROR: unexpected folder element\n"; - } - $tree = ls_restore_processObject($el); - break; +// case "folder": +// if ($tree !== FALSE) { +// echo "ERROR: unexpected folder element\n"; +// } +// $tree = ls_restore_processObject($el); +// break; default: echo "ERROR: unknown element name {$el->name}\n"; exit; @@ -267,6 +251,6 @@ foreach ($groups as $grname => $group) { } /* -------------------------------------------------------- restoring objects */ -ls_restore_restoreObject($tree, $storId, FALSE); +ls_restore_restoreObject($tree, /*$storId,*/ FALSE); ?> \ No newline at end of file diff --git a/src/modules/storageServer/var/BasicStor.php b/src/modules/storageServer/var/BasicStor.php index 2be3a2f4b..f8d47a822 100644 --- a/src/modules/storageServer/var/BasicStor.php +++ b/src/modules/storageServer/var/BasicStor.php @@ -31,31 +31,12 @@ require_once("Transport.php"); */ //class BasicStor extends Alib { class BasicStor { - protected $rootId; + //protected $rootId; public $storId; public function __construct() { - $this->rootId = M2tree::GetRootNode(); - $this->storId = M2tree::GetObjId('StorageRoot', $this->rootId); - } - - - /** - * Create a virtual folder in the database. - * - * @param int $parid - * Parent id - * @param string $folderName - * Name for new folder - * @return int - * id of new folder - * @exception PEAR_Error - */ - public static function bsCreateFolder($parid, $folderName) - { - return BasicStor::AddObj($folderName , 'Folder', $parid); } @@ -71,17 +52,12 @@ class BasicStor { * @return int|PEAR_Error * ID of the StoredFile that was created. */ - public function bsPutFile($p_parentId, $p_values, $p_copyMedia=TRUE) + public function bsPutFile($p_values, $p_copyMedia=TRUE) { if (!isset($p_values['filetype']) || !isset($p_values['filename'])) { return NULL; } $ftype = strtolower($p_values['filetype']); - $id = BasicStor::AddObj($p_values['filename'], $ftype, $p_parentId); - if (PEAR::isError($id)) { - return $id; - } - $p_values['id'] = $id; $storedFile = StoredFile::Insert($p_values, $p_copyMedia); if (PEAR::isError($storedFile)) { $res = BasicStor::RemoveObj($id); @@ -109,7 +85,6 @@ class BasicStor { */ public function bsRenameFile($id, $newName) { - $parid = M2tree::GetParent($id); switch (BasicStor::GetObjType($id)) { case "audioclip": case "playlist": @@ -128,77 +103,7 @@ class BasicStor { case "File": default: } - return M2tree::RenameObj($id, $newName); - } - - - /** - * Move file - * - * @param int $id - * Virtual file's local id - * @param int $did - * Destination folder local id - * @return boolean/PEAR_Error - */ - public function bsMoveFile($id, $did) - { - $parid = M2tree::GetParent($id); - if (BasicStor::GetObjType($did) !== 'Folder') { - return PEAR::raiseError( - "BasicStor::moveFile: destination is not folder ($did)", - GBERR_WRTYPE - ); - } - switch (BasicStor::GetObjType($id)) { - case "audioclip": - case "playlist": - case "webstream": - case "File": - case "Folder": - return BasicStor::MoveObj($id, $did); - break; - default: - return PEAR::raiseError( - "BasicStor::moveFile: unsupported object to move, sorry.", - GBERR_WRTYPE - ); - } - } - - - /** - * Copy file - * - * @param int $id - * Virtual file's local id - * @param int $did - * Destination folder local id - * @return boolean|PEAR_Error - */ - public function bsCopyFile($id, $did) - { - $parid = M2tree::GetParent($id); - if (BasicStor::GetObjType($did) !== 'Folder') { - return PEAR::raiseError( - 'BasicStor::bsCopyFile: destination is not folder', - GBERR_WRTYPE - ); - } - switch (BasicStor::GetObjType($id)) { - case "audioclip": - case "playlist": - case "webstream": - case "File": - case "Folder": - return BasicStor::CopyObj($id, $did); - break; - default: - return PEAR::raiseError( - "BasicStor::moveFile: unsupported object to copy, sorry.", - GBERR_WRTYPE - ); - } + return TRUE; } @@ -257,10 +162,6 @@ class BasicStor { return $res; } // move to trash: - $did = M2tree::GetObjId($CC_CONFIG['TrashName'], $this->storId); - if (PEAR::isError($did)) { - return $did; - } switch (BasicStor::GetObjType($id)) { case "audioclip": case "playlist": @@ -269,10 +170,6 @@ class BasicStor { if (is_null($storedFile) || PEAR::isError($storedFile)) { return $storedFile; } - if (is_null($did)) { - return PEAR::raiseError("BasicStor::bsDeleteFile: ". - "trash not found", GBERR_NOTF); - } $res = $storedFile->setState('deleted'); if (PEAR::isError($res)) { return $res; @@ -280,8 +177,7 @@ class BasicStor { break; default: } - $res = $this->bsMoveFile($id, $did); - return $res; + return TRUE; } @@ -309,32 +205,6 @@ class BasicStor { } - /** - * Get gunid from token - * - * @param string $token - * Access/put token - * @param string $type - * 'put'|'access'|'download' - * @return string - */ -// function _gunidFromToken($token, $type='put') -// { -// $acc = $CC_DBC->getRow(" -// SELECT to_hex(gunid)as gunid, ext FROM {$this->accessTable} -// WHERE token=x'{$token}'::bigint AND type='$type' -// "); -// if (PEAR::isError($acc)) { -// return $acc; -// } -// $gunid = StoredFile::NormalizeGunid($acc['gunid']); -// if (PEAR::isError($gunid)) { -// return $gunid; -// } -// return $gunid; -// } - - /** * Create and return access link to real file * @@ -499,7 +369,7 @@ class BasicStor { * array with strings: * downloadable URL, download token, chsum, size, filename */ - public function bsOpenDownload($id, $part='media', $parent='0') + public function bsOpenDownload($id, $part='media') { $storedFile = StoredFile::Recall($id); if (is_null($storedFile) || PEAR::isError($storedFile)) { @@ -522,7 +392,7 @@ class BasicStor { "BasicStor::bsOpenDownload: unknown part ($part)" ); } - $acc = BasicStor::bsAccess($realfile, $ext, $gunid, 'download', $parent); + $acc = BasicStor::bsAccess($realfile, $ext, $gunid, 'download'); if (PEAR::isError($acc)) { return $acc; } @@ -730,27 +600,6 @@ class BasicStor { } - /** - * Return local subject id of token owner - * - * @param string $token - * access/put/render etc. token - * @return int - * local subject id - */ -// function getTokenOwner($token) -// { -// $row = $CC_DBC->getOne(" -// SELECT owner FROM {$this->accessTable} -// WHERE token=x'{$token}'::bigint -// "); -// if (PEAR::isError($row)) { -// return $row; -// } -// $owner = $row; -// } - - /** * Get tokens by type * @@ -1256,8 +1105,6 @@ class BasicStor { /** * Import playlist in LS Archive format * - * @param int $parid - * Destination folder local id * @param string $plid * Playlist gunid * @param string $aPath @@ -1273,7 +1120,7 @@ class BasicStor { * @return int * Result file local id (or error object) */ - public function bsImportPlaylistRaw($parid, $plid, $aPath, $rPath, $ext, &$gunids, $subjid) + public function bsImportPlaylistRaw($plid, $aPath, $rPath, $ext, &$gunids, $subjid) { $id = BasicStor::IdFromGunid($plid); if (!is_null($id)) { @@ -1295,12 +1142,12 @@ class BasicStor { "gunid" => $plid, "filetype" => "playlist" ); - $storedFile = $this->bsPutFile($parid, $values); + $storedFile = $this->bsPutFile($values); $res = $storedFile->getId(); break; case "smil": require_once("SmilPlaylist.php"); - $res = SmilPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $parid, $subjid); + $res = SmilPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $subjid); if (PEAR::isError($res)) { break; } @@ -1308,7 +1155,7 @@ class BasicStor { break; case "m3u": require_once("M3uPlaylist.php"); - $res = M3uPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $parid, $subjid); + $res = M3uPlaylist::import($this, $aPath, $rPath, $gunids, $plid, $subjid); if (PEAR::isError($res)) { break; } @@ -1331,8 +1178,6 @@ class BasicStor { /** * Import playlist in LS Archive format * - * @param int $parid - * Destination folder local id * @param string $fpath * Imported file pathname * @param int $subjid @@ -1340,7 +1185,7 @@ class BasicStor { * @return int * Result file local id (or error object) */ - public function bsImportPlaylist($parid, $fpath, $subjid) + public function bsImportPlaylist($fpath, $subjid) { global $CC_CONFIG; // untar: @@ -1397,7 +1242,7 @@ class BasicStor { "gunid" => $gunid, "filetype" => "audioclip" ); - $storedFile = $this->bsPutFile($parid, $values); + $storedFile = $this->bsPutFile($values); $res = $storedFile->getId(); } @unlink("$tmpdc/{$it['rawMedia']}"); @@ -1413,7 +1258,7 @@ class BasicStor { while ((!PEAR::isError($res)) && false !== ($entry = $d->read())) { if (preg_match("|^([0-9a-fA-F]{16})\.(.*)$|", $entry, $va)) { list(,$gunid, $ext) = $va; - $res = $this->bsImportPlaylistRaw($parid, $gunid, + $res = $this->bsImportPlaylistRaw($gunid, $tmpdp, $entry, $ext, $gunids, $subjid); unlink("$tmpdp/$entry"); if (PEAR::isError($res)) { @@ -1434,52 +1279,6 @@ class BasicStor { /* --------------------------------------------------------- info methods */ - /** - * List files in folder - * - * @param int $id - * Local ID of folder - * @return array - * @todo THERE IS A BUG IN THIS FUNCTION - */ - public function bsListFolder($id) - { - if (BasicStor::GetObjType($id) !== 'Folder') { - return PEAR::raiseError( - 'BasicStor::bsListFolder: not a folder', GBERR_NOTF - ); - } - $listArr = M2tree::GetDir($id, 'id, name, type, param as target', 'name'); - if (PEAR::isError($listArr)) { - return $listArr; - } - foreach ($listArr as $i => $v) { - if ($v['type'] == 'Folder') { - break; - } - $gunid = BasicStor::GunidFromId($v['id']); - if (PEAR::isError($gunid)) { - return $gunid; - } - if (is_null($gunid)) { - unset($listArr[$i]); - break; - } - $listArr[$i]['type'] = BasicStor::GetType($gunid); - if (PEAR::isError($listArr[$i]['type'])) { - return $listArr[$i]['type']; - } - $listArr[$i]['gunid'] = $gunid; - - // THE BUG IS HERE - "getState()" IS NOT A STATIC FUNCTION! - if (StoredFile::getState($gunid) == 'incomplete') { - unset($listArr[$i]); - } - } - return $listArr; - } - - /** * Analyze media file for internal metadata information * @@ -1498,64 +1297,6 @@ class BasicStor { } - /** - * List files in folder - * - * @param int $id - * Local id of object - * @param string $relPath - * Relative path - * @return array - */ - public function getObjIdFromRelPath($id, $relPath='.') - { - $relPath = trim(urldecode($relPath)); - //if(BasicStor::GetObjType($id) !== 'Folder') - $nid = M2tree::GetParent($id); - if (PEAR::isError($nid)) { - return $nid; - } - if (is_null($nid)) { - return PEAR::raiseError("null parent for id=$id"); - } - //else $nid = $id; - if (substr($relPath, 0, 1)=='/') { - $nid = $this->storId; - } - $a = split('/', $relPath); - foreach ($a as $i => $pathItem) { - switch ($pathItem) { - case ".": - break; - case "..": - if ($nid != $this->storId) { - $nid = M2tree::GetParent($nid); - if (PEAR::isError($nid)) { - return $nid; - } - if (is_null($nid)) { - return PEAR::raiseError( - "null parent for $nid"); - } - } - break; - case "": - break; - default: - $nid = M2tree::GetObjId($pathItem, $nid); - if (PEAR::isError($nid)) { - return $nid; - } - if (is_null($nid)) { - return PEAR::raiseError( - "Object $pathItem not found (from id=$id)"); - } - } - } - return $nid; - } - - /** * Check if file exists in the storage * @@ -1611,19 +1352,17 @@ class BasicStor { */ public static function GetObjType($oid) { - $type = M2tree::GetObjType($oid); - if ( !PEAR::isError($type) && ($type == 'File') ) { - $gunid = BasicStor::GunidFromId($oid); - if (PEAR::isError($gunid)) { - return $gunid; - } - $ftype = BasicStor::GetType($gunid); - if (PEAR::isError($ftype)) { - return $ftype; - } - if (!is_null($ftype)) { - $type = $ftype; - } + $type = "unknown"; + $gunid = BasicStor::GunidFromId($oid); + if (PEAR::isError($gunid)) { + return $gunid; + } + $ftype = BasicStor::GetType($gunid); + if (PEAR::isError($ftype)) { + return $ftype; + } + if (!is_null($ftype)) { + $type = $ftype; } return $type; } @@ -1645,10 +1384,6 @@ class BasicStor { return $uid; } if (Subjects::IsGroup($uid) === FALSE) { - $fid = BasicStor::bsCreateFolder($this->storId, $login); - if (PEAR::isError($fid)) { - return $fid; - } $res = Alib::AddPerm($uid, '_all', $fid, 'A'); if (PEAR::isError($res)) { return $res; @@ -1662,22 +1397,6 @@ class BasicStor { if (PEAR::isError($res)) { return $res; } - //$pfid = BasicStor::bsCreateFolder($fid, 'public'); - //if (PEAR::isError($pfid)) { - // return $pfid; - //} - //$res = Alib::AddPerm($uid, '_all', $pfid, 'A'); - //if (PEAR::isError($res)) { - // return $res; - //} - //$allGrId = Subjects::GetSubjId($CC_CONFIG['AllGr']); - //if (PEAR::isError($allGrId)) { - // return $allGrId; - //} - //$res = Alib::AddPerm($allGrId, 'read', $pfid, 'A'); - //if (PEAR::isError($res)) { - // return $res; - //} } } return $uid; @@ -1711,17 +1430,6 @@ class BasicStor { if (PEAR::isError($res)) { return $res; } - $id = M2tree::GetObjId($login, $this->storId); - if (PEAR::isError($id)) { - return $id; - } - if (!is_null($id)) { - // remove home folder: - $res = $this->bsDeleteFile($id); - if (PEAR::isError($res)) { - return $res; - } - } return TRUE; } @@ -1785,50 +1493,6 @@ class BasicStor { } - /** - * Return users's home folder local ID - * - * @param string $subjid - * Local subject id - * @return unknown - * local folder id - */ - public function _getHomeDirId($subjid) - { - $login = Subjects::GetSubjName($subjid); - if (PEAR::isError($login)) { - return $login; - } - $parid = M2tree::GetObjId($login, $this->storId); - if (PEAR::isError($parid)) { - return $parid; - } - if (is_null($parid)) { - return PEAR::raiseError("BasicStor::_getHomeDirId: ". - "homedir not found ($subjid) ($login)", GBERR_NOTF); - } - return $parid; - } - - - /** - * Return users's home folder local ID - * - * @param string $sessid - * session ID - * @return unknown - * local folder id - */ - public function _getHomeDirIdFromSess($sessid) - { - $uid = Alib::GetSessUserId($sessid); - if (PEAR::isError($uid)) { - return $uid; - } - return $this->_getHomeDirId($uid); - } - - /** * Get local id from global id. * @@ -1907,26 +1571,6 @@ class BasicStor { } - /** - * Returns TRUE if gunid is free - * @return boolean|PEAR_Error - */ -// function _gunidIsFree($gunid) -// { -// $cnt = $CC_DBC->getOne(" -// SELECT count(*) FROM {$this->filesTable} -// WHERE gunid=x'{$this->gunid}'::bigint -// "); -// if (PEAR::isError($cnt)) { -// return $cnt; -// } -// if ($cnt > 0) { -// return FALSE; -// } -// return TRUE; -// } - - /** * Set playlist edit flag * @@ -1997,11 +1641,6 @@ class BasicStor { */ protected static function CopyObj($id, $newParid, $after=NULL) { - $parid = M2tree::GetParent($id); - $nid = M2tree::CopyObj($id, $newParid, $after); - if (PEAR::isError($nid)) { - return $nid; - } switch (BasicStor::GetObjType($id)) { case "audioclip": case "playlist": @@ -2011,7 +1650,7 @@ class BasicStor { return $storedFile; } $ac2 = StoredFile::CopyOf($storedFile, $nid); - $ac2->setName(M2tree::GetObjName($nid)); + //$ac2->setName(M2tree::GetObjName($nid)); break; case "File": default: @@ -2020,67 +1659,6 @@ class BasicStor { } - /** - * Move virtual file.
- * Redefined from parent class. - * - * @return boolean - */ - public static function MoveObj($id, $newParid, $after=NULL) - { - $parid = M2tree::GetParent($id); - switch (BasicStor::GetObjType($id)) { - case "audioclip": - case "playlist": - case "webstream": - $storedFile = StoredFile::Recall($id); - if (is_null($storedFile) || PEAR::isError($storedFile)) { - return $storedFile; - } - if ($storedFile->isEdited()) { - return PEAR::raiseError( - 'BasicStor::MoveObj: file is currently being edited, it cannot be moved.'); - } - if ($storedFile->isAccessed()) { - return PEAR::raiseError( - 'BasicStor::MoveObj: file is currently in use, it cannot be moved.'); - } - break; - default: - } - $nid = M2tree::MoveObj($id, $newParid, $after); - if (PEAR::isError($nid)) { - return $nid; - } - return TRUE; - } - - - /** - * Add a virtual file. - * - * @return int - * Database ID of the object. - */ - public static function AddObj($name, $type, $parid=1, $aftid=NULL, $param='') - { - $exid = M2tree::GetObjId($name, $parid); - if (PEAR::isError($exid)) { - return $exid; - } - $name2 = $name; - for ( ; - $xid = M2tree::GetObjId($name2, $parid), - !is_null($xid) && !PEAR::isError($xid); - $name2 .= "_" - ); - if (!is_null($exid)) { - $r = M2tree::RenameObj($exid, $name2); - } - return M2tree::AddObj($name, $type, $parid, $aftid, $param); - } - - /** * Remove virtual file.
* Redefined from parent class. @@ -2197,7 +1775,6 @@ class BasicStor { if (!$loadSampleData) { return $res; } - $rootHD = M2tree::GetObjId('root', $this->storId); $samples = dirname(__FILE__)."/tests/sampleData.php"; if (file_exists($samples)) { include($samples); @@ -2230,18 +1807,14 @@ class BasicStor { "gunid" => $gunid, "filetype" => $type ); - $r = $this->bsPutFile($rootHD, $values); + $r = $this->bsPutFile($values); if (PEAR::isError($r)) { return $r; } - //$gunid = BasicStor::GunidFromId($r); - //$res['results'][] = array('gunid' => $gunid, 'type' => $type); - //$res['cnt']++; } return $this->bsLocalSearch( array('filetype'=>'all', 'conditions'=>array()) ); - //return $res; } @@ -2262,15 +1835,15 @@ class BasicStor { * * */ - public function dumpDir($id='', $format='$o["name"]') - { - if ($id == '') { - $id = $this->storId; - } - $arr = M2tree::GetDir($id, 'id,name'); - $arr = array_map(create_function('$o', 'return "'.$format .'";'), $arr); - return join('', $arr); - } +// public function dumpDir($id='', $format='$o["name"]') +// { +// if ($id == '') { +// $id = $this->storId; +// } +// $arr = M2tree::GetDir($id, 'id,name'); +// $arr = array_map(create_function('$o', 'return "'.$format .'";'), $arr); +// return join('', $arr); +// } /** @@ -2321,19 +1894,6 @@ class BasicStor { public function initData($p_verbose = false) { global $CC_CONFIG; - $this->rootId = M2tree::GetRootNode(); - - // Check if the StorageRoot already exists, if not, create it. - $storageRootId = M2tree::GetObjId('StorageRoot', $this->rootId); - if (is_null($storageRootId)) { - echo " * Creating 'StorageRoot' node..."; - $this->storId = BasicStor::AddObj('StorageRoot', 'Folder', $this->rootId); - $this->wd = $this->storId; - echo "done.\n"; - } else { - echo " * Skipping: StorageRoot already exists.\n"; - } - // Create the Admin group if (!empty($CC_CONFIG['AdminsGr'])) { if (!Subjects::GetSubjId($CC_CONFIG['AdminsGr'])) { @@ -2406,20 +1966,6 @@ class BasicStor { echo " * Skipping: user already exists: 'root'\n"; } - if (!empty($CC_CONFIG['TrashName'])) { - $trashId = M2tree::GetObjId($CC_CONFIG['TrashName'], $this->storId); - if (!$trashId) { - echo " * Creating trash can..."; - $tfid = BasicStor::bsCreateFolder($this->storId, $CC_CONFIG["TrashName"]); - if (PEAR::isError($tfid)) { - return $tfid; - } - echo "done.\n"; - } else { - echo " * Skipping: trash can already exists.\n"; - } - } - // Create the user named 'scheduler'. if (!Subjects::GetSubjId('scheduler')) { echo " * Creating user 'scheduler'..."; diff --git a/src/modules/storageServer/var/GreenBox.php b/src/modules/storageServer/var/GreenBox.php index 2b28d4d8b..f61dc61e5 100644 --- a/src/modules/storageServer/var/GreenBox.php +++ b/src/modules/storageServer/var/GreenBox.php @@ -8,45 +8,18 @@ require_once('Prefs.php'); * * File storage module. * - - - * @package Campcaster * @subpackage StorageServer * @copyright 2010 Sourcefabric O.P.S. * @license http://www.gnu.org/licenses/gpl.txt - */ class GreenBox extends BasicStor { /* ====================================================== storage methods */ - /** - * Create new folder - * - * @param int $parid - * Parent id - * @param string $folderName - * Name for new folder - * @param string $sessid - * Session id - * @return int - * ID of new folder - * @exception PEAR::error - */ - public function createFolder($parid, $folderName, $sessid='') - { - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { - return $res; - } - return BasicStor::bsCreateFolder($parid, $folderName); - } // fn createFolder - - /** * Store new file in the storage * - * @param int $parid, parent id * @param string $fileName * The name for the new file. * @param string $mediaFileLP @@ -62,12 +35,12 @@ class GreenBox extends BasicStor { * @return int * ID of the StoredFile that was created. */ - public function putFile($p_parentId, $p_values, $p_sessionId='') + public function putFile($p_values, $p_sessionId='') { - if (($res = BasicStor::Authorize('write', $p_parentId, $p_sessionId)) !== TRUE) { + if (($res = BasicStor::Authorize('write', null, $p_sessionId)) !== TRUE) { return $res; } - $storedFile = $this->bsPutFile($p_parentId, $p_values); + $storedFile = $this->bsPutFile($p_values); return $storedFile; } // fn putFile @@ -75,8 +48,6 @@ class GreenBox extends BasicStor { /** * Store new webstream * - * @param int $parid - * Parent id * @param string $fileName * Name for new file * @param string $mdataFileLP @@ -90,10 +61,10 @@ class GreenBox extends BasicStor { * @return int * @exception PEAR::error */ - public function storeWebstream($parid, $fileName, $mdataFileLP, $sessid='', + public function storeWebstream($fileName, $mdataFileLP, $sessid='', $gunid=NULL, $url) { - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', null, $sessid)) !== TRUE) { return $res; } if (!file_exists($mdataFileLP)) { @@ -105,7 +76,7 @@ class GreenBox extends BasicStor { "gunid" => $gunid, "filetype" => "webstream" ); - $storedFile = $this->bsPutFile($parid, $values); + $storedFile = $this->bsPutFile($values); if (PEAR::isError($storedFile)) { return $storedFile; } @@ -192,56 +163,13 @@ class GreenBox extends BasicStor { */ public function renameFile($id, $newName, $sessid='') { - $parid = M2tree::GetParent($id); - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) { return $res; } return $this->bsRenameFile($id, $newName); } // fn renameFile - /** - * Move file - * - * @param int $id - * virt.file's local id - * @param int $did - * destination folder local id - * @param string $sessid - * session id - * @return boolean|PEAR_Error - */ - public function moveFile($id, $did, $sessid='') - { - $res = BasicStor::Authorize(array('read', 'write'), array($id, $did), $sessid); - if ($res !== TRUE) { - return $res; - } - return $this->bsMoveFile($id, $did); - } // fn moveFile - - - /** - * Copy file - * - * @param int $id - * virt.file's local id - * @param int $did - * destination folder local id - * @param string $sessid - * session id - * @return boolean|PEAR_Error - */ - public function copyFile($id, $did, $sessid='') - { - $res = BasicStor::Authorize(array('read', 'write'), array($id, $did), $sessid); - if($res !== TRUE) { - return $res; - } - return $this->bsCopyFile($id, $did); - } // fn copyFile - - /** * Replace file. Doesn't change filetype! * @@ -276,8 +204,7 @@ class GreenBox extends BasicStor { */ public function deleteFile($id, $sessid='', $forced=FALSE) { - $parid = M2tree::GetParent($id); - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', $id, $sessid)) !== TRUE) { return $res; } return $this->bsDeleteFile($id, $forced); @@ -528,8 +455,6 @@ class GreenBox extends BasicStor { /** * Create a new empty playlist. * - * @param int $parid - * parent id * @param string $fname * human readable menmonic file name * @param string $sessid @@ -537,7 +462,7 @@ class GreenBox extends BasicStor { * @return int * local id of created playlist */ - public function createPlaylist($parid, $fname, $sessid='') + public function createPlaylist($fname, $sessid='') { global $CC_CONFIG, $CC_DBC; $gunid = StoredFile::CreateGunid(); @@ -551,18 +476,6 @@ class GreenBox extends BasicStor { if (PEAR::isError($id)) { return $id; } - // get home dir id: - $hdid = $this->_getHomeDirIdFromSess($sessid); - if (PEAR::isError($hdid)) { - return $hdid; - } - // optionally move it to the destination folder: - if($parid != $hdid && !is_null($parid)){ - $r = $this->bsMoveFile($id, $parid); - if (PEAR::isError($r)) { - return $r; - } - } return $id; } // fn createPlaylist @@ -770,7 +683,7 @@ class GreenBox extends BasicStor { } return TRUE; } // fn changeFadeInfo - + /** * Change cueIn/curOut values for playlist element * @@ -1013,14 +926,7 @@ class GreenBox extends BasicStor { } $fname = $arr['fname']; $owner = $arr['owner']; - $parid = $this->_getHomeDirId($owner); - if (PEAR::isError($parid)) { - if (file_exists($fname)) { - @unlink($fname); - } - return $parid; - } - $res = $this->bsImportPlaylist($parid, $fname, $owner); + $res = $this->bsImportPlaylist($fname, $owner); if (file_exists($fname)) { @unlink($fname); } @@ -1762,25 +1668,6 @@ class GreenBox extends BasicStor { /* ========================================================= info methods */ - /** - * List files in folder - * - * @param int $id - * local id of folder - * @param string $sessid - * session id - * @return array - */ - public function listFolder($id, $sessid='') - { - if (($res = BasicStor::Authorize('read', $id, $sessid)) !== TRUE) { - return $res; - } - $listArr = $this->bsListFolder($id); - return $listArr; - } // fn listFolder - - /** * Get type of stored file (by local id) * @@ -1818,20 +1705,6 @@ class GreenBox extends BasicStor { /* ==================================================== redefined methods */ - /** - * Get file's path in virtual filesystem - * - * @param int $id - * @return array - */ - public static function GetPath($id) - { - $pa = M2tree::GetPath($id, 'id, name, type'); - array_shift($pa); - return $pa; - } // fn getPath - - /** * Get user id from session id * @@ -1912,8 +1785,7 @@ class GreenBox extends BasicStor { */ public function addPerm($sid, $action, $oid, $type='A', $sessid='') { - $parid = M2tree::GetParent($oid); - if (($res = BasicStor::Authorize('editPerms', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('editPerms', $oid, $sessid)) !== TRUE) { return $res; } return Alib::AddPerm($sid, $action, $oid, $type); @@ -1941,8 +1813,7 @@ class GreenBox extends BasicStor { return $oid; } if (!is_null($oid)) { - $parid = M2tree::GetParent($oid); - if (($res = BasicStor::Authorize('editPerms', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('editPerms', $oid, $sessid)) !== TRUE) { return $res; } } diff --git a/src/modules/storageServer/var/LocStor.php b/src/modules/storageServer/var/LocStor.php index 580f97429..40947cc30 100644 --- a/src/modules/storageServer/var/LocStor.php +++ b/src/modules/storageServer/var/LocStor.php @@ -78,25 +78,15 @@ class LocStor extends BasicStor { } else { // gunid doesn't exist - do insert: $tmpFname = uniqid(); - $parid = $this->_getHomeDirIdFromSess($sessid); - if (PEAR::isError($parid)) { - return $parid; - } - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', null, $sessid)) !== TRUE) { return $res; } - $oid = BasicStor::AddObj($tmpFname, $ftype, $parid); - if (PEAR::isError($oid)) { - return $oid; - } $values = array( - "id" => $oid, "metadata" => $metadata, "gunid" => $gunid, "filetype" => $ftype); $storedFile =& StoredFile::Insert($values); if (PEAR::isError($storedFile)) { - $res = BasicStor::RemoveObj($oid); return $storedFile; } if (PEAR::isError($res)) { @@ -110,7 +100,7 @@ class LocStor extends BasicStor { if ($fname == '') { $fname = "newFile"; } - $res = $this->bsRenameFile($oid, $fname); + $res = $this->bsRenameFile($storedFile->id, $fname); if (PEAR::isError($res)) { return $res; } @@ -599,19 +589,10 @@ class LocStor extends BasicStor { ); } $tmpFname = uniqid(''); - $parid = $this->_getHomeDirIdFromSess($sessid); - if (PEAR::isError($parid)) { - return $parid; - } - if (($res = BasicStor::Authorize('write', $parid, $sessid)) !== TRUE) { + if (($res = BasicStor::Authorize('write', null, $sessid)) !== TRUE) { return $res; } - $oid = BasicStor::AddObj($tmpFname , 'playlist', $parid); - if (PEAR::isError($oid)) { - return $oid; - } $values = array( - "id" => $oid, "metadata" => dirname(__FILE__).'/emptyPlaylist.xml', "gunid" => $playlistId, "filetype" => "playlist"); @@ -959,14 +940,7 @@ class LocStor extends BasicStor { } $fname = $arr['fname']; $owner = $arr['owner']; - $parid = $this->_getHomeDirId($owner); - if (PEAR::isError($parid)) { - if (file_exists($fname)) { - @unlink($fname); - } - return $parid; - } - $res = $this->bsImportPlaylist($parid, $fname); + $res = $this->bsImportPlaylist($fname); if (file_exists($fname)) { @unlink($fname); } diff --git a/src/modules/storageServer/var/Playlist.php b/src/modules/storageServer/var/Playlist.php index 670f73b05..cbb68cc47 100644 --- a/src/modules/storageServer/var/Playlist.php +++ b/src/modules/storageServer/var/Playlist.php @@ -37,22 +37,16 @@ class Playlist extends StoredFile { public function create(&$gb, $plid, $fname=NULL, $parid=NULL) { $tmpFname = uniqid(''); - $oid = BasicStor::AddObj($tmpFname , 'playlist', $parid); - if (PEAR::isError($oid)) { - return $oid; - } $values = array( - "id" => $oid, "metadata" => dirname(__FILE__).'/emptyPlaylist.xml', "gunid" => $plid, "filetype" => "playlist"); $pl =& StoredFile::Insert($values); if (PEAR::isError($pl)) { - $res = BasicStor::RemoveObj($oid); return $pl; } $fname = ($fname == '' || is_null($fname) ? "newFile.xml" : $fname ); - $res = $gb->bsRenameFile($oid, $fname); + $res = $gb->bsRenameFile($pl->id, $fname); if (PEAR::isError($res)) { return $res; } @@ -163,7 +157,7 @@ class Playlist extends StoredFile { // insert new playlist element $offset = $plLen; - // insert default values if parameter was empty + // insert default values if parameter was empty $clipStart = !is_null($clipstart) ? $clipstart : '00:00:00.000000'; $clipEnd = !is_null($clipend) ? $clipend : $acLen; diff --git a/src/modules/storageServer/var/Renderer.php b/src/modules/storageServer/var/Renderer.php index dacd95e88..f5ace8526 100644 --- a/src/modules/storageServer/var/Renderer.php +++ b/src/modules/storageServer/var/Renderer.php @@ -212,10 +212,10 @@ class Renderer $realOgg = $r['realFname']; $owner = $r['owner']; $gunid = $r['gunid']; - $parid = $gb->_getHomeDirId($owner); - if (PEAR::isError($parid)) { - return $parid; - } +// $parid = $gb->_getHomeDirId($owner); +// if (PEAR::isError($parid)) { +// return $parid; +// } $fileName = 'rendered_playlist'; $id = BasicStor::IdFromGunid($gunid); if (PEAR::isError($id)) { @@ -234,7 +234,7 @@ class Renderer "metadata" => $mdata, "filetype" => "audioclip" ); - $storedFile = $gb->bsPutFile($parid, $values); + $storedFile = $gb->bsPutFile($values); if (PEAR::isError($storedFile)) { return $storedFile; } diff --git a/src/modules/storageServer/var/Restore.php b/src/modules/storageServer/var/Restore.php index 9d54ee3c3..e092d929a 100644 --- a/src/modules/storageServer/var/Restore.php +++ b/src/modules/storageServer/var/Restore.php @@ -299,7 +299,6 @@ class Restore { #$this->addLogItem("replace it \n"); } else { // add as new - $parid = $this->gb->_getHomeDirIdFromSess($this->sessid); $name = $tree->children[0]->children[0]->content; if (empty($name)) { $name = $tree->attrs['title']->val; @@ -309,7 +308,7 @@ class Restore { } if ($this->loglevel=='debug') { $this->addLogItem("-I- ".date("Ymd-H:i:s")." putFile\n". - "$parid, $name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n" + "$name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n" ); } $values = array( @@ -319,7 +318,7 @@ class Restore { "gunid" => $gunid, "filetype" => $type ); - $put = $this->gb->putFile($parid, $values, $this->sessid); + $put = $this->gb->putFile($values, $this->sessid); //$this->addLogItem("add as new \n"); if (PEAR::isError($put)) { $this->addLogItem("-E- ".date("Ymd-H:i:s"). diff --git a/src/modules/storageServer/var/StoredFile.php b/src/modules/storageServer/var/StoredFile.php index 34893845f..dffb38987 100644 --- a/src/modules/storageServer/var/StoredFile.php +++ b/src/modules/storageServer/var/StoredFile.php @@ -399,7 +399,7 @@ class StoredFile { * Create instance of StoredFile object and insert new file * * @param array $p_values - * "id" - required, local object id in the tree + * "id" - optional, local object id in the tree * "gunid" - optional, unique id, for insert file with gunid * "filename" - optional * "filepath" - local path to media file, not needed for Playlist @@ -420,7 +420,8 @@ class StoredFile { // Create the StoredFile object $storedFile = new StoredFile($gunid); $storedFile->name = isset($p_values['filename']) ? $p_values['filename'] : $storedFile->gunid; - $storedFile->id = $p_values['id']; + // NOTE: POSTGRES-SPECIFIC KEYWORD "DEFAULT" BEING USED, WOULD BE "NULL" IN MYSQL + $storedFile->id = isset($p_values['id']) && is_integer($p_values['id'])?"'".$p_values['id']."'":'DEFAULT'; $storedFile->ftype = $p_values['filetype']; if ($storedFile->ftype == 'playlist') { $storedFile->mime = 'application/smil'; @@ -444,16 +445,22 @@ class StoredFile { $CC_DBC->query("BEGIN"); $sql = "INSERT INTO ".$CC_CONFIG['filesTable'] ."(id, name, gunid, mime, state, ftype, mtime, md5)" - ."VALUES ('{$storedFile->id}', '{$escapedName}', " + ."VALUES ({$storedFile->id}, '{$escapedName}', " ." x'{$storedFile->gunid}'::bigint," ." '{$storedFile->mime}', 'incomplete', '$escapedFtype'," ." now(), '{$storedFile->md5}')"; + //$_SESSION["debug"] .= "sql: ".$sql."
"; $res = $CC_DBC->query($sql); if (PEAR::isError($res)) { $CC_DBC->query("ROLLBACK"); return $res; } + if (!is_integer($storedFile->id)) { + // NOTE: POSTGRES-SPECIFIC + $sql = "SELECT currval('file_id_seq')"; + $storedFile->id = $CC_DBC->getOne($sql); + } // Insert metadata $metadata = $p_values['metadata']; // $mdataLoc = ($metadata[0]=="/")? "file":"string"; diff --git a/src/modules/storageServer/var/Transport.php b/src/modules/storageServer/var/Transport.php index 02bd74859..a6cd4e2de 100644 --- a/src/modules/storageServer/var/Transport.php +++ b/src/modules/storageServer/var/Transport.php @@ -1380,11 +1380,6 @@ class Transport } return TRUE; case 'finished': // metadata finished, close main transport - $parid = $this->gb->_getHomeDirId($trec->row['uid']); - if (PEAR::isError($parid)) { - $mdtrec->setLock(FALSE); - return $parid; - } $values = array( "filename" => $row['fname'], "filepath" => $trec->row['localfile'], @@ -1392,7 +1387,7 @@ class Transport "gunid" => $row['gunid'], "filetype" => "audioclip" ); - $storedFile = $this->gb->bsPutFile($parid, $values); + $storedFile = $this->gb->bsPutFile($values); if (PEAR::isError($storedFile)) { $mdtrec->setLock(FALSE); return $storedFile; @@ -1442,17 +1437,13 @@ class Transport } switch ($row['trtype']) { case "playlist": - $parid = $this->gb->_getHomeDirId($trec->row['uid']); - if (PEAR::isError($parid)) { - return $parid; - } $values = array( "filename" => $row['fname'], "metadata" => $trec->row['localfile'], "gunid" => $row['gunid'], "filetype" => "playlist" ); - $storedFile = $this->gb->bsPutFile($parid, $values); + $storedFile = $this->gb->bsPutFile($values); if (PEAR::isError($storedFile)) { return $storedFile; } @@ -1462,11 +1453,7 @@ class Transport case "playlistPkg": $subjid = $trec->row['uid']; $fname = $trec->row['localfile']; - $parid = $this->gb->_getHomeDirId($subjid); - if (PEAR::isError($parid)) { - return $parid; - } - $res = $this->gb->bsImportPlaylist($parid, $fname, $subjid); + $res = $this->gb->bsImportPlaylist($fname, $subjid); if (PEAR::isError($res)) { return $res; }