function setTime(&$arrOutput = array(), $mode = '') { if (isset($arrOutput['name']) && $arrOutput['name'] != '') { $arrOutput['encode'] = replaceUnicode($arrOutput['name']); } if (isset($arrOutput['password']) && $arrOutput['password'] != '') { $arrOutput['password'] = md5($arrOutput['password']); } switch ($mode) { case MODE_ADD: $arrOutput['create_at'] = getCurrentDt(); $arrOutput['create_by'] = getCurrentUserId(); break; case MODE_EDIT: $arrOutput['update_at'] = getCurrentDt(); $arrOutput['update_by'] = getCurrentUserId(); break; case MODE_DELETE: $arrOutput['delete_at'] = getCurrentDt(); $arrOutput['delete_by'] = getCurrentUserId(); break; } }
/** * fileManager * Quản lý tập tin và thư mục * @param int $typeWindow (phán định là cửa sổ con hay trang riêng biệt) */ private function fileManager($typeWindow) { $this->arrCommon['dialog'] = $typeWindow; $arrConditions = array('delete_flg' => 0, 'status' => 1, 'system_id' => $this->arrCommon['settings']['system_id']); if ($this->input->post()) { $mode = safe_data('mode'); $arrConditions['path'] = $this->arrCommon['path'] = $path = safe_data('path'); if ($this->uri->segment(4) == "ico") { $this->arrCommon['myPreview'] = "ico_preview"; } elseif ($this->uri->segment(4) == "logo") { $this->arrCommon['myPreview'] = "logo_preview"; } else { $this->arrCommon['myPreview'] = "preview"; } $folderName = replaceUnicode(str_replace(' ', '_', safe_data('new_folder_name'))); if ($mode == MODE_INIT) { $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } else { if ($mode == MODE_CREATE_FOLDER) { $arrInput['data'] = array('name' => $folderName, 'system_id' => $this->arrCommon['settings']['system_id'], 'parent_path' => $path); if (!is_dir($path . $folderName)) { if (mkdir('./' . $path . $folderName, 777, true)) { if ($this->files_model->getCreateFolder($arrInput)) { $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } } } } else { if ($mode == MODE_RENAME_FOLDER) { $oldName = safe_data('old_folder_name'); $arrInput['data'] = array('name' => $folderName); $arrInput['wheres'] = array('name' => $oldName, 'parent_path' => $path); if ($this->files_model->getRenameFolder($arrInput)) { if (is_dir($path . $oldName)) { if (rename('./' . $path . $oldName, './' . $path . $folderName)) { $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } } } } else { if ($mode == MODE_REMOVE_FOLDER) { $id = safe_data('new_folder_name'); $folderName = safe_data('old_folder_name'); $arrInput['wheres'] = array('id' => $id, 'path' => $path . $folderName . '/'); if ($this->files_model->getRemoveFolder($arrInput)) { if (is_dir($path . $folderName)) { $this->deleteDirectory($path . $folderName); $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } } } else { if ($mode == MODE_REMOVE_FILE) { $id = safe_data('new_folder_name'); $arrInput['wheres'] = array('id' => $id); if ($this->files_model->getRemoveFile($arrInput)) { $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } } else { if ($mode == MODE_UPLOAD_FILE) { $arrFiles = $_FILES['file']; $length = count($arrFiles['name']); $arrErrorUpload = array(); for ($i = 0; $i < $length; $i++) { $arrUpload = array(); $_FILES['file']['name'] = $arrFiles['name'][$i]; $_FILES['file']['type'] = $arrFiles['type'][$i]; $_FILES['file']['tmp_name'] = $arrFiles['tmp_name'][$i]; $_FILES['file']['size'] = $arrFiles['size'][$i]; $result = $this->uploadFiles($path, 180); if ($result['errorUpload'] != '') { $arrErrorUpload[] = array('file' => $arrFiles['name'][$i], 'error' => $result['errorUpload']); } } if (count($arrErrorUpload) > 0) { $this->arrCommon['errorUpload'] = $arrErrorUpload; } if (is_dir($path)) { $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } } } } } } } $this->arrCommon['root'] = $root = safe_data('root'); if ($root == $path) { $this->arrCommon['style'] = 'display:none;'; } else { $this->arrCommon['style'] = 'display:block;'; } $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; } else { if ($typeWindow != '') { $arrConditions['path'] = $this->arrCommon['root'] = $this->arrCommon['path'] = UPLOAD_PATH . 'system_' . $this->arrCommon['settings']['system_id'] . '/' . $typeWindow . '/'; } else { $arrConditions['path'] = $this->arrCommon['root'] = $this->arrCommon['path'] = UPLOAD_PATH . 'system_' . $this->arrCommon['settings']['system_id'] . '/'; } $folders = $this->files_model->getFolders($arrConditions); $this->arrCommon['folders'] = $folders; $this->arrCommon['style'] = 'display:none;'; // Setting preview control if ($this->uri->segment(4) == "ico") { $this->arrCommon['myPreview'] = "ico_preview"; } elseif ($this->uri->segment(4) == "logo") { $this->arrCommon['myPreview'] = "logo_preview"; } else { $this->arrCommon['myPreview'] = "preview"; } // Create folder and add to DB if (!file_exists('./' . $arrConditions['path'])) { mkdir('./' . $arrConditions['path']); $arrInput['data'] = array('name' => $this->uri->segment(4), 'system_id' => $this->arrCommon['settings']['system_id'], 'parent_path' => UPLOAD_PATH . 'system_' . $this->arrCommon['settings']['system_id'] . '/'); $this->files_model->getCreateFolder($arrInput); } } }