public function includeAction()
 {
     $clientModel = new ClientModel();
     $clientModel->getAdapter()->beginTransaction();
     $savetype = $this->_request->getParam("type");
     $covenantdata = $this->_request->getParam("covenantdata");
     $clientPhoneModel = new ClientphonenumberModel();
     $clientAdressModel = new ClientaddressModel();
     $clientcovenantModel = new ClientcovenantModel();
     $paramClientArray = array();
     $idcpf = $this->_request->getParam('idcpf');
     $idcep = $this->_request->getParam('idcep');
     //      *** Remove caracteres do CPF e RG ***
     $idcpf = str_replace(array(".", "-"), "", $idcpf);
     $idcep = str_replace("-", " ", $idcep);
     $paramClientArray = array('cdclient' => $this->_request->getParam('cdclient'), 'nmclient' => $this->_request->getParam('nmclient'), 'nmmail' => $this->_request->getParam('nmmail'), 'fgsex' => $this->_request->getParam('fgsex'), 'idrg' => $this->_request->getParam('idrg'), 'idcpf' => $idcpf, 'dtbirth' => $this->_request->getParam('dtbirth'), 'dtdum' => $this->_request->getParam('dtdum'), 'nmprofessional' => $this->_request->getParam('nmprofessional'), 'nrweight' => $this->_request->getParam('nrweight'), 'nrheight' => $this->_request->getParam('nrheight'), 'nmimage' => $this->_request->getParam('nmimage'), 'fgbloodtype' => $this->_request->getParam('fgbloodtype'), 'fgdufactor' => $this->_request->getParam('fgdufactor'), 'fgrhfactor' => $this->_request->getParam('fgrhfactor'), 'fgskincolor' => $this->_request->getParam('fgskincolor'), 'nrsonsnumber' => $this->_request->getParam('nrsonsnumber'), 'nmfather' => $this->_request->getParam('nmfather'), 'nmmother' => $this->_request->getParam('nmmother'), 'dsobservation' => $this->_request->getParam('dsobservation'), 'fgvip' => $this->_request->getParam('fgvip'), 'fgmailmkt' => $this->_request->getParam('fgmailmkt'), 'fgsmoker' => $this->_request->getParam('fgsmoker'), 'fgdiabetes' => $this->_request->getParam('fgdiabetes'), 'fgmaritalstatus' => $this->_request->getParam('fgmaritalstatus'), 'nrcardnumber' => $this->_request->getParam('nrcardnumber'));
     if (isset($paramClientArray["dtbirth"]) && $paramClientArray["dtbirth"] != '') {
         $paramClientArray["dtbirth"] = GslabUtils::dateToDatabaseFormat($paramClientArray["dtbirth"]);
     }
     if (isset($paramClientArray["dtdum"]) && $paramClientArray["dtdum"] != '') {
         $paramClientArray["dtdum"] = GslabUtils::dateToDatabaseFormat($paramClientArray["dtdum"]);
     }
     if ($savetype == 'edit') {
         $this->_model->update($paramClientArray, 'cdclient = ' . $this->_request->getParam('cdclient'));
         $cdclient = $this->_request->getParam('cdclient');
     } else {
         if ($savetype == 'add') {
             $cdclient = $this->_model->insert($paramClientArray);
         }
     }
     //*** Insere os dados do ClientAddress***
     $paramAddressArray = array('cdclient' => $cdclient, 'idcep' => $idcep, 'nmstreet' => $this->_request->getParam('nmstreet'), 'idaddresstype' => $this->_request->getParam('idaddresstype'), 'nmclientaddress' => $this->_request->getParam('nmclientaddress'), 'nrnumber' => $this->_request->getParam('nrnumber'), 'nmneighborhood' => $this->_request->getParam('nmneighborhood'), 'idcity' => $this->_request->getParam('idcity'), 'idstate' => $this->_request->getParam('fgstate'), 'idcomplement' => $this->_request->getParam('idcomplement'));
     if ($savetype == 'edit') {
         $clientAdressModel->update($paramAddressArray, 'cdclient = ' . $this->_request->getParam('cdclient'));
     } else {
         if ($savetype == 'add') {
             $clientAdressModel->insert($paramAddressArray);
         }
     }
     //*** Insere os dados do ClientPhoneNumber  ***
     if ($this->_request->getParam('nrphonenumber') != '' || $this->_request->getParam('nrcellphone') != '') {
         $paramPhoneArray = array('cdclient' => $cdclient, 'nrphonenumber' => $this->_request->getParam('nrphonenumber'), 'nrdddphone' => $this->_request->getParam('nrdddphone'), 'nrdddcellphone' => $this->_request->getParam('nrdddcellphone'), 'nrcellphonenumber' => $this->_request->getParam('nrcellphone'));
         if ($this->_request->getParam('cdclientphonenumber') != '') {
             $clientPhoneModel->update($paramPhoneArray, 'cdclientphonenumber = ' . $this->_request->getParam('cdclientphonenumber'));
         } else {
             $clientPhoneModel->insert($paramPhoneArray);
         }
     }
     if (!empty($covenantdata)) {
         $covenantdata = json_decode($covenantdata);
         $client = $this->_request->getParam("cdclient");
         if ($client != '') {
             $clientcovenantModel->delete('cdclient = ' . $client);
         }
         foreach ($covenantdata as $linha) {
             if ($linha->fgstatus == 0) {
                 $linha->fgstatus = 2;
             }
             $arrayCovenant = array('cdclient' => $cdclient, 'cdcovenant' => $linha->cdcovenant, 'idcovenantcard' => $linha->nrregistration, 'nmcardholder' => $linha->nmcardholder, 'dtreference' => date("Y-m-d H:i:s"), 'fgactive' => $linha->fgstatus);
             try {
                 $clientcovenantModel->insert($arrayCovenant);
             } catch (Exception $e) {
                 header("HTTP/1.0 406 Não foi possivel salvar os dados do paciente no sistema: Erro Interno -> " . $e->getMessage() . ".");
             }
             $arrayCovenant = '';
         }
     }
     echo 'tudo ok';
     $this->_model->getAdapter()->commit();
     //        $values = $this->_request->getParam("data");
     //        $values = explode("&", $values);
     //
     //        /*
     //         * Organiza em um array os dados recebidos
     //         */
     //        $formData = array();
     //        foreach($values as $value)
     //        {
     //            $value = explode("=", $value);
     //            $formData[ $value[0] ] = $value[1];
     //            $formData = str_replace("+", " ", $formData);
     //        }
     //
     //        $values = $formData;
     //
     //
     //        $savetype = $this->_request->getParam("type");
     //        $covenantdata = $this->_request->getParam("covenantdata");
     ////        $img = $_GET["img"];
     //
     //        $clientPhoneModel = new ClientphonenumberModel();
     //        $clientAdressModel = new ClientaddressModel();
     //        $clientcovenantModel = new ClientcovenantModel();
     //
     ////      *** Remove caracteres do CPF e RG ***
     //        $values["idcpf"] = str_replace(array(".", "-"), "", $values["idcpf"]);
     //        $values["nrheight"] = str_replace(",", ".", $values["nrheight"]);
     //
     //        $this->_model->getAdapter()->beginTransaction();
     //
     //        $paramClientArray = array();
     //
     //        try
     //        {
     //
     //            $idstate = GslabUtils::getBrazilianStatePrefix($values['idstate']);
     //            $nmclientaddress = GslabUtils::getLogradouroSaveDataBase($values['idaddresstype']);
     //
     //
     //
     //            $paramClientArray = array(
     //                'cdclient' => $values['cdclient'],
     //                'nmclient' => $values['nmclient'],
     //                'nmmail' => $values['nmmail'],
     //                'fgsex' => $fgsex,
     //                'idrg' => $values['idrg'],
     //                'idcpf' => $values['idcpf'],
     //                'dtbirth' => $values['dtbirth'],
     //                'nrweight' => $values['nrweight'],
     //                'nrheight' => $values['nrheight'],
     ////                'nmimage' => $img,
     //                'fgbloodtype' => $values['fgbloodtype'],
     //                'fgdufactor' => $values['fgdufactor'],
     //                'fgrhfactor' => $values['fgrhfactor'],
     //                'fgskincolor' => $values['fgskincolor'],
     //                'nrsonsnumber' => $values['nrsonsnumber'],
     //                'nmfather' => $values['nmfather'],
     //                'nmmother' => $values['nmmother'],
     //                'dsobservation' => $values['dsobservation'],
     //                'fgvip' => $fgvip,
     //                'fgmailmkt' => $fgmailmkt,
     //                'fgsmoker' => $fgsmoker,
     //                'fgdiabetes' => $fgdiabetes
     //            );
     //
     //            if (isset($paramClientArray["dtbirth"]) && $paramClientArray["dtbirth"] != '')
     //                $paramClientArray["dtbirth"] = GslabUtils::dateToDatabaseFormat($paramClientArray["dtbirth"]);
     //
     //            if ($savetype == 'edit')
     //                $this->_model->update($paramClientArray, 'cdclient = ' . $values['cdclient']);
     //            else if ($savetype == 'add')
     //                $values['cdclient'] = $this->_model->insert($paramClientArray);
     //
     //            //*** Insere os dados do ClientAddress***
     //            $paramAddressArray = array(
     //                'cdclient' => $values['cdclient'],
     //                'idcep' => $values['idcep'],
     //                'nmstreet' => $values['nmstreet'],
     //                'idaddresstype' => $values['idaddresstype'],
     //                'nmclientaddress' => $nmclientaddress,
     //                'nrnumber' => $values['nrnumber'],
     //                'nmneighborhood' => $values['nmneighborhood'],
     //                'idcity' => $values['idcity'],
     //                'idstate' => $values['idstate'],
     //                'idcomplement' => $values['idcomplement']
     //            );
     //
     //            if ($savetype == 'edit')
     //                $clientAdressModel->update($paramAddressArray, 'cdclient = ' . $values['cdclient']);
     //            else if ($savetype == 'add')
     //                $clientAdressModel->insert($paramAddressArray);
     //
     //
     //            //*** Insere os dados do ClientPhoneNumber  ***
     //            if (isset($values['nrcomercialphone']) && $values['nrcomercialphone'] != '')
     //            {
     //                $dddRes = 47;
     //                $numRes = $values['nrcomercialphone'];
     //
     //                $paramPhoneArray = array(
     //                    'cdclient' => $values['cdclient'],
     //                    'nrdddphone' => $dddRes,
     //                    'nrphonenumber' => $numRes,
     //                    'fgtypephone' => 1
     //                );
     //
     //
     //                if (count($clientPhoneModel->fetchAll('cdclient = ' . $values['cdclient'])) > 0)
     //                    $clientPhoneModel->update($paramPhoneArray, 'cdclient = ' . $values['cdclient']);
     //                else
     //                    $clientPhoneModel->insert($paramPhoneArray);
     //
     //            }
     //
     //            if (isset($values['nrphonenumber']) && $values['nrphonenumber'] != '')
     //            {
     //                $numeroCel = explode(" ", $values['nrphonenumber']);
     //                $dddCel = 47;
     //                $numCel = $values['nrphonenumber'];
     //
     //                $paramCelArray = array(
     //                    'cdclient' => $values['cdclient'],
     //                    'nrdddphone' => $dddCel,
     //                    'nrphonenumber' => $numCel,
     //                    'fgtypephone' => 3
     //                );
     //
     //                if (count($clientPhoneModel->fetchAll('cdclient = ' . $values['cdclient'])) > 0)
     //                    $clientPhoneModel->update($paramCelArray, 'cdclient = ' . $values['cdclient']);
     //                else
     //                    $clientPhoneModel->insert($paramCelArray);
     //            }
     //
     //            //$clientcovenantModel->delete('cdclient = ' . $values['cdclient']);
     //            //print_r('cdclient: '. $values['cdclient']);
     //            //die('here');
     //
     //            if(!empty($covenantdata))
     //            {
     //                $covenantdata = json_decode($covenantdata);
     //                foreach ($covenantdata as $linha)
     //                {
     //                    if ($linha->fgstatus == 0)
     //                        $linha->fgstatus = 2;
     //
     //                    $arrayCovenant = array(
     //                        'cdclient' => $values['cdclient'],
     //                        'cdcovenant' => $linha->cdcovenant,
     //                        'idcovenantcard' => $linha->nrregistration,
     //                        'nmcardholder' => $linha->nmcardholder,
     //                        'dtreference' => date("Y-m-d H:i:s"),
     //                        'fgactive' => $linha->fgstatus
     //                    );
     //
     //                    try
     //                    {
     //                        $clientcovenantModel->insert($arrayCovenant);
     //                    }
     //                    catch (Exception $e)
     //                    {
     //                        header("HTTP/1.0 406 Não foi possivel salvar os dados do paciente no sistema: Erro Interno -> ".$e->getMessage().".");
     //                    }
     //                    $arrayCovenant = '';
     //                }
     //                //print_r('covenantdata1: '. $arrayCovenant);
     //                //die();
     //
     //            }
     //
     //            echo 'tudo ok';
     //            $this->_model->getAdapter()->commit();
     //        }
     //        catch (Exception $e)
     //        {
     //            $this->_model->getAdapter()->rollBack();
     //            header("HTTP/1.0 406 Não foi possivel salvar os dados do paciente no sistema: Erro Interno -> ".$e->getMessage().".");
     //        }
 }