1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
16:
17: cInclude('includes', 'functions.file.php');
18:
19: 20: 21: 22: 23: 24:
25: class cApiFileInformationCollection extends ItemCollection {
26: 27: 28: 29: 30:
31: public function __construct() {
32: global $cfg;
33: parent::__construct($cfg['tab']['file_information'], 'idsfi');
34: $this->_setItemClass('cApiFileInformation');
35: }
36:
37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function create($typeContent, $filename, $description = '') {
57: $client = cRegistry::getClientId();
58: $auth = cRegistry::getAuth();
59: $item = new cApiFileInformation();
60: $item->loadByMany(array(
61: 'idclient' => $client,
62: 'type' => $typeContent,
63: 'filename' => $filename
64: ));
65: if (!$item->isLoaded()) {
66: $item = $this->createNewItem();
67:
68: $item->set('idclient', $client);
69: $item->set('type', $typeContent);
70: $item->set('filename', $filename);
71: $item->set('created', date('Y-m-d H:i:s'));
72: $item->set('lastmodified', date('Y-m-d H:i:s'));
73: $item->set('author', $auth->auth['uid']);
74: $item->set('modifiedby', $auth->auth['uid']);
75: $item->set('description', $description);
76: $item->store();
77:
78: return $item;
79: } else {
80: return $this->updateFile($filename, $typeContent, $description);
81: }
82: }
83:
84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106:
107: public function updateFile($filename, $typeContent, $description = '', $newFilename = '', $author = '') {
108: $auth = cRegistry::getAuth();
109: $client = cRegistry::getClientId();
110: $item = new cApiFileInformation();
111: $item->loadByMany(array(
112: 'idclient' => $client,
113: 'type' => $typeContent,
114: 'filename' => $filename
115: ));
116: $id = $item->get('idsfi');
117: if ($item->isLoaded()) {
118: $item->set('idsfi', $id);
119: $item->set('lastmodified', date('Y-m-d H:i:s'));
120: $item->set('description', $description);
121: $item->set('modifiedby', $auth->auth['uid']);
122: if (!empty($newFilename)) {
123: $item->set('filename', $newFilename);
124: }
125: if (!empty($author)) {
126: $item->set('author', $author);
127: }
128: $item->store();
129: }
130:
131: return $item;
132: }
133:
134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145:
146: public function removeFileInformation(array $values) {
147: $item = new cApiFileInformation();
148: $item->loadByMany($values);
149: $idsfi = $item->get('idsfi');
150: return $this->delete($idsfi);
151: }
152:
153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164:
165: public function getFileInformation($filename, $type) {
166: $client = cRegistry::getClientId();
167: $fileInformation = array();
168: $item = new cApiFileInformation();
169: $item->loadByMany(array(
170: 'idclient' => $client,
171: 'type' => $type,
172: 'filename' => $filename
173: ));
174: if ($item->isLoaded()) {
175: $fileInformation['idsfi'] = $item->get('idsfi');
176: $fileInformation['created'] = $item->get('created');
177: $fileInformation['lastmodified'] = $item->get('lastmodified');
178: $fileInformation['author'] = cSecurity::unFilter($item->get('author'));
179: $fileInformation['modifiedby'] = $item->get('modifiedby');
180: $fileInformation['description'] = cSecurity::unFilter($item->get('description'));
181: }
182: return $fileInformation;
183: }
184: }
185:
186: 187: 188: 189: 190: 191:
192: class cApiFileInformation extends Item
193: {
194: 195: 196: 197: 198: 199: 200: 201:
202: public function __construct($id = false) {
203: global $cfg;
204: parent::__construct($cfg['tab']['file_information'], 'idsfi');
205: if ($id !== false) {
206: $this->loadByPrimaryKey($id);
207: }
208: }
209: }
210: