Retirar if de uma Rotina

20/03/2014

0

PHP

Bem pessoal sou novo na área de programação, estou fazendo um curso aqui com vocês e correndo a atras de outros recursos.
Enfim uma empresa me chamou para atualizar o site e me deparei com esse problema.
Me pediram para tirar a validação de um envio de arquivos, só que estou inseguro de fazer vou passar o código espero que me ajudem.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once('application_controller.php');

include_once("./application/libraries/MPDF56/mpdf.php");

class Vacancies_Controller extends Application_Controller {

function __construct(){
parent::__construct();
$this->authenticate_user();
}



public function index($wave = '', $auditor_register = ''){

$this->authorize(array('coordinator', 'auditor'));
$current_user = $this->current_user();

$this->data['waves_list'] = $waves = $this->vacancy->waves();
$wave = empty($wave) ? $waves[0]['wave'] : $wave;

$this->data['wave'] = $wave;

if($current_user->type == 'auditor' || $auditor_register ){

if($current_user->type == 'auditor'){
$auditor_register = $this->current_user()->register_id;
}

$this->data['auditor'] = $auditor_register;
$this->data['open_vacancies'] = $this->vacancy->open_vacancies($auditor_register, $wave);
$this->data['close_vacancies'] = $this->vacancy->close_vacancies($auditor_register, $wave);

}
elseif($current_user->type == 'coordinator'){

$this->data['auditors'] = $this->vacancy->auditors_by_coordinator($current_user, $wave);
$this->view = 'vacancies/auditors';
}


}


public function vacancy($auditor_register = ''){

try{
$user = $this->user->find_by_register_id($auditor_register);
$this->data['open_vacancies'] = $this->vacancy->open_vacancies($current_user);
$this->data['close_vacancies'] = $this->vacancy->close_vacancies($current_user);
}catch(Exception $e){
$this->session->set_flashdata( array('error' => "Auditor não encontrado."));
redirect('feed', 'refresh');
}


}


public function add($wave = '', $promoter_register = ''){

try{


if($promoter_register){

$waves = $this->vacancy->wave();
$wave = empty($wave) ? $waves[0]['wave'] : $wave;


$promoter_files = $this->promoter_files->new_model();
$promoter_files->promoter_register = $promoter_register;
$promoter_files->wave = $wave;
$this->data['promoter_files'] = $promoter_files;

}



$params = $this->input->post('promoter_files');
if($params){

$promoter_files = $this->promoter_files->new_model($params);
$promoter_files->auditor_register = $this->current_user()->register_id;

if (!empty($_FILES['photo']['name'])){
$return = $promoter_files->do_upload('photo');
if($return === FALSE){
$this->form_validation->set_rules('photo', 'Imagem', 'callback_handle_upload');
}
}


if (!empty($_FILES['scanner']['name'])){
$return = $promoter_files->do_upload('scanner');
if($return === FALSE){
$this->form_validation->set_rules('scanner', 'Scanner', 'callback_handle_upload');
}
}



if( $promoter_files->save()){
$this->session->set_flashdata( array('success' => "Arquivos e nota registrado com sucesso."));
redirect('vacancies', 'refresh');
}else{
$this->view = 'vacancies/add';
$this->data['promoter_files'] = $promoter_files;
}

}


}catch(Exception $e){
$this->session->set_flashdata( array('error' => "Auditor não encontrado."));
redirect('feed', 'refresh');
}


}

public function pdf($wave = '', $promoter_register = '', $auditor_register = ''){


$waves = $this->vacancy->waves();
$wave = empty($wave) ? $waves[0]['wave'] : $wave;




$mpdf = new mPDF('', // mode - default ''
'', // format - A4, for example, default ''
0, // font size - default 0
'', // default font family
15, // margin_left
15, // margin right
10, // margin top
16, // margin bottom
9, // margin header
9, // margin footer
'L'); // L - landscape, P - portrait

$mpdf->allow_charset_conversion = true;
$mpdf->charset_in='UTF-8';

// Exibir a pagina inteira no browser
$mpdf->SetDisplayMode('fullpage');

// Cabeçalho: Seta a data/hora completa de quando o PDF foi gerado + um texto no lado direito
//$mpdf->SetHTMLHeader('<div style="border-bottom: 1px solid #000000;">Tracking Trade</div>');


// Rodapé: Seta a data/hora completa de quando o PDF foi gerado + um texto no lado direito
//$mpdf->SetFooter('{DATE j/m/Y H:i}|/|Tracking Trade');



$promoter = $this->user->find_by_register_id($promoter_register);
$html_retorno .= "<table>";
$html_retorno .= "<tr>";
$html_retorno .= "<td width='200px' style='font-size:20px;padding-left:80px;padding-top:30px;'>".$auditor_register."</td>";
$html_retorno .= "<td width='200px' style='font-size:20px;padding-left:100px;padding-top:30px;'>".$promoter->register_id."</td>";
$html_retorno .= "<td width='700px' style='font-size:20px;padding-left:40px;padding-top:30px;'>".$promoter->fullname."</td>";
$html_retorno .= "<td width='150px' style='font-size:30px;font-weight:bold;'> ONDA ".$wave."</td>";
$html_retorno .= "</tr>";
$html_retorno .= "</table>";


$html = "<html>";
$html .= "<head></head>";
$html .= "<body>";
$html .= $html_retorno;
$html .= "</body></html>";


$stylesheet = file_get_contents(site_url("/assets/stylesheets/pdf.css"));
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);

// define um nome para o arquivo PDF
$filename = 'formulario_'.date("Y-m-d_his").'.pdf';

$mpdf->Output($filename, 'D');
die();
//$mpdf->Output();
}


public function xls($wave = '', $auditor_register = ''){
$this->authorize(array('auditor', 'coordinator'));
$current_user = $this->current_user();

$this->data['waves_list'] = $waves = $this->vacancy->waves();
$wave = empty($wave) ? $waves[0]['wave'] : $wave;
$auditor_register = $auditor_register ? $auditor_register : $current_user->register_id;


$this->data['wave'] = $wave;
$this->data['auditor_register'] = $auditor_register;
$this->data['open_vacancies'] = $this->vacancy->open_vacancies($auditor_register, $wave);
$this->data['close_vacancies'] = $this->vacancy->close_vacancies($auditor_register, $wave);


$this->layout = 'ajax';
$this->view = 'vacancies/vacancy.xls';

}






}
Angelo Silva

Angelo Silva

Responder

Posts

20/03/2014

Marcio Araujo

Angelo, tentar ver se essa funcionalidade afeta outras operações. tem como vc pegar uma copia desse sistema? se sim, fica mais facil saber.
Responder

01/04/2014

Angelo Silva

obrigado amigo já consegui.
Responder

Que tal ter acesso a um e-book gratuito que vai te ajudar muito nesse momento decisivo?

Ver ebook

Recomendado pra quem ainda não iniciou o estudos.

Eu quero
Ver ebook

Recomendado para quem está passando por dificuldades nessa etapa inicial

Eu quero

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar