public function index() { $docId = $this->uri->segment(2); $docObj = new Document_Model($docId); $modules = $docObj->getModules(); if (!is_array($modules)) { $location = FCPATH . $this->config->item('dataDir') . $docObj->getLocation(); if (is_file($location)) { $data = array('id' => $docId, 'file' => $location); $this->load->view('editor/editor_view', $data); } else { $this->session->set_flashdata('error', 'There was an error trying to open this file for editing.'); redirect($_SERVER['HTTP_REFERER']); } } $mods = array(); foreach ($modules as $mod) { $modObj = new Module_Model($mod->id); $category = $modObj->getCategory(); $loc = $modObj->getLocation(); $location = FCPATH . $this->config->item('moduleDir') . $category . '/files/' . $loc; $mods[] = array('id' => $mod->id, 'category' => $category, 'location' => $location); } $data = array('id' => $docId, 'modules' => $mods); $this->load->view('editor/editor_view', $data); }
public function listFiles($fileIdArray, $userPermsObj, $dataDir, $showCheckBox = false, $rejectpage = false) { if (sizeof($fileIdArray) == 0 or !isset($fileIdArray[0])) { echo '<div class="row"><i class="fa fa-exclamation-triangle fa-2x"></i>No Files Found</div>'; return -1; } foreach ($fileIdArray as $fileid) { if (is_array($fileid)) { foreach ($fileid as $file) { $fileObj = new Document_Model($file); $createdDate = $this->globalFunctions->fixDate($fileObj->getCreatedDate()); $deptName = $fileObj->getDepartmentName(); $realName = $fileObj->getRealname(); $location = $fileObj->getLocation(); $fileExt = $fileObj->getExt(); //Get the file size in bytes. $fileSize = $this->globalFunctions->displayFilesize($dataDir . $location); $size = array('B', 'MB', 'KB', 'K', 'GB', 'M'); $repSize = ''; $fileSizeNoStr = str_ireplace($size, $repSize, $fileSize); $fileListArr[] = array('id' => $file, 'fileName' => $realName, 'createdDate' => $createdDate, 'deptName' => $deptName, 'fileSize' => $fileSizeNoStr, 'rejectPage' => $rejectpage, 'location' => $location, 'ext' => $fileExt); } } } return json_encode($fileListArr); }
public function newThumbnail($docId) { $documentObj = new Document_Model($docId); $fileExt = $documentObj->getExt(); //The obfuscated file name, stored in the location column $docName = $documentObj->getLocation(); //The docName without the file extention $baseName = $documentObj->getBaseName(); switch ($fileExt) { case 'pdf': $url = base_url() . $this->config->item('dataDir') . $docName; $newImage = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.jpg'; if (extension_loaded('imagick')) { //create a thumbnail from the screenshot $thumb = new Imagick($url . [0]); $thumb->thumbnailImage(400, 0); $thumb->writeImage($newImage); $msg = array('status' => 'success', 'msg' => 'Thumbnail was successfully created.'); echo json_encode($msg); } else { $msg = array('status' => 'error', 'msg' => 'You must have ImageMagick installed to convert a pdf to thumbnail image.'); echo json_encode($msg); } break; case 'html': case 'php': case 'htm': //create PDF from HTML $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $docName, true); //create thumbnail from HTML $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $newImage = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.jpg'; $this->image->generateFromHtml($html, $newImage, $options, true); $msg = array('status' => 'success', 'msg' => 'Successfully created a thumbnail of your file.'); echo json_encode($msg); break; case 'png': case 'jpg': $config['source_image'] = $this->config->item('dataDir') . $docName; $config['new_image'] = $this->config->item('dataDir') . 'thumbnails/' . $docName; $config['maintain_ratio'] = true; $config['height'] = 200; $this->load->library('image_lib', $config); if (!$this->image_lib->resize()) { $msg = array('status' => 'error', 'msg' => 'There was an error trying to resize the image.'); echo json_encode($msg); } else { $msg = array('status' => 'success', 'msg' => 'Successfully created a thumbnail of your image.'); echo json_encode($msg); } break; default: $msg = array('status' => 'error', 'msg' => 'This filetype is currently not supported for making thumbnails.'); echo json_encode($msg); break; } }
public function permDeleteFiles($fileId) { $this->load->helper('file'); $userPermObj = new User_Perms_Model($this->session->id); if (!$userPermObj->userObj->isRoot()) { $error = array('status' => 'error', 'msg' => 'You do not have permission to delete this file'); return json_encode($error); exit; } // all ok, proceed! if (isset($fileId)) { if ($userPermObj->canAdmin($fileId)) { $fileObj = new Document_Model($fileId); $location = $fileObj->getLocation(); // delete from db $data = array('id' => $fileId); $this->db->delete('documents', $data); $this->db->delete('log', $data); $data = array('fid' => $fileId); $this->db->delete('dept_perms', $data); $this->db->delete('user_perms', $data); $realName = $fileObj->getBaseName(); $ext = $fileObj->getExt(); if (is_file($this->config->item('archiveDir') . $location)) { unlink($this->config->item('archiveDir') . $location); } if (is_file($this->config->item('dataDir') . 'pdf/' . $realName . '.pdf')) { unlink($this->config->item('dataDir') . 'pdf/' . $realName . '.pdf'); } if (is_file($this->config->item('dataDir') . 'thumbnails/' . $realName . '.png')) { unlink($this->config->item('dataDir') . 'thumbnails/' . $realName . '.png'); } if ($ext == 'docx') { if (is_file($this->config->item('archiveDir') . $realName . '.odt')) { unlink($this->config->item('archiveDir') . $realName . '.odt'); } if (is_file($this->config->item('archiveDir') . $realName . '.html')) { unlink($this->config->item('archiveDir') . $realName . '.html'); } } if (is_dir($this->config->item('revisionDir') . $fileId . '/')) { delete_files($this->config->item('revisionDir') . $fileId . '/', true); } return true; } } return false; }
public function doUploadAjax() { $post = $this->input->post(); $fileDataObj = new Document_Model($post['id']); $location = $fileDataObj->getLocation(); $this->load->library('upload'); $config['upload_path'] = $this->config->item('dataDir') . 'tmp'; $config['allowed_types'] = 'gif|jpg|png|php|html|pdf|doc|docx|odt|odp|ods|csv|xml|xls|xlsx|ppt'; $this->upload->initialize($config); if (!$this->upload->do_upload('userfile')) { $error = array('status' => 'error', 'msg' => $this->upload->display_errors('', '')); echo json_encode($error); exit; } else { $data = $this->upload->data(); $fileInfo = array('formData' => $post, 'fileData' => $data); $this->checkin->checkInFile($fileInfo); } }
public function updateDocument($id) { $docObj = new Document_Model($id); $location = $docObj->getLocation(); $baseName = $docObj->getBaseName(); $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $location, true); $this->image->setBinary($this->config->item('image_binary')); $options = array('format' => 'jpg', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $newImage = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.jpg'; $this->image->generateFromHtml($html, $newImage, $options, true); $options = array('viewport-size' => '1250', 'load-error-handling' => 'skip'); $newPdf = $this->config->item('dataDir') . 'pdf/' . $baseName . '.pdf'; $this->pdf->setBinary($this->config->item('pdf_binary')); $this->pdf->generateFromHtml($html, $newPdf, $options, true); $config['source_image'] = $newImage; $config['maintain_ratio'] = true; $config['height'] = 200; $this->load->library('image_lib', $config); $this->image_lib->resize(); }
public function index() { $docObj = new Document_Model($this->docId); $location = $docObj->getLocation(); $fileExt = $docObj->getExt(); $baseName = $docObj->getBaseName(); switch ($fileExt) { case 'html': case 'php': $url = base_url() . $this->config->item('dataDir') . 'pdf/' . $baseName . '.pdf'; break; case 'doc': case 'docx': $url = base_url() . $this->config->item('dataDir') . $baseName . '.odt'; break; case 'pdf': $url = base_url() . $this->config->item('dataDir') . $location; break; } header('Location:' . base_url() . 'assets/js/viewer#' . $url); }
public function newPdf($docId) { $documentObj = new Document_Model($docId); $fileExt = $documentObj->getExt(); //The obfuscated file name, stored in the location column $docName = $documentObj->getLocation(); //The docName without the file extention $baseName = $documentObj->getBaseName(); switch ($fileExt) { case 'html': case 'php': case 'htm': $html = $this->load->file(FCPATH . $this->config->item('dataDir') . $docName, true); $newPdf = FCPATH . $this->config->item('dataDir') . 'pdf/' . $baseName . '.pdf'; $options = array('viewport-size' => '1250', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $this->pdf->generateFromHtml($html, $newPdf, $options, true); $msg = array('status' => 'success', 'msg' => 'Successfully created a new pdf of your file.'); echo json_encode($msg); break; case 'png': case 'jpg': case 'gif': case 'tif': case 'bmp': $html = '<html><body><div class="container"><img class="img-responsive" src=" ' . FCPATH . $this->config->item('dataDir') . $docName . ' "></div></body></html>'; $newPdf = FCPATH . $this->config->item('dataDir') . 'pdf/' . $baseName . '.pdf'; $options = array('viewport-size' => '1250', 'user-style-sheet' => FCPATH . 'assets/css/bootstrap.css', 'load-error-handling' => 'skip'); $this->pdf->generateFromHtml($html, $newPdf, $options, true); $msg = array('status' => 'success', 'msg' => 'Successfully created a new pdf of your file.'); echo json_encode($msg); break; default: $msg = array('status' => 'error', 'msg' => 'This filetype is currently not supported for making pdfs.'); echo json_encode($msg); break; } }
public function checkInFile(array $data = null) { $id = $data['formData']['id']; $fileDataObj = new Document_Model($id); $location = $fileDataObj->getLocation(); if ($fileDataObj->getError() == '' && $fileDataObj->getStatus() == $this->uid) { //look to see how many revision are there $result = $fileDataObj->getTotalRevisions(); $revisionNumber = count($result); // if revision dir not available, create it if (!is_dir($this->config->item('revisionDir'))) { if (!mkdir($this->config->item('revisionDir'), 0775)) { $error = array('status' => 'error', 'msg' => 'Could not create the Revision Directory'); echo json_encode($error); exit; } } //creates the revision directory folder for the specific file being revised if (!is_dir($this->config->item('revisionDir') . $id)) { if (!mkdir($this->config->item('revisionDir') . $id, 0775)) { $error = array('status' => 'error', 'msg' => 'Could not create the Revision Directory ' . $this->config->item('revisionDir') . $id); echo json_encode($error); exit; } } //creates the revision directory pdf folder for the specific file being revised if (!is_dir($this->config->item('revisionDir') . $id . '/pdf')) { if (!mkdir($this->config->item('revisionDir') . $id . '/pdf', 0775)) { $error = array('status' => 'error', 'msg' => 'Could not create the Revision Directory ' . $this->config->item('revisionDir') . $id . '/pdf'); echo json_encode($error); exit; } } //creates the revision directory thumbnail folder for the specific file being revised if (!is_dir($this->config->item('revisionDir') . $id . '/thumbnails')) { if (!mkdir($this->config->item('revisionDir') . $id . '/thumbnails', 0775)) { $error = array('status' => 'error', 'msg' => 'Could not create the Revision Directory ' . $this->config->item('revisionDir') . $id . '/thumbnails'); echo json_encode($error); exit; } } $fileExt = $fileDataObj->getExt(); $baseName = $fileDataObj->getBaseName(); $fileName = $this->config->item('dataDir') . $location; $pdf = $this->config->item('dataDir') . 'pdf/' . $baseName . '.pdf'; $thumb = $this->config->item('dataDir') . 'thumbnails/' . $baseName . '.png'; $revPdf = $this->config->item('revisionDir') . $id . '/pdf/' . $id . '_' . ($revisionNumber - 1) . '.pdf'; $revThumb = $this->config->item('revisionDir') . $id . '/thumbnails/' . $id . '_' . ($revisionNumber - 1) . '.png'; /*if there is a pdf copy the pdf to the appropriate *revision directory and then delete old pdf */ if (file_exists($pdf)) { if (!copy($pdf, $revPdf)) { $error = array('status' => 'error', 'msg' => 'There was an error copying ' . $pdf . ' to ' . $revPdf); echo json_encode($error); } else { unlink($pdf); } } /*if there is a thumbnail copy the thumbnail to the *appropriate revision directory and delete old thumbnail */ if (file_exists($thumb)) { if (!copy($thumb, $revThumb)) { $error = array('status' => 'error', 'msg' => 'There was an error copying ' . $thumb . ' to ' . $revThumb); echo json_encode($error); } else { unlink($thumb); } } //read and close $fileHandler = fopen($fileName, "r"); $fileContent = fread($fileHandler, filesize($fileName)); fclose($fileHandler); //write and close $fileHandler = fopen($this->config->item('revisionDir') . $id . '/' . $id . '_' . ($revisionNumber - 1) . '.' . $fileExt, "w"); fwrite($fileHandler, $fileContent); fclose($fileHandler); // all OK, proceed! $userName = $this->userObj->getUserName(); //update revision log set the current revision to the next number $fileDataObj->updateCurrentRevision($revisionNumber); //add a new revision and set to current $fileDataObj->insertNewRevision($userName, $data['formData']['note']); //complete the file check in process $fileDataObj->checkIn($publishable, $data['fileData']['file_name']); // rename and save file if (!copy($data['fileData']['full_path'], $this->config->item('dataDir') . $location)) { $error = array('status' => 'error', 'msg' => 'We were unable to successfully copy the checked in file to the file directory'); echo json_encode($error); } else { unlink($data['fileData']['full_path']); $msg = array('status' => 'success', 'msg' => 'We successfully uploaded the checked in file, and create a revision directory for the previous version.'); echo json_encode($msg); } AccessLog_Model::addLogEntry($id, 'I'); } }