public function executeGConfig(sfWebRequest $request) { $this->setLayout('gestio'); $this->IDS = $this->getUser()->getSessionPar('idS'); $this->accio = $request->getParameter('accio', 'C'); $ROPTIONS = $request->getParameter('options', array('option_id' => '0')); $RESPAIS = $request->getParameter('espais', array('EspaiID' => '0')); $RMATERIAL = $request->getParameter('materialgeneric', array('idMaterialGeneric' => '')); $RDESCOMPTE = $request->getParameter('descomptes', array('idDescompte' => '0')); $this->FOPTIONS = OptionsPeer::initialize($ROPTIONS['option_id'], $this->IDS, false); $this->FESPAIS = EspaisPeer::initialize($RESPAIS['EspaiID'], $this->IDS); $this->FMATERIAL = MaterialgenericPeer::initialize($RMATERIAL['idMaterialGeneric'], $this->IDS); $this->FENTITAT = SitesPeer::initialize($this->IDS); //$this->FDESCOMPTE = DescomptesPeer::initialize( $RDESCOMPTE['idDescompte'] , $this->IDS ); //Agafem el codi de facebook de l'usuari $this->FBI = UsuarisPeer::getUserFbCode($this->getUser()->getSessionPar('idU')); $this->PARS = array(); $this->PARS = myUser::f_FbAuth(false, $this->getController()->genUrl('@fb_link', true)); //Carreguem les dades del facebook. $this->ERROR = ""; if ($request->hasParameter('BNEWOPTION')) { $this->accio = 'NEW_OPTION'; } if ($request->hasParameter('BSAVEOPTION')) { $this->accio = 'SAVE_OPTION'; } if ($request->hasParameter('BSAVEESPAI')) { $this->accio = 'SAVE_ESPAI'; } if ($request->hasParameter('BDELETEESPAI')) { $this->accio = 'DELETE_ESPAI'; } if ($request->hasParameter('BSAVEMATERIAL')) { $this->accio = 'SAVE_MATERIAL'; } if ($request->hasParameter('BDELETEMATERIAL')) { $this->accio = 'DELETE_MATERIAL'; } if ($request->hasParameter('BSAVESITE')) { $this->accio = 'SAVE_SITE'; } if ($request->hasParameter('BSAVEDESCOMPTE')) { $this->accio = 'SAVE_DESCOMPTE'; } switch ($this->accio) { case 'AJAX_OPCIO': return $this->renderText(OptionsPeer::getString($request->getParameter('IDO'), $this->IDS)); break; case 'NEW_OPTION': $this->FOPTIONS = OptionsPeer::initialize($ROPTIONS['option_id'], $this->IDS, true); break; case 'SAVE_OPTION': $this->FOPTIONS->bind($ROPTIONS); if ($this->FOPTIONS->isValid()) { $this->FOPTIONS->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FOPTIONS->getObject()); $this->FOPTIONS = OptionsPeer::initialize($this->FOPTIONS->getObject()->getOptionId(), $this->IDS, false); } break; case 'SAVE_ESPAI': //Si entrem un espai que és 0, llavors vol dir que fem un nou espai if ($RESPAIS['EspaiID'] == 0) { unset($RESPAIS['EspaiID']); } $this->FESPAIS->bind($RESPAIS, $request->getFiles('espais')); if ($this->FESPAIS->isValid()) { $this->FESPAIS->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FESPAIS->getObject()); $this->FESPAIS = EspaisPeer::initialize($this->FESPAIS->getObject()->getEspaiid(), $this->IDS); } //Agafem els multimèdia dels paràmetres $AMR = $request->getParameter('multimedia'); $FMR = $request->getFiles('multimedia'); foreach ($AMR as $K => $MR) { if ($MR['accio'] == 1 || $MR['accio'] == 0) { //És nou o una modificació $FM = MultimediaPeer::initialize($MR['multimedia_id'], $MR['site_id'], $MR['taula'], $MR['id_extern'], $K); $FM->bind($MR, $FMR[$K]); $FM->saveNewUpdate(); } elseif ($MR['accio'] == 2) { //S'ha d'esborrar $FM = MultimediaPeer::initialize($MR['multimedia_id'], $MR['site_id'], $MR['taula'], $MR['id_extern'], $K); $FM->delete(); } } break; case 'DELETE_ESPAI': $this->FESPAIS->getObject()->setActiu(false)->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FESPAIS->getObject()); $this->FESPAIS = EspaisPeer::initialize(0, $this->IDS); break; case 'SAVE_MATERIAL': //Si entrem un espai que és 0, llavors vol dir que fem un nou espai if ($RMATERIAL['idMaterialGeneric'] == 0) { unset($RMATERIAL['idMaterialGeneric']); } $this->FMATERIAL->bind($RMATERIAL); if ($this->FMATERIAL->isValid()) { $this->FMATERIAL->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FMATERIAL->getObject()); $this->FMATERIAL = MaterialgenericPeer::initialize($this->FMATERIAL->getObject()->getIdmaterialgeneric(), $this->IDS); } break; case 'DELETE_MATERIAL': $this->FMATERIAL->getObject()->setInactiu(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FMATERIAL->getObject()); $this->FMATERIAL = MaterialgenericPeer::initialize(0, $this->IDS); break; //Vincula l'usuari del facebook //Vincula l'usuari del facebook case 'FB_LINK': $idU = $this->getUser()->getSessionPar('idU'); $OU = UsuarisPeer::retrieveByPK($idU); $FB_ID = $this->PARS['user']['id']; //Mirem si el número de facebook està associat a un altre usuari. Si és així, no fem res però emetem error. $OUF = UsuarisPeer::getUserFromFacebook($FB_ID); if ($OUF instanceof Usuaris) { $this->ERROR = 'El compte de facebook actual està vinculat a un altre usuari. <br />Si us plau comuniqui-ho a informatica@casadecultura.org o bé entri al seu usuari de facebook i torni-ho a provar.'; } elseif ($OU instanceof Usuaris) { $OU->setFacebookid($this->PARS['user']['id']); $OU->save(); } $this->FBI = UsuarisPeer::getUserFbCode($this->getUser()->getSessionPar('idU')); break; //Desvincula l'usuari del facebook //Desvincula l'usuari del facebook case 'FB_UNLINK': $idU = $this->getUser()->getSessionPar('idU'); $OU = UsuarisPeer::retrieveByPK($idU); $OU->setFacebookid(NULL); $OU->save(); $this->FBI = UsuarisPeer::getUserFbCode($this->getUser()->getSessionPar('idU')); break; //Guardem els canvis a una entitat //Guardem els canvis a una entitat case 'SAVE_SITE': $RS = $request->getParameter('sites'); $this->FENTITAT->bind($RS, $request->getFiles('sites')); if ($this->FENTITAT->isValid()) { $this->FENTITAT->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FENTITAT->getObject()); $this->FENTITAT = SitesPeer::initialize($this->IDS); } break; case 'SAVE_DESCOMPTE': //Si entrem un descompte que és 0, vol dir que creem un nou descompte $this->FDESCOMPTE->bind($RDESCOMPTE); if ($this->FDESCOMPTE->isValid()) { $this->FDESCOMPTE->save(); $this->getUser()->addLogAction($this->accio, 'gConfig', $this->FDESCOMPTE->getObject()); $this->FDESCOMPTE = DescomptesPeer::initialize($this->FDESCOMPTE->getObject()->getIddescompte(), $this->IDS); } break; } }