driver documents on cockpit.la should be downloadable and should include the driver's full name #3462

This commit is contained in:
Daniel Camargo 2014-07-17 10:46:07 -03:00
parent 8e7d60d44f
commit 5d8097fefd
8 changed files with 92 additions and 10 deletions

View File

@ -6,6 +6,37 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun
switch ( c::getPagePiece( 3 ) ) {
case 'download':
$hasPermission = ( c::admin()->permission()->check( ['global', 'drivers-all'] ) || ( $id_admin == $user->id_admin ) );
if( $hasPermission ){
$id_driver_document_status = c::getPagePiece( 4 );
$document = Cockpit_Driver_Document_Status::o( $id_driver_document_status );
if( $document->id_driver_document_status ){
$file = $document->doc_path();
$name = $document->driver()->name . ' - ' .$document->driver_document()->name;
$ext = pathinfo( $file, PATHINFO_EXTENSION );
$name .= '.' . $ext;
if( file_exists( $file ) ){
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename=' . $name );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate' );
header( 'Pragma: public' );
header( 'Content-Length: ' . filesize( $file ) );
readfile( $file );
exit;
} else {
$this->_error( 'download:file-not-found' );
}
} else {
$this->_error( 'download:file-not-found' );
}
} else {
$this->_error( 'download:permission-denied' );
}
break;
case 'list':
$this->_list();
break;
@ -239,8 +270,27 @@ class Controller_api_driver_documents extends Crunchbutton_Controller_RestAccoun
echo json_encode( $data );
}
private function _error( $error = 'invalid request' ){
echo json_encode( [ 'error' => $error ] );
exit();
private function _error( $error = 'invalid request', $filename = '' ){
if( strrpos( $error, 'download' ) === false ){
echo json_encode( [ 'error' => $error ] );
exit();
} else {
$error = str_replace( 'download:', '', $error );
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/octet-stream' );
header( 'Content-Disposition: attachment; filename=' . $error . '.txt' );
header( 'Expires: 0' );
header( 'Cache-Control: must-revalidate' );
header( 'Pragma: public' );
switch ( $error ) {
case 'file-not-found':
echo 'File Not Found!';
break;
case 'permission-denied':
echo 'Permission Denied!';
break;
}
}
}
}

View File

