Beispiel #1
0
 public function executeBasic(sfWebRequest $request)
 {
     $doc = new sfTinyDoc();
     $doc->createFrom();
     $doc->loadXml('content.xml');
     $nbr_col = 10;
     $nbr_row = 5;
     for ($col = 1; $col <= $nbr_col; $col++) {
         $columns[$col] = 'column_' . $col;
     }
     // Creating data
     $data = array();
     for ($row = 1; $row <= $nbr_row; $row++) {
         $record = array();
         for ($col = 1; $col <= $nbr_col; $col++) {
             $record[$columns[$col]] = $row * $col * 2;
         }
         $data[$row] = $record;
     }
     $doc->mergeXmlBlock('c0,c1,c2', $columns);
     $doc->mergeXmlBlock('r', $data);
     $doc->saveXml();
     $doc->close();
     $doc->sendResponse();
     $doc->remove();
     throw new sfStopException();
 }
Beispiel #2
0
 public static function printDocument($OCESSIO)
 {
     $OCM = $OCESSIO->getCessiomaterials();
     $MAT = "";
     foreach ($OCM as $OCMAT) {
         $OMAT = $OCMAT->getMaterial();
         $MAT .= ' un/a ' . $OMAT->getNom() . ' amb identificador ' . $OMAT->getIdentificador() . ',';
     }
     // create the document
     $doc = new sfTinyDoc();
     $doc->createFrom(array('extension' => 'docx'));
     $doc->loadXml('word/document.xml');
     $doc->mergeXmlField('NOM', $OCESSIO->getNom());
     $doc->mergeXmlField('DNI', $OCESSIO->getDni());
     $doc->mergeXmlField('REPRESENTANT', $OCESSIO->getRepresentant());
     $doc->mergeXmlField('MATERIAL', $MAT);
     if ($OCESSIO->getMaterialNoInventariat() != '') {
         $doc->mergeXmlField('MATERIAL_NO_INVENTARIAT', ' i ' . $OCESSIO->getMaterialNoInventariat());
     } else {
         $doc->mergeXmlField('MATERIAL_NO_INVENTARIAT', '');
     }
     $doc->mergeXmlField('MOTIU', $OCESSIO->getMotiu());
     $doc->mergeXmlField('CONDICIONS1', $OCESSIO->getCondicions());
     $doc->mergeXmlField('DATA_SORTIDA', $OCESSIO->getDataCessio());
     $doc->mergeXmlField('DATA_RETORN', $OCESSIO->getDataRetorn());
     $doc->saveXml();
     $doc->close();
     // send and remove the document
     $doc->sendResponse();
     $doc->remove();
     throw new sfStopException();
 }
 /**
  * Matrícules
  *
  */
 public function executeGMatricules(sfWebRequest $request)
 {
     $this->setLayout('gestio');
     $this->IDS = $this->getUser()->getSessionPar('idS');
     //Netegem cerca
     if ($request->getParameter('accio') == 'C') {
         $this->CERCA = $this->getUser()->setSessionPar('cerca', array('text' => '', 'select' => 2));
         $this->PAGINA = $this->getUser()->setSessionPar('pagina', 1);
         $this->redirect('gestio/gMatricules?accio=CA');
     }
     $this->CERCA = $this->getUser()->ParReqSesForm($request, 'cerca', array('text' => "", 'select' => 2));
     $this->PAGINA = $this->getUser()->ParReqSesForm($request, 'PAGINA', 1);
     $accio = $this->getUser()->ParReqSesForm($request, 'accio', 'CA');
     //Inicialitzem el formulari de cerca
     $this->FCerca = new CercaTextChoiceForm();
     $this->FCerca->setChoice(array(2 => 'Alumnes', 3 => 'Matrícula'));
     $this->FCerca->bind($this->CERCA);
     //Inicialitzem variables
     $this->MODE = array('CONSULTA' => false, 'NOU' => false, 'EDICIO' => false, 'LMATRICULES' => false, 'VERIFICA' => false);
     if ($request->isMethod('POST')) {
         if ($request->hasParameter('BCERCA')) {
             switch ($this->CERCA['select']) {
                 case 2:
                     $accio = 'CA';
                     break;
                 case 3:
                     $accio = 'CM';
                     break;
             }
             $this->PAGINA = 1;
         } elseif ($request->hasParameter('BNOU')) {
             $accio = 'NU';
         } elseif ($request->hasParameter('BSAVENEWUSER')) {
             $accio = 'SAVE_NEW_USER';
         } elseif ($request->hasParameter('BSELCURS')) {
             $accio = 'SNU';
         } elseif ($request->hasParameter('BSAVECURS')) {
             $accio = 'SAVE_CURS';
         } elseif ($request->hasParameter('BPAGAMENT')) {
             $accio = 'PAGAMENT';
         } elseif ($request->hasParameter('BSUBMIT')) {
             $accio = 'S';
         } elseif ($request->hasParameter('BDELETE')) {
             $accio = 'D';
         } elseif ($request->hasParameter('BSAVE')) {
             $accio = 'SAVE_MATRICULA';
         } elseif ($request->hasParameter('BSAVEMATRICULA')) {
             $accio = 'SAVE_NEW_MATRICULA';
         }
     }
     //Aquest petit bloc és per si es modifica amb un POST el que s'ha enviat per GET
     $this->getUser()->setSessionPar('accio', $accio);
     $this->getUser()->setSessionPar('PAGINA', $this->PAGINA);
     //Guardem la pàgina per si hem fet una consulta nova
     switch ($accio) {
         // Iniciem una nova matrícula
         case 'NU':
             $this->IDM = $request->getParameter('IDM', null);
             $this->CURSOS = MatriculesPeer::getCursosMatriculacio($this->IDS);
             $this->MODE = 'MAT_USUARI';
             break;
             //Consultem els usuaris disponibles
         //Consultem els usuaris disponibles
         case 'AJAX_USUARIS':
             $RET = UsuarisPeer::cercaTotsCampsSelect($request->getParameter('q'), $request->getParameter('lim'), $this->IDS);
             return $this->renderText(json_encode($RET));
             break;
         case 'AJAX_GET_CURSOS':
             $IDU = $request->getParameter('IDU', null);
             return $this->renderPartial('matriculesLlistatCursos', array('IDU' => $IDU, 'CURSOS' => MatriculesPeer::getCursosMatriculacio($this->IDS)));
             break;
             //Carreguem les dades de pagament de la matrícula
         //Carreguem les dades de pagament de la matrícula
         case 'AJAX_EXTRES':
             $OC = CursosPeer::retrieveByPK($request->getParameter('IDC'));
             $IDU = $request->getParameter('IDU');
             //Si no hem trobat el curs, retornem un error
             if (!$OC instanceof Cursos) {
                 return $this->renderPartial('matricules', array("OC" => new Cursos(), "RET" => array(), "ERROR" => "ERROR: El curs no s'ha trobat."));
                 //Treiem les dades extres que s'han d'entrar
             } else {
                 $MostraPreu = !$OC->isPle();
                 return $this->renderPartial('matricules', array("IDU" => $IDU, "OC" => $OC, "RET" => $OC->getDescomptesArray($MostraPreu), "ERROR" => ""));
             }
             break;
             //Guardem les dades de la matrícula i carreguem les dades de pagament o bé redireccionem cap a OK.
         //Guardem les dades de la matrícula i carreguem les dades de pagament o bé redireccionem cap a OK.
         case 'SAVE_NEW_MATRICULA':
             //La matrícula pot ser amb pagament de targeta de crèdit o bé en metàl·lic.
             $RS = $request->getParameter('matricules');
             $RET = MatriculesPeer::saveNewMatricula($RS['idU'], $RS['idC'], "", $RS['descompte'], $RS['mode_pagament'], $RS['idDadesBancaries']);
             $AVISOS = $RET['AVISOS'];
             //Si la matrícula surt amb algun estat que no sigui tpv, fem la redirecció i mostrem el missatge.
             if (array_key_exists('ERR_USUARI', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=0&MISSATGE=ERR_USUARI');
             } elseif (array_key_exists('ERR_CURS', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=0&MISSATGE=ERR_CURS');
             } elseif (array_key_exists('ERR_JA_TE_UNA_MATRICULA', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=0&MISSATGE=ERR_JA_TE_UNA_MATRICULA');
             } elseif (array_key_exists('CURS_PLE', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=CURS_PLE');
             } elseif (array_key_exists('CURS_PLE_LLISTA_ESPERA', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=CURS_PLE_LLISTA_ESPERA');
             } elseif (array_key_exists('RESERVA_OK', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=RESERVA_OK');
             } elseif (array_key_exists('MATRICULA_METALIC_OK', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=MATRICULA_METALIC_OK');
             } elseif (array_key_exists('MATRICULA_DOMICILIACIO_OK', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=MATRICULA_DOMICILIACIO_OK');
             } elseif (array_key_exists('MATRICULA_CODI_BARRES', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=' . $RET['OM']->getIdmatricules() . '&MISSATGE=MATRICULA_METALIC_OK');
             } elseif (array_key_exists('ERR_CURS_RESTRINGIT', $AVISOS)) {
                 $this->redirect('gestio/gMatricules?accio=PAGAMENT&IDM=0&MISSATGE=ERR_CURS_RESTRINGIT');
             }
             //La matrícula es paga amb TPV
             if (array_key_exists('PAGAMENT_TPV', $AVISOS)) {
                 $NOM = UsuarisPeer::retrieveByPK($RET['OM']->getUsuarisUsuariid())->getNomComplet();
                 $this->TPV = MatriculesPeer::getTPV($RET['OM']->getPagat(), $NOM, $RET['OM']->getIdmatricules(), $RET['OM']->getSiteid(), false);
                 $this->URL = OptionsPeer::getString('TPV_URL', $RET['OM']->getSiteId());
                 $this->setLayout('blank');
                 $this->setTemplate('pagament');
             }
             break;
             //Entenem que hem fet un pagament correcte i mostrem pantalla de finalització.
         //Entenem que hem fet un pagament correcte i mostrem pantalla de finalització.
         case 'PAGAMENT':
             $this->IDM = $request->getParameter('IDM');
             $this->OM = MatriculesPeer::retrieveByPK($this->IDM);
             $this->MISSATGE = $request->getParameter('MISSATGE');
             $this->MODE = 'PAGAMENT';
             $this->getUser()->addLogAction($accio, 'gMatricules', $this->IDM);
             myUser::addLogTimeline('alta', 'matricules', $this->getUser()->getSessionPar('idU'), $this->IDS, $this->IDM);
             break;
             //Si hem fet un pagament amb targeta, anem a la següent pantalla. El TPV serà l'encarregat de donar-li l'estat oportú.
         //Si hem fet un pagament amb targeta, anem a la següent pantalla. El TPV serà l'encarregat de donar-li l'estat oportú.
         case 'OK':
             $RedSys = new sha256();
             $decode = $RedSys->decodeMerchantParameters($request->getParameter('Ds_MerchantParameters'));
             $RedSys->stringToArray($decode);
             $parametres = $RedSys->vars_pay;
             $this->IDM = $parametres['Ds_MerchantData'];
             if ($this->IDM > 0) {
                 $this->MISSATGE = "PAGAMENT_TPV";
             } else {
                 $this->MISSATGE = "PAGAMENT_TPV_KO";
             }
             $this->MODE = 'PAGAMENT';
             break;
             //Esborra una matrícula
         //Esborra una matrícula
         case 'D':
             $RM = $request->getParameter('matricules');
             $OM = MatriculesPeer::retrieveByPK($RM['idMatricules']);
             $OM->setActiu(false);
             $OM->save();
             $this->getUser()->addLogAction($accio, 'gMatricules', $OM);
             myUser::addLogTimeline('baixa', 'matricules', $this->getUser()->getSessionPar('idU'), $this->IDS, $RM['idMatricules']);
             break;
             //Edita una matrícula
         //Edita una matrícula
         case 'E':
             $this->IDM = $request->getParameter('IDM');
             $this->FMATRICULA = MatriculesPeer::initialize($this->IDM, $this->IDS);
             $this->MODE = 'EDICIO';
             break;
             //Guardem una matrícula modificada
         //Guardem una matrícula modificada
         case 'SAVE_MATRICULA':
             $RS = $request->getParameter('matricules');
             $this->FMATRICULA = MatriculesPeer::initialize($RS['idMatricules'], $this->IDS);
             $this->FMATRICULA->bind($RS);
             if ($this->FMATRICULA->isValid()) {
                 $this->FMATRICULA->save();
                 $this->getUser()->addLogAction($accio, 'gMatricules', $this->FMATRICULA->getObject());
                 myUser::addLogTimeline('modificació', 'matricules', $this->getUser()->getSessionPar('idU'), $this->IDS, $RS['idMatricules']);
                 $this->redirect('gestio/gMatricules?accio=CA');
             }
             $this->MODE = 'EDICIO';
             break;
             //Cerquem alumnes
         //Cerquem alumnes
         case 'CA':
             if (empty($this->CERCA['text'])) {
                 $this->ALUMNES = MatriculesPeer::cercaAlumnes('....', $this->PAGINA, $this->IDS);
             } else {
                 $this->ALUMNES = MatriculesPeer::cercaAlumnes($this->CERCA['text'], $this->PAGINA, $this->IDS);
             }
             $this->SELECT = 2;
             $this->MODE = 'CONSULTA';
             break;
             //Cerquem per matrícula
         //Cerquem per matrícula
         case 'CM':
             $C = new Criteria();
             $C->add(MatriculesPeer::IDMATRICULES, $this->CERCA['text']);
             $this->MATRICULES = MatriculesPeer::doSelect($C);
             $this->MODE = 'LMATRICULES';
             break;
         case 'LMA':
             $this->MATRICULES = MatriculesPeer::getMatriculesUsuari($request->getParameter('IDA'), $this->IDS);
             $this->MODE = 'LMATRICULES';
             break;
             //Imprimeix la baixa d'una matrícula
         //Imprimeix la baixa d'una matrícula
         case 'PB':
             $IDM = $request->getParameter('IDM');
             $OM = MatriculesPeer::retrieveByPK($IDM);
             $OU = $OM->getUsuaris();
             $OC = $OM->getCursos();
             $doc = new sfTinyDoc();
             $url_prop = OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS) . 'documents/FullBaixa' . $this->IDS . '.docx';
             $url_gen = OptionsPeer::getString('SF_WEBSYSROOT', $this->IDS) . 'documents/FullBaixaGen.docx';
             if (file_exists($url_prop)) {
                 $doc->createFrom($url_prop);
             } else {
                 $doc->createFrom($url_gen);
             }
             $doc->loadXml('word/document.xml');
             $mat = 'MAT' . $OM->getIdmatricules();
             $doc->mergeXmlField('nom', $OU->getNomComplet());
             $doc->mergeXmlField('telèfon', $OU->getTelefonString());
             $doc->mergeXmlField('identificador', $OU->getDni());
             $doc->mergeXmlField('carrer', $OU->getAdreca());
             $doc->mergeXmlField('poble', $OU->getPoblacioString());
             $doc->mergeXmlField('postal', $OU->getCodipostal());
             $doc->mergeXmlField('concepte', $OC->getCodi() . ' - ' . $OC->getTitolcurs());
             $doc->mergeXmlField('data_baixa', $OM->getDataBaixa('d/m/Y'));
             $doc->saveXml();
             $doc->close();
             $doc->sendResponse();
             $doc->remove();
             throw new sfStopException();
             break;
         case 'PRINT_PAGAMENT':
             $idM = $request->getParameter('IDM');
             $OM = MatriculesPeer::retrieveByPK($idM);
             $HTML = MatriculesPeer::DocMatriculaPagamentCaixer($OM, $this->IDS);
             myUser::Html2PDF($HTML);
             throw new sfStopException();
             break;
         case 'C':
             $this->getUser()->addLogAction('inside', 'gMatricules');
             break;
     }
 }
Beispiel #4
0
 public function executeVoucher(sfWebRequest $request)
 {
     $this->form = new ReportVoucherForm();
     if ($request->getParameter('employee_id')) {
         $this->form->setDefault('employee_id', $request->getParameter('employee_id'));
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName()));
         if ($this->form->isValid()) {
             $date = $this->form->getValue('date');
             $as_of_date = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']);
             $c = new Criteria();
             // only chose client service types of the selected type
             $c->add(ClientServicePeer::OBJECT_TYPE, $this->form->getValue('client_service_type'));
             // make sure client and provider are not null
             $c->add(ClientServicePeer::CLIENT_ID, null, Criteria::ISNOTNULL);
             // if an employee is selected - only show vouchers for that provider
             if ($this->form->getValue('employee_id')) {
                 $c->add(ClientServicePeer::EMPLOYEE_ID, $this->form->getValue('employee_id'));
             } else {
                 $c->add(ClientServicePeer::EMPLOYEE_ID, null, Criteria::ISNOTNULL);
             }
             // check that the service was active at any point during the selected month of the selected year
             $c->add(ClientServicePeer::START_DATE, ClientServicePeer::START_DATE . ' <=\'' . $date['year'] . '-' . $date['month'] . '-31\'', Criteria::CUSTOM);
             // if they have an end date make sure it is in the selected month or later of the selected year
             $cton1 = $c->getNewCriterion(ClientServicePeer::END_DATE, ClientServicePeer::END_DATE . '>=\'' . $date['year'] . '-' . $date['month'] . '-1\'', Criteria::CUSTOM);
             $cton2 = $c->getNewCriterion(ClientServicePeer::END_DATE, null);
             $cton1->addOr($cton2);
             $c->add($cton1);
             // if they have a change date make sure it is in the selected month or later of the selected year
             $cton3 = $c->getNewCriterion(ClientServicePeer::CHANGE_DATE, ClientServicePeer::CHANGE_DATE . '>=\'' . $date['year'] . '-' . $date['month'] . '-1\'', Criteria::CUSTOM);
             $cton4 = $c->getNewCriterion(ClientServicePeer::CHANGE_DATE, null);
             $cton3->addOr($cton4);
             $c->add($cton3);
             // remove any services of irrelevant types
             $c->add(ClientServicePeer::SERVICE_ID, array_keys(sfConfig::get('app_voucher_ignore_services', 0)), Criteria::NOT_IN);
             // dont include waiting list kids
             $c->add(ClientServicePeer::WAITING_LIST, false);
             // sort by provider to group in list
             $c->addAscendingOrderByColumn(ClientServicePeer::EMPLOYEE_ID);
             // then sort by client to group them in provider list
             $c->addAscendingOrderByColumn(ClientServicePeer::CLIENT_ID);
             $this->services = ClientServicePeer::doSelectJoinAll($c);
             // create the document
             $doc = new sfTinyDoc();
             $doc->createFrom(array('basename' => $this->form->getValue('client_service_type') . 'Voucher'));
             $doc->loadXml('content.xml');
             $doc->mergeXmlField('cal_prev', $this->generateCalImage($date['day'], $date['month'] - 1, $date['year']));
             $doc->mergeXmlField('cal_next', $this->generateCalImage($date['day'], $date['month'], $date['year']));
             $doc->mergeXmlField('billing_period', date("M", $as_of_date) . ' 1 - ' . date("M", $as_of_date) . ' ' . date("t", $as_of_date));
             $doc->mergeXmlField('due_date', date("M", mktime(0, 0, 0, $date['month'] + 1, $date['day'], $date['year'])) . ' 3rd');
             $doc->mergeXmlBlock('service', $this->services);
             $doc->saveXml();
             $doc->close();
             // send and remove the document
             $doc->sendResponse();
             $doc->remove();
             throw new sfStopException();
         }
     }
 }
Beispiel #5
0
 public function executeBillingVoucher(sfWebRequest $request)
 {
     $client = ClientPeer::retrieveByPk($request->getParameter('id'));
     $this->forward404Unless($client);
     // create the document
     $doc = new sfTinyDoc();
     $doc->createFrom();
     $doc->loadXml('content.xml');
     $doc->mergeXmlField('client', $client);
     $doc->saveXml();
     $doc->close();
     // send and remove the document
     $doc->sendResponse();
     $doc->remove();
     throw new sfStopException();
 }
Beispiel #6
0
 /**
  * Matrícules
  *
  */
 public function executeGMatricules(sfWebRequest $request)
 {
     $this->setLayout('gestio');
     $this->IDS = $this->getUser()->getSessionPar('idS');
     //Netegem cerca
     if ($request->getParameter('accio') == 'C') {
         $this->CERCA = $this->getUser()->setSessionPar('cerca', array('text' => '', 'select' => 2));
         $this->PAGINA = $this->getUser()->setSessionPar('pagina', 1);
         $this->redirect('gestio/gMatricules?accio=CA');
     }
     $this->CERCA = $this->getUser()->ParReqSesForm($request, 'cerca', array('text' => "", 'select' => 2));
     $this->PAGINA = $this->getUser()->ParReqSesForm($request, 'PAGINA', 1);
     $accio = $this->getUser()->ParReqSesForm($request, 'accio', 'CA');
     //Inicialitzem el formulari de cerca
     $this->FCerca = new CercaTextChoiceForm();
     $this->FCerca->setChoice(array(1 => 'Cursos', 2 => 'Alumnes'));
     $this->FCerca->bind($this->CERCA);
     //Inicialitzem variables
     $this->MODE = array('CONSULTA' => false, 'NOU' => false, 'EDICIO' => false, 'LMATRICULES' => false, 'VERIFICA' => false);
     if ($request->isMethod('POST')) {
         if ($request->hasParameter('BCERCA')) {
             $accio = $this->CERCA['select'] == 2 ? 'CA' : 'CC';
             $this->PAGINA = 1;
         } elseif ($request->hasParameter('BNOU')) {
             $accio = 'NU';
         } elseif ($request->hasParameter('BSAVENEWUSER')) {
             $accio = 'SAVE_NEW_USER';
         } elseif ($request->hasParameter('BSELCURS')) {
             $accio = 'SNU';
         } elseif ($request->hasParameter('BSAVECURS')) {
             $accio = 'SAVE_CURS';
         } elseif ($request->hasParameter('BPAGAMENT')) {
             $accio = 'PAGAMENT';
         } elseif ($request->hasParameter('BSUBMIT')) {
             $accio = 'S';
         } elseif ($request->hasParameter('BDELETE')) {
             $accio = 'D';
         } elseif ($request->hasParameter('BSAVE')) {
             $accio = 'SAVE_MATRICULA';
         }
     }
     //Aquest petit bloc és per si es modifica amb un POST el que s'ha enviat per GET
     $this->getUser()->setSessionPar('accio', $accio);
     $this->getUser()->setSessionPar('PAGINA', $this->PAGINA);
     //Guardem la pàgina per si hem fet una consulta nova
     switch ($accio) {
         //Crea un usuari nou per poder seguir fent la matrícula
         case 'ADD_USER':
             $this->FUsuari = UsuarisPeer::initialize(0, $this->IDS, true, false);
             $this->MODE = 'MAT_NOU_USUARI';
             break;
             //Guarda el nou usuari
         //Guarda el nou usuari
         case 'SAVE_NEW_USER':
             $RU = $request->getParameter('usuaris');
             $this->FUsuari = UsuarisPeer::initialize(0, $this->IDS, true, false);
             $this->FUsuari->bind($RU);
             if ($this->FUsuari->isValid()) {
                 $this->FUsuari->save();
                 $this->getUser()->addLogAction($accio, 'gMatricules', $this->FUsuari->getObject());
                 $this->redirect('gestio/gMatricules?accio=NU');
             }
             $this->MODE = 'MAT_NOU_USUARI';
             break;
             // Nova matrícula
         // Nova matrícula
         case 'NU':
             $this->IDM = $request->getParameter('IDM', null);
             $this->FMatricula = MatriculesPeer::initialize($this->IDM, $this->IDS, true);
             $this->MODE = 'MAT_USUARI';
             break;
         case 'AJAX_USUARIS':
             $RET = UsuarisPeer::cercaTotsCampsSelect($request->getParameter('q'), $request->getParameter('lim'), $this->IDS);
             return $this->renderText(json_encode($RET));
             break;
             //Comprovem les dades que hem entrat de l'usuari
         //Comprovem les dades que hem entrat de l'usuari
         case 'SNU':
             $RM = $request->getParameter('matricules_usuari');
             $this->FMatricula = MatriculesPeer::initialize(0, $this->IDS, true);
             $this->FMatricula->bind($RM);
             if ($this->FMatricula->isValid()) {
                 $this->FMatricula->save();
                 $this->getUser()->addLogAction($accio, 'gMatricules', $this->FMatricula->getObject());
                 //Si tot OK, iniciem l'elecció del curs
                 $this->IDM = $this->FMatricula->getObject()->getIdmatricules();
                 $this->CURSOS = MatriculesPeer::getCursosMatriculacio($this->IDS);
                 $this->MODE = 'NOU';
             } else {
                 $this->MODE = 'MAT_USUARI';
             }
             break;
             //Guardem la matrícula al curs que hem escollit
         //Guardem la matrícula al curs que hem escollit
         case 'SAVE_CURS':
             $this->IDM = $request->getParameter('IDM');
             //L'hem enviat ocult
             $this->IDC = $request->getParameter('IDC');
             $this->FMatricula = MatriculesPeer::initialize($this->IDM, $this->IDS, false);
             $OMatricula = $this->FMatricula->getObject();
             $OMatricula->setCursosIdcursos($this->IDC);
             $OMatricula->setDatainscripcio(date('Y-m-d H:i', time()));
             $Preu = CursosPeer::CalculaPreu($OMatricula->getCursosIdcursos(), $OMatricula->getTreduccio(), $this->IDS);
             $OMatricula->setEstat(MatriculesPeer::EN_PROCES);
             $OMatricula->setPagat($Preu);
             $OMatricula->save();
             $this->getUser()->addLogAction($accio, 'gMatricules', $OMatricula);
             $this->redirect('gestio/gMatricules?accio=FP&IDM=' . $this->IDM);
             break;
             //Mostra la prematrícula i carreguem les dades del pagament
         //Mostra la prematrícula i carreguem les dades del pagament
         case 'FP':
             $this->FMatricula = MatriculesPeer::initialize($request->getParameter('IDM'), $this->IDS);
             $this->MATRICULA = $this->FMatricula->getObject();
             $this->IDM = $this->MATRICULA->getIdmatricules();
             $PREU = CursosPeer::CalculaTotalPreus(array($this->MATRICULA->getCursosIdcursos()), $this->MATRICULA->getTreduccio(), $this->IDS);
             $NOM = UsuarisPeer::retrieveByPK($this->MATRICULA->getUsuarisUsuariid())->getNomComplet();
             $this->CURS_PLE = CursosPeer::isPle($this->MATRICULA->getCursosIdcursos(), $this->IDS);
             //Passem si el curs es ple
             $MATRICULA = $this->MATRICULA->getIdmatricules();
             $this->TPV = MatriculesPeer::getTPV($PREU, $NOM, $MATRICULA, $this->IDS, false);
             $this->MODE = 'VALIDACIO_CURS';
             break;
             //Entenem que hem fet un pagament a caixa i mostrem missatge de finalització.
         //Entenem que hem fet un pagament a caixa i mostrem missatge de finalització.
         case 'PAGAMENT':
             $this->IDM = $request->getParameter('IDM');
             $this->OM = MatriculesPeer::retrieveByPK($this->IDM);
             if (MatriculesPeer::setMatriculaPagada($this->OM)) {
                 if ($this->OM instanceof Matricules && $this->IDM > 0) {
                     $this->MISSATGE = "OK";
                 } else {
                     $this->MISSATGE = "KO";
                 }
                 $this->getUser()->addLogAction($accio, 'gMatricules', $this->MATRICULA);
                 $this->MODE = 'PAGAMENT';
                 $this->SendMailMatricula($this->OM, $this->IDS);
             }
             break;
             //Si hem fet un pagament amb targeta, anem a la següent pantalla.
         //Si hem fet un pagament amb targeta, anem a la següent pantalla.
         case 'OK':
             $this->IDM = $request->getParameter('Ds_MerchantData', 0);
             if ($request->hasParameter('OK') && $this->IDM > 0) {
                 $this->MISSATGE = "OK";
             } else {
                 $this->MISSATGE = "KO";
             }
             $this->MODE = 'PAGAMENT';
             break;
             //Esborra una matrícula
         //Esborra una matrícula
         case 'D':
             $RM = $request->getParameter('matricules');
             $OM = MatriculesPeer::retrieveByPK($RM['idMatricules']);
             $OM->setActiu(false);
             $OM->save();
             $this->getUser()->addLogAction($accio, 'gMatricules', $OM);
             break;
             //Edita una matrícula
         //Edita una matrícula
         case 'E':
             $this->IDM = $request->getParameter('IDM');
             $this->FMATRICULA = MatriculesPeer::initialize($this->IDM, $this->IDS);
             $this->MODE = 'EDICIO';
             break;
             //Guardem una matrícula modificada
         //Guardem una matrícula modificada
         case 'SAVE_MATRICULA':
             $RS = $request->getParameter('matricules');
             $this->FMATRICULA = MatriculesPeer::initialize($RS['idMatricules'], $this->IDS);
             $this->FMATRICULA->bind($RS);
             if ($this->FMATRICULA->isValid()) {
                 $this->FMATRICULA->save();
                 $this->getUser()->addLogAction($accio, 'gMatricules', $this->FMATRICULA->getObject());
                 $this->redirect('gestio/gMatricules?accio=CA');
             }
             $this->MODE = 'EDICIO';
             break;
         case 'CA':
             $this->ALUMNES = MatriculesPeer::cercaAlumnes($this->CERCA['text'], $this->PAGINA, $this->IDS);
             $this->SELECT = 2;
             $this->MODE = 'CONSULTA';
             break;
         case 'CC':
             $this->CURSOS = MatriculesPeer::cercaCursos($this->CERCA['text'], $this->PAGINA, $this->IDS);
             $this->SELECT = 1;
             $this->MODE = 'CONSULTA';
             break;
         case 'LMA':
             $this->MATRICULES = MatriculesPeer::getMatriculesUsuari($request->getParameter('IDA'), $this->IDS);
             $this->MODE = 'LMATRICULES';
             break;
         case 'LMC':
             $this->MATRICULES = MatriculesPeer::getMatriculesCurs($request->getParameter('IDC'), $this->IDS);
             $this->MODE = 'LMATRICULES';
             break;
         case 'P':
             $IDP = $request->getParameter('IDP');
             $OM = MatriculesPeer::retrieveByPK($IDP);
             $OU = $OM->getUsuaris();
             $OC = $OM->getCursos();
             $doc = new sfTinyDoc();
             if ($OM->getSiteid() > 1) {
                 $doc->createFrom(OptionsPeer::getString('SF_WEBSYSROOT') . 'web/images/matricules/gMatriculesGenSuccess.docx');
             } else {
                 $doc->createFrom(array('extension' => 'docx'));
             }
             $doc->loadXml('word/document.xml');
             $mat = 'MAT' . $OM->getIdmatricules();
             $doc->mergeXmlField('factura', $mat);
             $doc->mergeXmlField('client', $OU->getDni());
             $doc->mergeXmlField('data', $OM->getDatainscripcio('d/m/Y'));
             $doc->mergeXmlField('nom', $OU->getNomComplet());
             $doc->mergeXmlField('telèfon', $OU->getTelefonString());
             $doc->mergeXmlField('identificador', $OU->getDni());
             $doc->mergeXmlField('carrer', $OU->getAdreca());
             $doc->mergeXmlField('poble', $OU->getPoblacioString());
             $doc->mergeXmlField('postal', $OU->getCodipostal());
             $doc->mergeXmlField('concepte', $OC->getCodi() . ' - ' . $OC->getTitolcurs());
             $doc->mergeXmlField('preu', $OM->getPagat());
             $doc->mergeXmlField('quantitat', '1');
             $doc->mergeXmlField('import', $OM->getPagat());
             $doc->mergeXmlField('base', $OM->getPagat());
             $doc->mergeXmlField('iva', '0%');
             $doc->mergeXmlField('total', $OM->getPagat());
             $doc->mergeXmlField('dia', $OC->getDatainici('d/m/Y'));
             $doc->mergeXmlField('horari', $OC->getHoraris());
             $doc->saveXml();
             $doc->close();
             $doc->sendResponse();
             $doc->remove();
             throw new sfStopException();
             break;
         case 'C':
             $this->getUser()->addLogAction('inside', 'gMatricules');
             break;
     }
 }