'doList', 'new' => 'doNew', 'insert' => 'doInsert', 'edit' => 'doEdit', 'update' => 'doUpdate', 'del' => 'doDelete', 'newfile' => 'doNewFile', 'insertfile' => 'doInsertFile', 'editfile' => 'doEditFile', 'updatefile' => 'doUpdateFile', 'delfile' => 'doDeleteFile', ); function FilesView() { $this->files_dir = WWW_PATH . '/userfile'; } function exec(&$Doc) { $this->Doc = &$Doc; $this->Doc->addItemProp('JSs', 'js/ajaxfileupload.js'); $action = $_REQUEST['action']; if (!array_key_exists($action, $this->actions)) { $actionNames = array_keys($this->actions); $action = $actionNames[0]; } $function = $this->actions[$action]; $this->$function(); } function _getBaseFileForm($method = 'post') { require_once 'app/Files/FileForm.php'; $form = new AjaxUploadForm($this->Doc, 'form', $method); $this->submitTitle = 'Upload'; $form->addElement('hidden', 'action', '', array ('id' => 'formaction')); return $form; } function _getBaseForm($method = 'post') { require_once 'class/Form/Form.class.php'; $form = new Form($this->Doc, 'form', $method); $form->action = CURR_PAGE; $form->addElement('hidden', 'action'); $form->cancelUrl = 'javascript:ShowFolder();'; return $form; } function getEditNewFolderForm() { $form = $this->_getBaseForm($name); $form->addElement('text', 'name', 'Name'); $form->addRuleRequired(array ('name')); return $form; } function getEditNewFileForm() { $form = $this->_getBaseFileForm($name); $form->addElement('file', 'file', 'File', array('id' => 'file')); $form->addRuleRequired(array('file')); return $form; } function getNewFolderForm() { $form = $this->getEditNewFolderForm($name); $form->addElement('hidden', 'parent', $_REQUEST['dir']); return $form; } function getNewFileForm() { $form = $this->getEditNewFileForm($name); $form->addElement('hidden', 'parent', $_REQUEST['dir'], array('id' => 'directory')); return $form; } function getEditFolderForm() { $form = $this->getEditNewFolderForm($name); $form->addElement('hidden', 'oldname', $_REQUEST['dir']); return $form; } function getEditFileForm() { $form = $this->getEditNewFileForm($name); $form->addElement('hidden', 'oldname', $_REQUEST['file'], array('id' => 'directory')); return $form; } function doDeleteAjax() { $this->doDelete(); } function doDelete() { $_REQUEST['dir'] = urldecode(stripslashes($_REQUEST['dir'])); $this->deleteDirectory($_REQUEST['dir'] . '/'); } function doDeleteFileAjax() { $this->doDeleteFile(); } function doDeleteFile() { $_REQUEST['file'] = urldecode(stripslashes($_REQUEST['file'])); unlink($_REQUEST['file']); echo dirname($_REQUEST['file']); die(); } function deleteDirectory($cDir) { $dh = opendir($cDir); while (false !== ($filename = readdir($dh))) { if (file_exists($cDir . $filename) && $filename != '.' && $filename != '..' && $filename != '.svn') { if (is_dir($cDir . $filename)) { $this->deleteDirectory($cDir . $filename . '/'); } else { unlink($cDir . $filename); } } } rmdir($cDir . $file); } function doInsertAjax() { $this->doInsert(); } function doInsert() { $form = $this->getNewFolderForm(); if ($form->validate()) { $aData = $form->exportValues(); mkdir($aData['parent'] . "/" . trim($aData['name'])); chmod($aData['parent'] . "/" . $aData['name'], 0777); echo $aData['parent'] . "/" . $aData['name']; } else { echo 'error'; } die(); } function doInsertFileAjax() { $this->doInsertFile(); } function doInsertFile() { $aFile = $_FILES['file']; $_POST['parent'] = stripslashes($_POST['parent']); if (!$aFile['error']) { move_uploaded_file($aFile['tmp_name'], $_POST['parent'] . '/' . $aFile['name']); } chmod($_POST['parent'] . "/" . $aFile['name'], 0777); echo "{error: '',\nmsg: '" . addslashes($_POST['parent']) . "'\n}"; die(); } function doNewAjax() { $this->doNew(); } function doNew() { $_REQUEST['dir'] = urldecode(stripslashes($_REQUEST['dir'])); $form = $this->getNewFolderForm(); $form->setTitle('Add New Folder into ' . basename($_REQUEST['dir'])); $hAction = &$form->getElement('action'); $hAction->setValue('insert'); $form->exec(); } function doNewFileAjax() { $this->doNewFile(); } function doNewFile() { $_REQUEST['dir'] = urldecode(stripslashes($_REQUEST['dir'])); $form = $this->getNewFileForm(); $form->setTitle('Add New File into ' . basename($_REQUEST['dir'])); $hAction = &$form->getElement('action'); $hAction->setValue('insertfile'); $form->exec(); } function doUpdateAjax() { $this->doUpdate(); } function doUpdate() { $form = $this->getEditFolderForm(); if ($form->validate()) { $aData = $form->exportValues(); rename($aData['oldname'], dirname($aData['oldname']) . "/" . trim($aData['name'])); echo $aData['oldname']; } else { echo 'error'; } die(); } function doUpdateFileAjax() { $this->doUpdateFile(); } function doUpdateFile() { $aFile = $_FILES['file']; $_POST['oldname'] = stripcslashes($_POST['oldname']); unlink($_POST['oldname']); if (!$aFile['error']) { move_uploaded_file($aFile['tmp_name'], dirname($_POST['oldname']) . '/' . $aFile['name']); } chmod(dirname($_POST['oldname']) . "/" . $aFile['name'], 0777); echo "{error: '',\nmsg: '" . dirname(addslashes($_POST['oldname'])) . "'\n}"; die(); } function doEditAjax() { $this->doEdit(); } function doEdit() { $_REQUEST['dir'] = urldecode(stripslashes($_REQUEST['dir'])); $form = $this->getEditFolderForm(); $form->setTitle('Rename Folder ' . basename($_REQUEST['dir'])); $hAction = &$form->getElement('action'); $hAction->setValue('update'); $iName = &$form->getElement('name'); $iName->setValue(basename($_REQUEST['dir'])); $form->exec(); } function doEditFileAjax() { $this->doEditFile(); } function doEditFile() { $_REQUEST['file'] = urldecode(stripslashes($_REQUEST['file'])); $form = $this->getEditFileForm(); $form->setTitle('Modify File ' . basename($_REQUEST['file'])); $hAction = &$form->getElement('action'); $hAction->setValue('updatefile'); $form->exec(); } function doListAjax() { $this->doList(); } function doList() { $_REQUEST['dir'] = urldecode(stripslashes($_REQUEST['dir'])); $aFiles = array ( 'tpl' => BASE_PATH . '/app/Files/tpl/filetree.tpl', 'files_dir' => $this->files_dir, ); if (dirname($_REQUEST['dir']) == $this->files_dir && $_REQUEST['showroot'] && $_REQUEST['showroot'] != 'undefined') { $aFiles['root'] = basename($_REQUEST['dir']); if (!is_dir($_REQUEST['dir'])) { mkdir($_REQUEST['dir']); } chmod($_REQUEST['dir'], 0777); } if (file_exists($_REQUEST['dir'])) { $dh = opendir($_REQUEST['dir']); while (false !== ($filename = readdir($dh))) { $files[] = trim($filename); } natcasesort($files); if (count($files) > 2) { /* The 2 accounts for . and .. */ // All dirs foreach ($files as $file) { if (file_exists($_REQUEST['dir'] . $file) && $file != '.' && $file != '.svn' && $file != '..' && is_dir($_REQUEST['dir'] . $file)) { $aFiles['directories'][] = array( 'fullpath' => $_REQUEST['dir'] . $file, 'name' => $file, 'count' => count(glob($_REQUEST['dir'] . $file . '/*')), 'countdir' => count(glob($_REQUEST['dir'] . $cFolder . '/*', GLOB_ONLYDIR)) ); } } // All files foreach ($files as $file) { if (file_exists($_REQUEST['dir'] . $file) && $file != '.' && $file != '..' && ! is_dir($_REQUEST['dir'] . $file)) { $aFile = array( 'fullpath' => $_REQUEST['dir'] . $file, 'name' => $file, 'ext' => preg_replace('/^.*\./', '', $file), 'justname' => preg_replace('/\.[^.]+$/', '', $file) ); if (preg_replace('/^.*\./', '', $file) == 'systemurl') { $f = fopen($_REQUEST['dir'] . $file, 'r'); $aFile['cUrl'] = fread($f, filesize($_REQUEST['dir'] . $file)); fclose($f); } $aFiles['files'][] = $aFile; } } } $aFiles['rootcount'] = count($aFiles['directories']) + count($aFiles['files']); $aFiles['rootcountdir'] = count($aFiles['directories']); if ($_REQUEST['showroot'] != 'undefined' || count($aFiles['files']) + count($aFiles['directories'])) { $this->Doc->addContent($aFiles); } } } } ?>