public function getAction($name)
 {
     if (!empty($name)) {
         foreach ($this->getConfiguration()->actions->action as $action) {
             if ($action["name"] == $name) {
                 $map = new ActionMapping();
                 try {
                     $map->setInput($action["input"]);
                     $map->setClass($action["class"]);
                     $map->setName($action["name"]);
                     $map->setFormName($action["form"]);
                     if ($this->getForward($action["forward"])) {
                         $map->setForward($this->getForward($action["forward"]));
                     }
                     $map->setPath($action["path"]);
                     $map->setValidate((bool) $action["validate"]);
                     $map->setRoles($action["roles"]);
                     $map->setParameter($action["parameter"]);
                     $forwards = array();
                     foreach ($action->forward as $key => $forward) {
                         $forwards[] = new ActionForward($forward["name"], $forward["path"]);
                     }
                     $map->setForwards($forwards);
                     return $map;
                 } catch (Exception $e) {
                     throw new ConfigurationException("Action: {$action['name']}");
                 }
             }
         }
         throw new ActionNotFoundException("Action: {$name}");
     } else {
         throw new EmptyStringException();
     }
 }
 public function execute($action)
 {
     if (isset($_SESSION["idRoom"])) {
         // Setting the room state to off
         $this->dao->updateRoomState($_SESSION["idRoom"], false, 0);
     }
     unset($_SESSION['id']);
     unset($_SESSION['name']);
     unset($_SESSION['user']);
     session_destroy();
     $action = new ActionMapping();
     $action->setName("loginForm");
     $action->setType("ForwardAction");
     $action->setRole("");
     $action->setForwards(array("success" => ".showLoginForm", "error" => ".error"));
     $forwardAction = new ForwardAction();
     $forwardAction->execute($action);
 }
 public function execute($action)
 {
     //error_reporting(E_ALL);
     //ini_set("display_errors", 1);
     $forwards = $action->getForwards();
     $strJson = str_replace('\\', '', $_POST['json']);
     $json = json_decode(utf8_encode($strJson));
     $data = $json->{'logindata'};
     $sucess = false;
     $createdUser = false;
     if (!is_null($data->{'email'})) {
         $user = $this->dao->getUserByEmail($data->{'email'});
         if (!$user) {
             //  Store a new user
             $user = new User();
             $user->setName($data->{'name'});
             $user->setEmail($data->{'email'});
             $user->setPassword($data->{'passoword'});
             if ($data->{'roomCreator'} == 'F0') {
                 $user->setRoomcreator(true);
             } else {
                 $user->setRoomcreator(false);
             }
             // Saving a new user
             $this->dao->saveNewUser($user);
             $createdUser = true;
         }
         //else{
         //TODO verificar a senha
         //}
         // Store data in PHP SESSION
         if ($user) {
             $sucess = true;
             $_SESSION['id'] = $user->getUserId();
             $_SESSION['name'] = $user->getName();
             $_SESSION['roomCreator'] = $user->getRoomcreator();
             $_SESSION['email'] = $user->getEmail();
             $_SESSION['user'] = $user;
         } else {
             //TODO ajustar quando o login nao funciona
             $sucess = false;
             $_REQUEST["errorMsg"] = $this->message->getText("error.loginFail");
             $this->pageController->run($forwards['error']);
         }
     } else {
         //TODO ajustar quando o login nao funciona
         $sucess = false;
         $_REQUEST["errorMsg"] = $this->message->getText("error.loginFail");
         $this->pageController->run($forwards['error']);
     }
     if ($createdUser == true) {
         // Verifica se o usuario foi criado, se sim, manda para uma pagina de sucesso
         $action = new ActionMapping();
         $action->setName("createdUserSuccess");
         $action->setType("ForwardAction");
         $action->setRole("");
         $action->setForwards(array("success" => ".createdUserSuccess"));
         $forwardAction = new ForwardAction();
         $forwardAction->execute($action);
     } else {
         if ($sucess) {
             $_REQUEST["msg"] = "Sua conta foi criada com sucesso no Quadro Branco, por favor, volte e entre novamente";
             $action = new ActionMapping();
             $action->setName("listRoons");
             $action->setType("ListRoonsAction");
             $action->setRole("");
             $action->setForwards(array("success" => ".showUserPage", "error" => ".error"));
             $listRoonsAction = new ListRoonsAction();
             $listRoonsAction->execute($action);
         }
     }
 }
 /**
  * Metodo responsavel por criar o array de objetos ActionMapping
  * @return : void
  */
 private function createActionsMappings()
 {
     $actionsList = $this->_document->getElementsByTagName('action');
     foreach ($actionsList as $action) {
         $actionMapping = new ActionMapping();
         if ($action->hasAttribute("ssl")) {
             if ($action->getAttribute("ssl") == "false") {
                 $actionMapping->setSSL(0);
             } else {
                 $actionMapping->setSSL(1);
             }
         }
         if ($action->hasAttribute("authentication")) {
             if ($action->getAttribute("authentication") == "false") {
                 $actionMapping->setAuthentication(0);
             } else {
                 $actionMapping->setAuthentication(1);
             }
         }
         if ($action->hasChildNodes()) {
             $actionChildNode = $action->childNodes;
             foreach ($actionChildNode as $actionChild) {
                 if ($actionChild->nodeName == "name") {
                     $actionMapping->setName($actionChild->nodeValue);
                 }
                 if ($actionChild->nodeName == "type") {
                     $actionMapping->setType($actionChild->nodeValue);
                 }
                 if ($actionChild->nodeName == "role") {
                     $actionMapping->setRole($actionChild->nodeValue);
                 }
                 if ($actionChild->nodeName == "forwards") {
                     $actionMapping->setForwards($this->createForwards($actionChild));
                 }
                 if ($actionChild->nodeName == "validation") {
                     $actionMapping->setValidations($this->createValidation($actionChild));
                 }
             }
             $this->_actionsMapping[] = $actionMapping;
         }
     }
 }