@ -14,14 +14,29 @@ class Cockpit_Driver_Document_Status extends Cana_Table {
return Util::uploadWWW() . 'drivers-doc/';
}
public function download_url(){
return '/api/driver/documents/download/' . $this->id_driver_document_status;
}
public function path(){
return Util::uploadPath() . '/drivers-doc/';
}
public function doc_path(){
return Util::uploadPath() . '/drivers-doc/' . $this->file;
}
public function url(){
return $this->www() . $this->file;
}
public function driver_document(){
if( !$this->_driver_document ){
$this->_driver_document = Cockpit_Driver_Document::o( $this->id_driver_document );
}
return $this->_driver_document;
}
public function document( $id_admin, $id_driver_document ){
$document = Cockpit_Driver_Document_Status::q( 'SELECT * FROM driver_document_status WHERE id_admin = ' . $id_admin . ' AND id_driver_document =' . $id_driver_document )->get( 0 );
if( $document->id_driver_document ){

View File

@ -143,7 +143,7 @@ class Crunchbutton_Util extends Cana_Model {
'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e',
'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b',
'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', '/' => '-', ' ' => '-', '.' => ''
'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', '/' => '-', ' ' => '-', '.' => '', '[' => '', ']' => ''
);
$stripped = preg_replace( array( '/\s{2,}/', '/[\t\n]/' ), ' ', $txt );

View File

@ -26,7 +26,7 @@
<a href="{{doc.url}}" target="_blank">Download Template</a>
</td>
<td>
<span ng-show="doc.status" title="Sent at {{doc.status.date_formated}}"><a href="{{doc.status.url}}" target="_blank">Download</a></span>
<span ng-if="doc.status" class="link orange" ng-click="download( doc.status.id_driver_document_status)" title="Sent at {{doc.status.date_formated}}">Download</span>
<span ng-if="!doc.status" ng-click="setDocument(doc.id_driver_document)" class="sp-label sp-label-warning link">
Upload missing doc
</span>
@ -46,7 +46,7 @@
{{doc.name}}
</td>
<td>
<span ng-show="doc.status" title="Sent at {{doc.status.date_formated}}"><a href="{{doc.status.url}}" target="_blank">Download</a></span>
<span ng-if="doc.status" class="link orange" ng-click="download( doc.status.id_driver_document_status)" title="Sent at {{doc.status.date_formated}}">Download</span>
<span ng-if="!doc.status" ng-click="setDocument(doc.id_driver_document)" class="sp-label sp-label-warning link">
Upload missing doc
</span>

View File

@ -33,7 +33,7 @@
<td>{{doc.doc}}</span></td>
<td><span ng-repeat="community in doc.communities">{{community}}</span></td>
<td>{{doc.date}}<br>{{doc.time}}</td>
<td><a ng-href="{{doc.url}}" target="_blank">Download</a></td>
<td><span class="link orange" ng-click="download( doc.id_driver_document_status)" title="Sent at {{doc.status.date_formated}}">Download</span></td>
<td>
<div ng-if="doc.approving">
<i class="fa fa-circle-o-notch fa-spin"></i>

View File

@ -94,7 +94,7 @@
{{doc.name}}
</td>
<td>
<span ng-show="doc.status" title="Sent at {{doc.status.date_formated}}"><a href="{{doc.status.url}}" target="_blank">Download</a></span>
<span ng-if="doc.status" class="link orange" ng-click="download( doc.status.id_driver_document_status )" title="Sent at {{doc.status.date_formated}}">Download</span>
<span ng-if="!doc.status" ng-click="setDocument(doc.id_driver_document)" class="sp-label sp-label-warning link">
Upload missing doc
</span>

View File

@ -394,6 +394,10 @@ NGApp.controller( 'DriversOnboardingDocsCtrl', function ( $scope, $timeout, Driv
$scope.navigation.link( '/drivers/onboarding/' + id_admin );
}
$scope.download = function( id_driver_document_status ){
DriverOnboardingService.docs.download( id_driver_document_status );
}
list();
} );
@ -578,6 +582,10 @@ NGApp.controller( 'DriversOnboardingFormCtrl', function ( $scope, $routeParams,
App.alert( 'Upload error, please try again or send us a message.' );
});
$scope.download = function( id_driver_document_status ){
DriverOnboardingService.docs.download( id_driver_document_status );
}
start();
} );
@ -673,6 +681,10 @@ NGApp.controller( 'DriversDocsFormCtrl', function( $scope, $fileUploader, Driver
App.alert( 'Upload error, please try again or send us a message.' );
});
$scope.download = function( id_driver_document_status ){
DriverOnboardingService.docs.download( id_driver_document_status );
}
} );
NGApp.controller( 'PreOnboardingCtrl', function( $scope, PreOnboardingService, CommunityService, DriverOnboardingService ) {

View File

@ -1,4 +1,4 @@
NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $routeParams ) {
NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $routeParams, $window ) {
var service = {};
@ -24,7 +24,7 @@ NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $rout
'save' : { 'method': 'POST', params : { action : 'save' } },
'pendency' : { 'method': 'GET', params : { action : 'pendency' } },
'list' : { 'method': 'GET', params : { action : 'list' } },
'approve' : { 'method': 'GET', params : { action : 'approve' } },
'approve' : { 'method': 'GET', params : { action : 'approve' } }
}
);
@ -116,6 +116,11 @@ NGApp.factory( 'DriverOnboardingService', function( $rootScope, $resource, $rout
} );
}
service.docs.download = function( id_driver_document_status ){
var url = App.service + 'driver/documents/download/' + id_driver_document_status;
$window.open( url );
}
// get docs list
service.docs.list = function( id_admin, callback ){
if( id_admin ){