/css/aem.css" type="text/css" media="all" />
	
</head>
<body>
	<?php 
require "header.php";
require "modal.php";
require "menu.php";
if ($handleErrors = \library\handleErrors::getErrors()) {
    foreach ($handleErrors as $error) {
        if ($error->getType() == $error::TYPE_ERR && $error->getDiv() == 'err_global') {
            echo msgError($error->getMsg());
        }
    }
}
if ($handleErrors = \library\handleErrors::getErrors()) {
    foreach ($handleErrors as $error) {
        if ($error->getType() == $error::TYPE_SUC && $error->getDiv() == 'err_global') {
            echo msgSuccess($error->getMsg());
        }
    }
}
?>

	<div class="container">        
		<?php 
require "breadcrumb.php";
?>
		<?php 
if (isset($msgError)) {
    echo msgError($msgError);
    /**
     * create a simple form.
     * @return string formulary formatted in HTML
     */
    public function createView()
    {
        $view = "\n\t\t\t<form action='#' method='post' name='" . uniqid('form') . "'  enctype='multipart/form-data' role='form' class='" . $this->class . "'>\n\t\t\t<table class='table'>";
        // for all fields of the form...
        foreach ($this->fields as $field) {
            // ... check if the field is an hidden component or a separator component
            if (get_class($field) == "library\\webComponents\\hidden" || get_class($field) == "library\\webComponents\\separator") {
                $view .= "<tr><td colspan='2'  style='border:0px;'>" . $field->build() . "</td></tr>";
            } else {
                $view .= "\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td style='min-width:100px;'>" . $field->getTitle() . "</td>\n\t\t\t\t\t\t\t<td>" . $field->build() . "</td>\n\t\t\t\t\t\t</tr>";
                $errors = \library\handleErrors::getErrorsByDiv("field_error_msg_" . $field->getName());
                if (!empty($errors)) {
                    foreach ($errors as $error) {
                        $view .= "<tr>\n\t\t\t\t\t\t\t\t\t<td style='border : 0px;'></td><td style='border : 0px;'><div class='fg-red field_error_msg_" . $field->getName() . "'>" . $error->getMsg() . "</div>\n\t\t\t\t\t\t\t\t</tr>";
                    }
                }
            }
        }
        $view .= '
				<tr>
					<td colspan="2">
						<button class="btn btn-primary" type="submit" id="submit"><span class="glyphicon glyphicon-ok"></span> Valider</button>
						<input type="hidden" name="form_entity" value="' . get_class($this->getEntity()) . '"/>
					</td>
				</tr>
				</table>
				</form>';
        return $view;
    }
 /**
  * active a user
  * @param string $email
  */
 public function active($email, $code)
 {
     if ($this->checkEmailExists($email)) {
         $users = $this->currentManager->getByEmail($email);
         if ($users[0]->level == $code) {
             $users[0]->level = 1;
             $users[0]->active = 1;
             $this->currentEntity->hydrate($users[0]);
             if ($this->currentManager->save($this->currentEntity)) {
                 $this->page->addVar('content', _TR_ValidationSuccess);
                 $_SESSION['users'] = $users[0];
             }
         } else {
             \library\handleErrors::setErrors($this->errorElement);
         }
     } else {
         \library\handleErrors::setErrors($this->errorExistingElement);
     }
 }
 /**
  * is valid method.
  * @return bool false=invalid, true=valid
  */
 public function isValid()
 {
     $res = true;
     foreach ($this->validators as $validator) {
         if (!$validator->isValid($this->value)) {
             $error = new \library\error(array('type' => \library\error::TYPE_ERR, 'msg' => $validator->getErrorMsg(), 'div' => 'field_error_msg_' . $this->getName()));
             \library\handleErrors::setErrors($error);
             $res = false;
         }
     }
     return $res;
 }