Beispiel #1
0
 public function downloadFile()
 {
     $fileId = $this->uri->segment(3);
     $this->fileDataObj = new Document_Model($fileId);
     if ($this->fileDataObj->getError() != null or $this->fileDataObj->getStatus() > 0 or $this->fileDataObj->isArchived()) {
         $this->session->set_flashdata('error', 'There was an error downloading that file.');
         redirect($_SERVER['HTTP_REFERRER']);
         exit;
     }
     $fileName = $this->config->item('dataDir') . $this->fileDataObj->getLocation();
     $this->fileDataObj->modifyRights($this->uid);
     AccessLog_Model::addLogEntry($fileId, 'O');
     AccessLog_Model::addLogEntry($fileId, 'D');
     if (file_exists($fileName)) {
         header('Cache-control: private');
         header('Content-Type: ' . get_mime_by_extension($fileName));
         header('Content-Disposition: attachment; filename="' . $this->fileDataObj->getRealName() . '"');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         readfile($fileName);
     }
 }
 public function rejectFile($data)
 {
     if (is_array($data['files'])) {
         foreach ($data['files'] as $file) {
             $checkBox[] = array('id' => $file);
         }
     } else {
         $checkBox[] = array('id' => $data['files']);
     }
     $reviewerComments = 'To= ' . $data['form']['to'] . ';Subject= ' . $data['form']['subject'] . ' ;Comments= ' . $data['form']['comments'];
     $date = date('M-d-Y H:i');
     $fullName = $this->session->firstName . ' ' . $this->session->lastName;
     $reviewerEmail = $this->session->email;
     $reviewerPhone = $this->session->phone;
     $reviewerDept = $this->userObj->getDeptName();
     if ($this->session->admin) {
         $idArray = $this->userObj->getAllRevieweeIds();
     } else {
         $idArray = $this->userObj->getRevieweeIds();
     }
     foreach ($checkBox as $key => $value) {
         // Check to make sure the current file_id is in their list of reviewable ID's
         if (in_array($value, $idArray)) {
             $fileId = $value['id'];
             $newFileObj = new Document_Model($fileId);
             $newUserObj = new User_Model($newFileObj->getOwner());
             $mailTo = $newUserObj->getEmailAddress();
             $deptId = $newFileObj->getDepartment();
             if (isset($data['form']['sendToUsers'][0]) && in_array('owner', $data['form']['sendToUsers'])) {
                 $data['form']['sendToUsers'] = array_slice($data['form']['sendToUsers'], 1);
                 $emailData = array('reviewer' => $fullName, 'title' => 'Author', 'fileName' => $newFileObj->getRealName(), 'status' => 'Rejected', 'data' => date('l \\t\\h\\e jS'), 'msg' => ' was rejected the document repository.', 'email' => $reviewerEmail, 'siteName' => $this->config->item('site_name'), 'phoneNumber' => $reviewerPhone, 'department' => $reviewerDept, 'comments' => $data['form']['comments']);
                 $body = $this->load->view('emails/publish_file_email_view', $emailData, true);
                 $subject = $newFileObj->getRealName() . ' has been rejected by ' . $fullName;
                 $this->email->setFrom($reviewerEmail, $fullName);
                 $this->email->addAddress($mailTo, $fullName);
                 $this->email->Subject = $subject;
                 $this->email->msgHTML($body);
                 $this->email->send();
             }
             $newFileObj->Publishable(-1);
             $newFileObj->setReviewerComments($reviewerComments);
             AccessLog_Model::addLogEntry($fileId, 'R');
             echo json_encode(array('status' => 'success', 'msg' => 'File Status successfully updated.'));
         } else {
             echo json_encode(array('status' => 'error', 'msg' => 'You cannot alter this files status.'));
             exit;
         }
     }
 }
Beispiel #3
0
 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');
     }
 }