Beispiel #1
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;
     }
 }