Source for file staticbinfileclass.php

Documentation is available at staticbinfileclass.php


1 <?php
2 /**
3 * @author Jan H. Andersen <jha@ipwsystems.dk>
4 * @author Martin R. Larsen <mrl@ipwsystems.dk>
5 * @copyright {@link http://www.ipwsystems.dk/ IPW Systems a.s}
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @package METAjour
8 * @subpackage core
9 * $Id: staticbinfileclass.php,v 1.1 2005/02/07 09:56:20 jan Exp $
10 */
11
12 require_once('absfileclass.php');
13
14 class staticbinfile extends absfile {
15 var $ERR_CANNOTMAKEDIR = 8;
16
17 function staticbinfile() {
18 $this->absfile();
19 $this->addcolumn('name',0,UI_STRING);
20 $this->addcolumn('description',0,UI_STRING);
21
22 $this->removeview('createvariant');
23 }
24
25 function getRoot() {
26 return $this->userhandler->getDirStaticbinfile();
27 }
28
29 function getPath($parentid) {
30 if ($parentid == 0) return $this->getRoot();
31 $obj = owRead($parentid);
32 return $obj->getFullPath().'/';
33 }
34
35 function prv_createobject(&$arr) {
36 $uploaddir = $this->getPath($this->getParentId());
37 if ($_FILES['__uploadfile__']['tmp_name']) {
38 if (move_uploaded_file($_FILES['__uploadfile__']['tmp_name'],
39 $uploaddir.basename($_FILES['__uploadfile__']['name']))) {
40 $arr['name'] = $_FILES['__uploadfile__']['name'];
41 parent::prv_createobject($arr);
42 } else {
43 # make an error statement here
44 }
45 } else {
46 # in case we're creating an object based on a file already in
47 # the filesystem (remember to set $arr['name'] on createObject() )
48 parent::prv_createobject($arr);
49 }
50 }
51
52 function prv_readobject($objectid) {
53 # check for exist, or delete the entry from the staticbinfile table
54 $uploaddir = $this->getpath($this->getParentId());
55 if (($res['size'] = @filesize($uploaddir .$this->prv_options['name'])) !== FALSE) {
56 $res['realfile'] = $uploaddir .$this->prv_options['name'];
57 include_once($this->userhandler->getSystemPath().'core/util/class.mimetypes.php');
58 $mime =& new Mime_Types($this->userhandler->getSystemPath().'core/util/mime.types');
59 $res['mimetype'] = $mime->get_type($this->prv_options['name']);
60 return $res;
61 } else {
62 $db = &getDbConn();
63 if (!empty($objectid)) $db->Execute("delete from ".$this->objecttable." where objectid = $objectid");
64 $this->_removeelement = true;
65 return array();
66 }
67 }
68
69 function prv_updateobject($objectid, $arr) {
70 $obj = owRead($objectid);
71 if ($obj) {
72 if ($arr['name'] != $obj->elements[0]['name']) {
73 if (rename($this->getpath($this->getParentId()).$obj->elements[0]['name'],
74 $this->getpath($this->getParentId()).$arr['name'])) {
75 parent::prv_UpdateObject($objectid, $arr);
76 } else {
77 # make an error statement here
78 }
79 } else {
80 # in case we just changed the description
81 parent::prv_UpdateObject($objectid, $arr);
82 }
83 }
84 }
85
86 function listObjects($parentid=0,$objectid=0) {
87 $matches = glob($this->getPath($parentid).'*');
88 if (is_array($matches)) {
89 $db = &getDbConn();
90 $files = $db->getCol("select name from ".$this->objecttable.", object where ".$this->objecttable.".objectid = object.objectid and object.deleted = 0 and object.parentid = $parentid");
91 if (!$files) $files = array();
92 foreach ($matches as $fname) {
93 if (!is_dir($fname)) {
94 if (!in_array(basename($fname),$files)) {
95 $obj = owNew($this->type);
96 $obj->createObject(array('name' => basename($fname)),$parentid);
97 }
98 }
99 }
100 }
101 return parent::listObjects($parentid,$objectid);
102 }
103
104 }
105
106 ?>

Documentation generated on Thu, 9 Jun 2005 06:53:32 +0200 by phpDocumentor 1.2.3