1: <?php
  2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20: 
 21: 
 22: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 23: 
 24:  25:  26:  27:  28:  29:  30:  31:  32: 
 33: function removeFileInformation($iIdClient, $sFilename, $sType, $oDb) {
 34:     global $cfg;
 35: 
 36:     if (!isset($oDb) || !is_object($oDb)) {
 37:         $oDb = cRegistry::getDb();
 38:     }
 39: 
 40:     $iIdClient = cSecurity::toInteger($iIdClient);
 41:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
 42:     $sType = cSecurity::filter((string) $sType, $oDb);
 43: 
 44:     $sSql = "DELETE FROM `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
 45:             filename = '$sFilename' AND type = '$sType';";
 46:     $oDb->query($sSql);
 47:     $oDb->free();
 48: }
 49: 
 50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66: 
 67: function getFileInformation($iIdClient, $sFilename, $sType, $oDb) {
 68:     global $cfg;
 69: 
 70:     if (!isset($oDb) || !is_object($oDb)) {
 71:         $oDb = cRegistry::getDb();
 72:     }
 73: 
 74:     $iIdClient = cSecurity::toInteger($iIdClient);
 75:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
 76:     $sType = cSecurity::filter((string) $sType, $oDb);
 77: 
 78:     $aFileInformation = array();
 79:     $sSql = "SELECT * FROM `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
 80:             filename = '$sFilename' AND type = '$sType';";
 81:     $oDb->query($sSql);
 82:     if ($oDb->numRows() > 0) {
 83:         $oDb->nextRecord();
 84:         $aFileInformation['idsfi'] = $oDb->f('idsfi');
 85:         $aFileInformation['created'] = $oDb->f('created');
 86:         $aFileInformation['lastmodified'] = $oDb->f('lastmodified');
 87:         $aFileInformation['author'] = cSecurity::unFilter($oDb->f('author'));
 88:         $aFileInformation['modifiedby'] = $oDb->f('modifiedby');
 89:         $aFileInformation['description'] = cSecurity::unFilter($oDb->f('description'));
 90:     }
 91:     $oDb->free();
 92: 
 93:     return $aFileInformation;
 94: }
 95: 
 96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 
