private function beforeActionExecute() { $userId = (string) HttpContext::getInstance()->getSession()->userId; if ($userId !== "") { Helpers::redirect(''); } }
/** * @Route ["/conference/new", "post"] * @Authorize */ public function postNewConference(NewConferenceBindingModel $model) : View { try { if (!$model->isValid()) { $viewModel = new \Framework\ViewModels\Conference\NewConferenceViewModel(); $viewModel->errorsList = $model->getErrorsList(); $viewModel->error = true; foreach ($this->db->findAll("Venue") as $venue) { $viewModel->venues[] = array('id' => $venue->id, 'name' => $venue->name); } return new View('\\Conference\\getNewConference', $viewModel); } $userId = $this->httpContext->identity()->id; $conf = $this->db->Create("Conference", array("name" => $model->name, "start" => date("Y-m-d H:i:s", strtotime($model->from)), "end" => date("Y-m-d H:i:s", strtotime($model->to)), "venue_id" => $model->venue_id, "user_id" => $userId)); $conf->save(); $this->redirect(\Framework\Helpers\Helpers::url() . "conference/{$conf->id}/manage"); } catch (\Exception $e) { $viewModel = new \Framework\ViewModels\Conference\NewConferenceViewModel(); $viewModel->errorsList = $userModel->getErrorsList(); $viewModel->errorsList[] = $e->getMessage(); $viewModel->error = true; foreach ($this->db->findAll("Venue") as $venue) { $viewModel->venues[] = array('id' => $venue->id, 'name' => $venue->name); } return new View('\\Conference\\getNewConference', $viewModel); } }
public function ListConferences() { $body = ""; foreach ($this->conferences as $conference) { $id = $conference['id']; $conferenceName = $conference['name']; $link = \Framework\Helpers\Helpers::url() . "conference/" . $id . "/manage"; $body = $body . "<div class='col-xs-12'><a href='{$link}'>{$conferenceName}</a></div>"; } echo $body; }
private function initController() { $controllerName = $this->controllerName; if (!Helpers::startsWith($controllerName, AppConfig::CONTROLLERS_NAMESPACE)) { $controllerName = AppConfig::CONTROLLERS_NAMESPACE . ucfirst($this->controllerName) . AppConfig::CONTROLLERS_SUFFIX; } class_exists($controllerName, false); $annotationsParser = new AnnotationsParser($controllerName, $this->actionName); $annotationsParser->checkAnnotations(); $this->controller = new $controllerName(HttpContext::getInstance()); }
public function ListLectures() { $body = ""; foreach ($this->lectures as $lecture) { $id = $lecture['id']; $lectureName = $lecture['name']; $link = \Framework\Helpers\Helpers::url() . "conference/" . $this->id . "/lecture/" . $id . "/edit"; $body = $body . "<div class='col-xs-12'><a href='{$link}'>{$lectureName}</a></div>"; } echo $body; }
private function beforeActionExecute() { $userId = (string) HttpContext::getInstance()->getSession()->userId; if ($userId == "") { Helpers::redirect("users/login"); } $userRole = UserManager::getInstance()->getUserRole(intval($userId)); if (!in_array($userRole->getName(), $this->roles)) { throw new ApplicationException("Not enough permissions to see this page!"); } }
public static function init() { spl_autoload_register(function ($class) { $pathParams = explode('\\', $class); $path = implode(DIRECTORY_SEPARATOR, $pathParams); $path = str_replace($pathParams[0], "", $path); if (!file_exists(substr($path . '.php', 1))) { Helpers::redirect("error"); } require_once $path . '.php'; }); }
public function ListVenues() { $body = ""; foreach ($this->venues as $venue) { $id = $venue['id']; $venueName = $venue['name']; $link = \Framework\Helpers\Helpers::url() . 'admin/venues/' . $id; $body = $body . "<tr class='gradeA' onclick='document.location=\"" . $link . "\"'>"; $body = $body . "<td>" . $id . "</td><td>" . $venueName . "</td>"; $body = $body . "</tr>"; } echo $body; }
public function ListHalls() { $body = ""; foreach ($this->halls as $hall) { $id = $hall['id']; $hallName = $hall['name']; $hallBelongsTo = $hall['belongsTo']; $link = \Framework\Helpers\Helpers::url() . 'admin/halls/' . $id; $body = $body . "<tr class='gradeA' onclick='document.location=\"" . $link . "\"'>"; $body = $body . "<td>" . $id . "</td><td>" . $hallName . "</td><td>" . $hallBelongsTo . "</td>"; $body = $body . "</tr>"; } echo $body; }
public function ListUsers() { $body = ""; foreach ($this->users as $user) { $id = $user['id']; $userName = $user['username']; $link = \Framework\Helpers\Helpers::url() . 'admin/users/' . $id; $body = $body . "<tr class='gradeA'>"; $body = $body . "<td>" . $id . "</td><td>" . $userName . "</td>"; $body = $body . "<td><a class='btn btn-primary' href='" . $link . "/edit'><i class='fa fa-gear'></i></a></td>" . "<td><a class='btn btn-primary' href='" . $link . "/change-role'><i class='fa fa-users'></i></a></td>" . "<td><a class='btn btn-danger delete'href='" . $link . "/delete'><i class='fa fa-times'></i></a></td>"; $body = $body . "</tr>"; } echo $body; }
/** * @Route ["/conference/{conferenceId}/lecture/new", "post"] * @Authorize */ public function postAddLectureToConference(int $conferenceId, NewLectureBindingModel $model) : View { try { $conference = $this->db->FindFirst("Conference", "id='{$conferenceId}'"); if ($conference == false || $conference->user_id != $this->httpContext->identity()->id) { throw new \Exception("", 404); } if (!$model->isValid()) { $viewModel = new \Framework\ViewModels\Conference\ManageConferenceViewModel(); $viewModel->errorsList = $model->getErrorsList(); $viewModel->error = true; $viewModel->conferenceName = $conference->name; $viewModel->start = date('d/m/Y', strtotime($conference->start)); $viewModel->end = date('d/m/Y', strtotime($conference->end)); $viewModel->venueId = $conference->venue_id; foreach ($this->db->findAll("Venue") as $venue) { $viewModel->venues[] = array('id' => $venue->id, 'name' => $venue->name); } foreach ($this->db->findAll("Lecture", "conference_id = '{$conferenceId}'") as $lecture) { $viewModel->lectures[] = array('id' => $lecture->id, 'name' => $lecture->name); } if (count($model->lectures) > 0) { $viewModel->hasLectures = true; } return new View('\\Conference\\manageConference', $viewModel); } $lecture = $this->db->Create("Lecture", array("name" => $model->name, "start" => date("Y-m-d H:i:s", strtotime($model->from)), "end" => date("Y-m-d H:i:s", strtotime($model->to)), "user_id" => $model->user_id, "conference_id" => $conferenceId)); $lecture->save(); $this->redirect(\Framework\Helpers\Helpers::url() . "conference/{$conferenceId}/manage"); } catch (\Exception $e) { $viewModel = new \Framework\ViewModels\Conference\ManageConferenceViewModel(); $viewModel->errorsList = $userModel->getErrorsList(); $viewModel->errorsList[] = $e->getMessage(); $viewModel->error = true; foreach ($this->db->findAll("Venue") as $venue) { $viewModel->venues[] = array('id' => $venue->id, 'name' => $venue->name); } foreach ($this->db->findAll("Lecture", "conference_id = '{$conferenceId}'") as $lecture) { $model->lectures[] = array('id' => $lecture->id, 'name' => $lecture->name); } if (count($model->lectures) > 0) { $model->hasLectures = true; } return new View('\\Conference\\manageConference', $viewModel); } }
</td> <td> <?php if ($hall["isActive"]) { ?> <a href="<?php echo \Framework\Helpers\Helpers::url() . "admin/halls/" . htmlspecialchars($hall["id"]) . "/edit"; ?> ">Edit</a> | <a href="<?php echo \Framework\Helpers\Helpers::url() . "admin/halls/" . htmlspecialchars($hall["id"]) . "/deactivate"; ?> ">Deactivate</a> <?php } else { ?> <a href="<?php echo \Framework\Helpers\Helpers::url() . "admin/halls/" . htmlspecialchars($hall["id"]) . "/activate"; ?> ">Activate</a> <?php } ?> </td> </tr> <?php } ?> </tbody> </table>
</li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'conference/my'; ?> ">My conferences</a> </li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'conference/all'; ?> ">Open conferences</a> </li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'conference/signed-up'; ?> ">Signed up for</a> </li> </ul> </nav> <?php } ?> </header> <div id="page-content-wrapper"> <?php if (\Framework\Core\Identity::isUserLogged()) { ?> <button type="button" class="hamburger is-closed" data-toggle="offcanvas">
echo \Framework\Helpers\Helpers::url() . 'admin'; ?> "><i class="fa fa-dashboard"></i> Dashboard</a> </li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'admin/venues'; ?> "><i class="fa fa-table"></i> Manage venues</a> </li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'admin/halls'; ?> "><i class="fa fa-table"></i> Manage halls</a> </li> <li> <a href="<?php echo \Framework\Helpers\Helpers::url() . 'admin/users'; ?> "><i class="fa fa-user"></i> Manage users</a> </li> </ul> </div> </nav> <!-- /. NAV SIDE --> <div id="page-wrapper"> <div id="page-inner"> <!-- /. ROW -->
private static function viewAdjustment() { if (Helpers::endsWith(self::$actionName, "Pst") || Helpers::endsWith(self::$actionName, "Put") || Helpers::endsWith(self::$actionName, "Del")) { self::$actionName = substr(self::$actionName, 0, strlen(self::$actionName) - 3); } }
" class="hvr-underline-reveal"><span class="glyphicon glyphicon-user"></span></a></li> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'users/password'; ?> "><span class="glyphicon glyphicon-lock"></span></a></li> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'users/logout'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-out"></span></a></li> <?php } else { ?> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'users/login'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-in"></span></a></li> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'users/register'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-registration-mark"></span></a></li> <?php } ?> </ul> </ul> </div><!-- /.navbar-collapse --> </div><!-- /.container-fluid --> </nav> </header> <main class="row">
/** * @Authorize "Admin" */ public function deleteHall(int $hallId) : View { try { $hall = $this->db->FindFirst("Hall", "id='{$hallId}'"); if ($hall == false) { throw new \Exception("Hall #{$hallId} does not exist"); } $hall->destroy(); $this->redirect(\Framework\Helpers\Helpers::url() . "admin/halls"); } catch (\Exception $e) { $viewModel = new \Framework\Areas\Admin\ViewModels\Halls\EditHallViewModel(); $viewModel->errorsList = $model->getErrorsList(); $viewModel->errorsList[] = $e->getMessage(); $viewModel->error = true; $hall = $this->db->FindFirst("Hall", "id='{$hallId}'"); $viewModel->hallName = $hall->name; $viewModel->hallId = $hallId; $viewModel->belongsToId = $hall->venue_id; foreach ($this->db->findAll("Venue") as $venue) { $viewModel->venues[] = array('id' => $venue->id, 'name' => $venue->name); } return new View('\\Halls\\getEditHall', $viewModel); } }
echo \Framework\Core\Csrf::getToken(); ?> name= <?php echo \Framework\Config\Config::ACSRF_FIELD_NAME; ?> /> <input type="submit" value="Log in" /> <?php if ($model->error) { ?> <div class='errors-box-cont col-xs-12'> <?php echo $model->error ? $model->ListErrors() : ''; ?> </div> <?php } ?> </form> </div> <script src="<?php echo \Framework\Helpers\Helpers::url(); ?> Js/Libs/jquery-2.1.4.min.js"></script> <script src="<?php echo \Framework\Helpers\Helpers::url(); ?> Js/index.js"></script> </body> </html>
/** * @NoAction * @param string $path */ public function redirect(string $path = AppConfig::DEFAULT_REDIRECTION) { header("Location: " . Helpers::url() . $path); exit; }
<label class="col-md-2 control-label" for="Category">Venue</label> <div class="col-md-10"> <select class="form-control" name="venueId" required> <option value="">-- Select Venue --</option>--> <?php foreach ($model->getVenues() as $venue) { ?> <option value="<?php echo htmlspecialchars(intval($venue["id"])); ?> "><?php echo htmlspecialchars($venue["name"]); ?> </option> <?php } ?> </select> </div> </div> <div class="form-group col-md-7"> <div class="col-md-offset-2 col-md-10"> <input type="submit" class="btn btn-primary" value="Add"> <a class="btn btn-default" href="<?php echo \Framework\Helpers\Helpers::url() . "admin/halls"; ?> ">Cancel</a> </div> </div> </form>
/** * @Authorize "Admin" */ public function logout() { \Framework\Core\Identity::logout(); $this->redirect(\Framework\Helpers\Helpers::url() . "admin/login"); }
</div> </div> <div class="form-group col-md-7"> <label class="col-md-3 control-label" for="new-role">New role</label> <div class="col-md-9"> <select id="new-role" class="form-control" name="newRole" required> <option value="">-- Select role --</option> <?php foreach ($model->getRoles() as $role) { ?> <option value="<?php echo htmlspecialchars($role["id"]); ?> "><?php echo htmlspecialchars($role["name"]); ?> </option> <?php } ?> </select> </div> </div> <div class="form-group col-md-7 "> <input type="submit" class="btn btn-primary col-md-offset-4" value="Add"> <a class="btn btn-default" href="<?php echo \Framework\Helpers\Helpers::url() . "admin/users"; ?> ">Cancel</a> </div> </form>
" class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'register'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-registration-mark"></span> Register</a></li> </ul> <?php } else { ?> <ul class="nav navbar-nav"> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'profile'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-user"></span> Profile</a></li> </ul> <ul class="nav navbar-nav navbar-right"> <li><a href="<?php echo \Framework\Helpers\Helpers::url() . 'logout'; ?> " class="hvr-underline-reveal"><span class="glyphicon glyphicon-log-out"></span> Logout</a></li> </ul> <?php } ?> </ul> </div> </div> </nav> </header> <div class="container">
private function updateDatabase() { $tablesClasses = $this->getIdentityClasses(); $this->processTableClasses($tablesClasses); Helpers::writeInFile("Config/migrations.txt", strval(time())); }
private function scanControllersRoutes(array $controllersNames) { foreach ($controllersNames as $controllersName) { $fullPath = "Framework\\" . "Controllers" . "\\" . $controllersName; $rc = new \ReflectionClass($fullPath); $methods = $rc->getMethods(); foreach ($methods as $method) { $methodDoc = $method->getDocComment(); if ($methodDoc && preg_match('/@NoAction/', $methodDoc, $dummy)) { continue; } $requestMethods = array("GET"); $action = $controllersName . "/" . $method->getName(); if ($methodDoc && preg_match_all('/@(POST|PUT|DELETE|GET)/', $methodDoc, $requestMethodsAnnotations)) { $requestMethods = $requestMethodsAnnotations[1]; } $this->actions[$action] = array("methods" => $requestMethods, "annotations" => [], "params" => [], "arguments" => []); if ($methodDoc && preg_match('/@Route\\(([^\\)]+)\\)/', $methodDoc, $routeAnnotation)) { $params = explode("/", $routeAnnotation[1]); array_shift($params); array_shift($params); $this->customRoutes[$routeAnnotation[1]] = array("controller" => $controllersName, "action" => $method->getName(), "parameters" => $params, "methods" => $requestMethods); } if ($methodDoc && preg_match_all('/@@(\\w+)(?:\\(([^)\\s\\n*]+)\\))*/', $methodDoc, $fieldMatch)) { for ($i = 0; $i < count($fieldMatch[0]); $i++) { $annotationName = AppConfig::ANNOTATIONS_NAMESPACE . ucfirst($fieldMatch[1][$i]) . AppConfig::ANNOTATIONS_SUFFIX; $this->actions[$action]["annotations"][$annotationName] = $fieldMatch[2][$i]; } } if ($methodDoc && preg_match_all('/@param\\s+([^\\s]+)\\s+\\$([^\\s]+)/', $method->getDocComment(), $parameterType)) { for ($i = 0; $i < count($parameterType[0]); $i++) { $this->actions[$action]["params"][$parameterType[2][$i]] = $parameterType[1][$i]; } } } } Helpers::writeInFile("Config/routes.json", json_encode($this->customRoutes)); Helpers::writeInFile("Config/actions.json", json_encode($this->actions)); }
private function checkBindingModel() { $errors = []; $controller = AppConfig::CONTROLLERS_NAMESPACE . ucfirst($this->getControllerName()) . AppConfig::CONTROLLERS_SUFFIX; $reflector = new \ReflectionClass($controller); $method = $reflector->getMethod($this->action); if (!$method->getParameters()) { return; } $params = $method->getParameters(); $count = 0; foreach ($params as $param) { if ($param->getClass() !== null && class_exists($param->getClass()->getName(), false)) { $className = $param->getClass()->getName(); if (Helpers::endsWith($className, "BindingModel")) { $paramReflectorClass = new \ReflectionClass($param->getClass()->getName()); $bindingModelName = $paramReflectorClass->getName(); $bindingModel = new $bindingModelName(); $paramClassFields = $paramReflectorClass->getProperties(); foreach ($paramClassFields as $field) { $doc = $field->getDocComment(); $annotations = self::getBindingModelAnnotations($doc); $fieldName = $field->getName(); $setter = 'set' . $field->getName(); $displayName = array_key_exists("Display", $annotations) ? $annotations["Display"] : $fieldName; if (array_key_exists("Required", $annotations) && !isset($_POST[$fieldName]) || strlen($_POST[$fieldName]) === 0) { $errors[] = $displayName . " is required."; } else { if (array_key_exists("MinLength", $annotations) && isset($_POST[$fieldName]) && strlen($_POST[$fieldName]) < intval($annotations["MinLength"])) { $errors[] = "Min length for " . $displayName . " is " . $annotations["MinLength"]; } else { if (array_key_exists("MaxLength", $annotations) && isset($_POST[$fieldName]) && strlen($_POST[$fieldName]) > intval($annotations["MaxLength"])) { $errors[] = "Max length for " . $displayName . " is " . $annotations["MaxLength"]; } else { $bindingModel->{$setter}($_POST[$fieldName]); } } } } $this->params[] = $bindingModel; } } else { if (count($this->params) < $count + 1) { throw new \Exception("Different parameters count!"); } else { if (preg_match('/@param ([^\\s]+) \\$' . $param->getName() . "/", $method->getDocComment(), $parameterType)) { if ($parameterType[1] === "int") { $this->params[$count] = intval($this->params[$count]); } } } } $count++; } if (count($errors) > 0) { $redirect = $this->requestStr; if (HttpContext::getInstance()->getRequest()->getForm()->redirect !== "") { $redirect = HttpContext::getInstance()->getRequest()->getForm()->redirect; } $_SESSION["binding-errors"] = $errors; throw new ApplicationException("", $redirect); } }
<p>Start time: <span class="start-time-span"><?php echo htmlspecialchars($conference["startTime"]); ?> </span></p> <p>End time: <span class="end-time-span"><?php echo htmlspecialchars($conference["endTime"]); ?> </span></p> <?php if ($conference["isDismissed"]) { ?> <p><span class="dismissed-span">Dismissed</span></p> <?php } elseif ($conference["isActive"]) { ?> <p><span class="active-span">Active</span></p> <?php } else { ?> <p><span class="inactive-span">Inactive</span></p> <?php } ?> <p><a href="<?php echo \Framework\Helpers\Helpers::url() . "conferences/details/" . htmlspecialchars($conference["id"]); ?> " class="btn btn-primary" role="button">Learn more</a></p> </div> <?php } }
/** * @Authorize "Admin" */ public function deleteUser(int $userId) : View { try { $user = $this->db->FindFirst(\Framework\Config\Config::USER_CLASS, "id='{$userId}'"); if ($user == false) { throw new \Exception("User #{$userId} does not exist"); } $userLectures = $this->db->FindAll("UserLecture", "user_id='{$userId}'"); $lectures = $this->db->FindAll("Lecture", "user_id='{$userId}'"); $confs = $this->db->FindAll("Conference", "user_id='{$userId}'"); $notifs = $this->db->FindAll("Notification", "user_id='{$userId}'"); foreach ($userLectures as $ul) { $ul->destroy(); } foreach ($lectures as $l) { $l->destroy(); } foreach ($confs as $c) { $c->destroy(); } foreach ($notifs as $n) { $n->destroy(); } $user->destroy(); $this->redirect(\Framework\Helpers\Helpers::url() . "admin/users"); } catch (\Exception $e) { $viewModel = new \Framework\Areas\Admin\ViewModels\Users\EditUserViewModel(); $viewModel->errorsList = $model->getErrorsList(); $viewModel->errorsList[] = $e->getMessage(); $viewModel->error = true; $user = \Framework\Core\Identity::getUserInformation($userId); $viewModel->firstname = $user['firstname']; $viewModel->lastname = $user['lastname']; $viewModel->email = $user['email']; $viewModel->id = $user['id']; $viewModel->username = $user['username']; return new View('\\Users\\getEditUser', $viewModel); } }
<span class="datepicker-icon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> </div> <div class="form-group col-md-7"> <label class="col-md-3 control-label" for="end-time">End time</label> <div id="end-time-picker" class="input-group col-md-9 date date-input date-picker"> <input class="form-control" id="end-time" name="endTime" type="datetime" value="<?php echo htmlspecialchars($model->getEndTime()); ?> " readonly> <div class="input-group-addon"> <span class="datepicker-icon"> <span class="glyphicon glyphicon-calendar"></span> </span> </div> </div> </div> <div class="form-group col-md-7"> <div class="col-md-offset-2 col-md-10"> <input type="submit" class="btn btn-primary" value="Activate"> <a class="btn btn-default" href="<?php echo \Framework\Helpers\Helpers::url() . "conferences/edit/" . htmlspecialchars($model->getId()); ?> ">Cancel</a> </div> </div> </form>
<strong>Register Yourself</strong> </div> <div class="panel-body"> <form action="" role="form" method="post"> <div class="form-group input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-tag"></i></span> <input id="login-username" type="text" class="form-control" name="userName" value="" placeholder="Desired Username" required> </div> <div class="form-group input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span> <input id="login-fullname" type="text" class="form-control" name="fullName" value="" placeholder="Your Name" required> </div> <div class="form-group input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> <input id="login-password" type="password" class="form-control" name="password" placeholder="Enter Password" required> </div> <div class="form-group input-group"> <span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span> <input id="login-password" type="password" class="form-control" name="confirmPassword" placeholder="Repeat Password" required> </div> <input type="submit" value="Register me" id="login-btn" class="btn btn-success " /> <hr /> Already Registered ? <a href="<?php echo \Framework\Helpers\Helpers::url() . 'users/login'; ?> ">Login here</a> </form> </div> </div> </div> </div>