function downloadfilesAction() { if ($_POST) { $doc_id = $_POST['doc_id']; $empDocuModel = new Default_Model_Employeedocs(); $empDocuments = $empDocuModel->getEmpDocumentsByFieldOrAll('id', $doc_id); if ($empDocuments[0]['attachments']) { $attachments = json_decode($empDocuments[0]['attachments'], true); if (count($attachments) > 0) { $new = array(); $ori = array(); foreach ($attachments as $k => $v) { $new[] = $v["new_name"]; $ori[] = $v["original_name"]; } } } $file_names = $new; $originalNames = $ori; $originalNamesString = implode(",", $originalNames); $archive_file_name = preg_replace('/[^a-zA-Z0-9\']/', '_', $empDocuments[0]['name']); $file_path = EMP_DOC_UPLOAD_PATH; define('DATE_CONSTANT', date('Y-m-d H:i:s')); $temp = md5(DATE_CONSTANT . uniqid()) . '.zip'; $zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip->open($file_path . $archive_file_name . $temp, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$archive_file_name}>\n"); } //add each files of $file_name array to archive for ($i = 0; $i < sizeof($file_names); $i++) { $name = ''; $count = substr_count($originalNamesString, $originalNames[$i]); if ($count > 1) { $name = $i . $originalNames[$i]; } else { $name = $originalNames[$i]; } $zip->addFile($file_path . $file_names[$i], $name); } $zip->close(); //then send the headers to foce download the zip file header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=" . $archive_file_name . '.zip'); header("Pragma: no-cache"); header("Expires: 0"); readfile($file_path . $archive_file_name . $temp); unlink($file_path . $archive_file_name . $temp); exit; } else { $this->_redirect('error'); } }
public function doceditAction() { if (defined('EMPTABCONFIGS')) { $empOrganizationTabs = explode(",", EMPTABCONFIGS); if (in_array('employeedocs', $empOrganizationTabs)) { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; $loginUserGroup = $auth->getStorage()->read()->group_id; $loginUserRole = $auth->getStorage()->read()->emprole; } $id = $this->getRequest()->getParam('userid'); $myEmployees_model = new Default_Model_Myemployees(); $getMyTeamIds = $myEmployees_model->getTeamIds($loginUserId); $teamIdArr = array(); if (!empty($getMyTeamIds)) { foreach ($getMyTeamIds as $teamId) { array_push($teamIdArr, $teamId['user_id']); } } if ($loginUserRole == SUPERADMINROLE || $loginUserGroup == MANAGEMENT_GROUP || $loginUserGroup == HR_GROUP || $loginUserGroup == MANAGER_GROUP && in_array($id, $teamIdArr)) { try { if ($id && is_numeric($id) && $id > 0 && $id != $loginUserId) { $employeeModal = new Default_Model_Employee(); $empdata = $employeeModal->getActiveEmployeeData($id); if (!empty($empdata)) { $empDocuModel = new Default_Model_Employeedocs(); $empDocuments = $empDocuModel->getEmpDocumentsByFieldOrAll('user_id', $id); $this->view->empDocuments = $empDocuments; } $usersModel = new Default_Model_Users(); $employeeData = $usersModel->getUserDetailsByIDandFlag($id); if (!empty($employeeData)) { $this->view->employeedata = $employeeData[0]; } $this->view->id = $id; $this->view->empdata = $empdata; } else { $this->view->rowexist = "norows"; } } catch (Exception $e) { $this->view->rowexist = "norows"; } // Show message to user when document was deleted by other user. $this->view->messages = $this->_helper->flashMessenger->getMessages(); } else { $this->_redirect('error'); } } else { $this->_redirect('error'); } } else { $this->_redirect('error'); } }
public function doceditAction() { if (defined('EMPTABCONFIGS')) { $empOrganizationTabs = explode(",", EMPTABCONFIGS); if (in_array('employeedocs', $empOrganizationTabs)) { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { $loginUserId = $auth->getStorage()->read()->id; } $id = $this->getRequest()->getParam('userid'); try { if ($id && is_numeric($id) && $id > 0 && $id != $loginUserId) { $employeeModal = new Default_Model_Employee(); $empdata = $employeeModal->getActiveEmployeeData($id); if (!empty($empdata)) { $empDocuModel = new Default_Model_Employeedocs(); $empDocuments = $empDocuModel->getEmpDocumentsByFieldOrAll('user_id', $id); $this->view->empDocuments = $empDocuments; } $usersModel = new Default_Model_Users(); $employeeData = $usersModel->getUserDetailsByIDandFlag($id); if (!empty($employeeData)) { $this->view->employeedata = $employeeData[0]; } $this->view->id = $id; $this->view->empdata = $empdata; } else { $this->view->rowexist = "norows"; } } catch (Exception $e) { $this->view->rowexist = "norows"; } } else { $this->_redirect('error'); } } else { $this->_redirect('error'); } }
function downloadfilesAction() { if ($_POST) { $doc_id = $_POST['doc_id']; $file_name = isset($_POST['file_name']) ? $_POST['file_name'] : ''; $empDocuModel = new Default_Model_Employeedocs(); $empDocuments = $empDocuModel->getEmpDocumentsByFieldOrAll('id', $doc_id); if (!empty($empDocuments)) { if ($empDocuments[0]['attachments']) { $attachments = json_decode($empDocuments[0]['attachments'], true); //Downloading single file if ($file_name) { $new = array(); $ori = array(); foreach ($attachments as $k => $v) { if ($file_name == $v["new_name"]) { $new[] = $v["new_name"]; $ori[] = $v["original_name"]; } } } else { if (count($attachments) > 0) { $new = array(); $ori = array(); foreach ($attachments as $k => $v) { $new[] = $v["new_name"]; $ori[] = $v["original_name"]; } } } } $file_names = $new; $originalNames = $ori; $originalNamesString = implode(",", $originalNames); if (isset($file_name) && empty($_POST['user_id'])) { $fileNameArr = explode('.', $file_name); $download_file_name = $empDocuments[0]['name'] . '_' . $ori[0]; //to appand original name for single file download $archive_file_name = preg_replace('/[^a-zA-Z0-9\']/', '_', $download_file_name); } else { $archive_file_name = preg_replace('/[^a-zA-Z0-9\']/', '_', $empDocuments[0]['name']); } $file_path = EMP_DOC_UPLOAD_PATH; $temp = md5(DATE_CONSTANT . uniqid()) . '.zip'; $zip = new ZipArchive(); //create the file and throw the error if unsuccessful if ($zip->open($file_path . $archive_file_name . $temp, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <{$archive_file_name}>\n"); } //add each files of $file_name array to archive for ($i = 0; $i < sizeof($file_names); $i++) { $name = ''; $count = substr_count($originalNamesString, $originalNames[$i]); if ($count > 1) { $name = $i . $originalNames[$i]; } else { $name = $originalNames[$i]; } $zip->addFile($file_path . $file_names[$i], $name); } $zip->close(); //then send the headers to foce download the zip file header("Content-type: application/zip"); header("Content-Disposition: attachment; filename=" . $archive_file_name . '.zip'); header("Pragma: no-cache"); header("Expires: 0"); readfile($file_path . $archive_file_name . $temp); unlink($file_path . $archive_file_name . $temp); exit; } else { $this->_helper->getHelper("FlashMessenger")->addMessage(array("error" => 'This document was deleted by other user just now.')); $auth = Zend_Auth::getInstance(); $loginUserId = $auth->getStorage()->read()->id; if (!empty($_POST['user_id'])) { if (!empty($_POST['context']) && $_POST['context'] == 'My Employees') { $this->_redirect('myemployees/docedit/userid/' . $_POST['user_id']); } else { $this->_redirect('employeedocs/index/userid/' . $_POST['user_id']); } } else { $this->_redirect('mydetails/documents'); } } } else { $this->_redirect('error'); } }