111: function updateFileInformation($iIdClient, $sFilename, $sType, $sAuthor, $sDescription, $oDb, $sFilenameNew = '') {
112:     global $cfg;
113: 
114:     if (!isset($oDb) || !is_object($oDb)) {
115:         $oDb = cRegistry::getDb();
116:     }
117: 
118:     if ($sFilenameNew == '') {
119:         $sFilenameNew = $sFilename;
120:     }
121: 
122:     $iIdClient = cSecurity::toInteger($iIdClient);
123:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
124:     $sType = cSecurity::filter((string) $sType, $oDb);
125:     $sDescription = cSecurity::filter((string) stripslashes($sDescription), $oDb);
126:     $sAuthor = cSecurity::filter((string) $sAuthor, $oDb);
127: 
128:     $sSql = "SELECT * from `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
129:             filename = '$sFilename' AND type = '$sType';";
130:     $oDb->query($sSql);
131:     if ($oDb->numRows() == 0) {
132:         
133:         $sSql = "INSERT INTO `" . $cfg["tab"]["file_information"] . "` (
134:                     `idclient` ,
135:                     `type` ,
136:                     `filename` ,
137:                     `created` ,
138:                     `lastmodified` ,
139:                     `author` ,
140:                     `modifiedby` ,
141:                     `description`)
142:                 VALUES (
143:                     $iIdClient,
144:                     '$sType',
145:                     '$sFilenameNew',
146:                     NOW(),
147:                     '0000-00-00 00:00:00',
148:                     '$sAuthor',
149:                     '',
150:                     '$sDescription'
151:                 );";
152:     } else {
153:         $sSql = "UPDATE `" . $cfg["tab"]["file_information"] . "` SET `lastmodified` = NOW(),
154:                 `modifiedby` = '$sAuthor',
155:                 `description` = '$sDescription',
156:                 `filename` = '$sFilenameNew'
157:                 WHERE idclient=$iIdClient AND
158:                       filename='$sFilename' AND
159:                       type='$sType';";
160:     }
161: 
162:     $oDb->free();
163:     $oDb->query($sSql);
164:     $oDb->free();
165: }
166: 
167: 168: 169: 170: 171: 172: 
173: function getFileType($filename) {
174:     return cFileHandler::getExtension($filename);
175: }
176: 
177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 
188: function getDirectorySize($sDirectory, $bRecursive = false) {
189:     $ret = 0;
190:     $files = scanDirectory($sDirectory, $bRecursive);
191:     if ($files === false) {
192:         return false;
193:     }
194: 
195:     foreach ($files as $file) {
196:         $temp = cFileHandler::info($file);
197:         $ret += $temp['size'];
198:     }
199: 
200:     return $ret;
201: }
202: 
203: 204: 205: 206: 207: 208: 209: 
210: function scanDirectory($sDirectory, $bRecursive = false) {
211:     if (substr($sDirectory, strlen($sDirectory) - 1, 1) == '/') {
212:         $sDirectory = substr($sDirectory, 0, strlen($sDirectory) - 1);
213:     }
214: 
215:     if (!is_dir($sDirectory)) {
216:         return false;
217:     }
218: 
219:     $aFiles = array();
220:     $openDirs = array();
221:     $closedDirs = array();
222:     array_push($openDirs, $sDirectory);
223: 
224:     while (count(($openDirs)) >= 1) {
225:         $sDirectory = array_pop($openDirs);
226:         if (is_dir($sDirectory)) {
227:             if (($hDirHandle = opendir($sDirectory)) !== false) {
228:                 while (($sFile = readdir($hDirHandle)) !== false) {
229:                     if ($sFile != '.' && $sFile != '..') {
230:                         $sFullpathFile = $sDirectory . '/' . $sFile;
231:                         if (is_file($sFullpathFile) && cFileHandler::readable($sFullpathFile)) {
232:                             array_push($aFiles, $sFullpathFile);
233:                         } elseif (is_dir($sFullpathFile) && $bRecursive == true) {
234:                             if (!in_array($sFullpathFile, $closedDirs)) {
235:                                 array_push($openDirs, $sFullpathFile);
236:                             }
237:                         }
238:                     }
239:                 }
240:                 closedir($hDirHandle);
241:             }
242:         }
243:         array_push($closedDirs, $sDirectory);
244:     }
245: 
246:     return $aFiles;
247: }
248: 
249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 
261: function recursiveCopy($sourcePath, $destinationPath, $mode = 0777, array $options = array()) {
262:     if (!is_dir($destinationPath)) {
263:         mkdir($destinationPath, $mode);
264:     }
265: 
266:     $forceOverwrite = (isset($options['force_overwrite'])) ? (bool) $options['force_overwrite'] : false;
267:     $oldPath = getcwd();
268: 
269:     if (is_dir($sourcePath)) {
270:         chdir($sourcePath);
271:         $myhandle = opendir('.');
272: 
273:         while (($file = readdir($myhandle)) !== false) {
274:             if ($file != '.' && $file != '..') {
275:                 if (is_dir($file)) {
276:                     
277:                     recursiveCopy($sourcePath . $file . '/', $destinationPath . $file . '/', $mode, $options);
278:                     chdir($sourcePath);
279:                 } elseif (cFileHandler::exists($sourcePath . $file)) {
280:                     
281:                     if (cFileHandler::exists($destinationPath . $file)) {
282:                         if ($forceOverwrite) {
283:                             copy($sourcePath . $file, $destinationPath . $file);
284:                         }
285:                     } else {
286:                         copy($sourcePath . $file, $destinationPath . $file);
287:                     }
288:                 }
289:             }
290:         }
291:         closedir($myhandle);
292:     }
293: 
294:     chdir($oldPath);
295: }
296: