From dfe234a7aaaacedcc94716f955b44a1b50c4a057 Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 6 Apr 2016 13:50:31 +0200 Subject: * components -> controls --- app/php/controls/CalendarScaffold.php | 127 ++++++++++++++++++++++++++++++ app/php/controls/CalendarScaffold.tpl | 57 ++++++++++++++ app/php/controls/HeaderMenu.php | 16 ++++ app/php/controls/HeaderMenu.tpl | 22 ++++++ app/php/controls/LoginBox.php | 23 ++++++ app/php/controls/LoginBox.tpl | 29 +++++++ app/php/controls/PasswordChange.php | 38 +++++++++ app/php/controls/PasswordChange.tpl | 52 ++++++++++++ app/php/controls/RegistrationForm.php | 26 ++++++ app/php/controls/RegistrationForm.tpl | 59 ++++++++++++++ app/php/controls/SafeActiveFileUpload.php | 12 +++ app/php/controls/SafeFileUpload.php | 34 ++++++++ app/php/controls/TimezoneSelect.php | 49 ++++++++++++ app/php/controls/TimezoneSelect.tpl | 4 + app/php/controls/UpcomingEvents.php | 35 ++++++++ app/php/controls/UpcomingEvents.tpl | 10 +++ app/php/controls/UserSelection.php | 39 +++++++++ app/php/controls/UserSelection.tpl | 25 ++++++ app/php/controls/config.xml | 6 ++ 19 files changed, 663 insertions(+) create mode 100644 app/php/controls/CalendarScaffold.php create mode 100644 app/php/controls/CalendarScaffold.tpl create mode 100644 app/php/controls/HeaderMenu.php create mode 100644 app/php/controls/HeaderMenu.tpl create mode 100644 app/php/controls/LoginBox.php create mode 100644 app/php/controls/LoginBox.tpl create mode 100644 app/php/controls/PasswordChange.php create mode 100644 app/php/controls/PasswordChange.tpl create mode 100644 app/php/controls/RegistrationForm.php create mode 100644 app/php/controls/RegistrationForm.tpl create mode 100644 app/php/controls/SafeActiveFileUpload.php create mode 100644 app/php/controls/SafeFileUpload.php create mode 100644 app/php/controls/TimezoneSelect.php create mode 100644 app/php/controls/TimezoneSelect.tpl create mode 100644 app/php/controls/UpcomingEvents.php create mode 100644 app/php/controls/UpcomingEvents.tpl create mode 100644 app/php/controls/UserSelection.php create mode 100644 app/php/controls/UserSelection.tpl create mode 100644 app/php/controls/config.xml (limited to 'app/php/controls') diff --git a/app/php/controls/CalendarScaffold.php b/app/php/controls/CalendarScaffold.php new file mode 100644 index 0000000..f265d53 --- /dev/null +++ b/app/php/controls/CalendarScaffold.php @@ -0,0 +1,127 @@ +setViewState('Facade', $facade); + } + + public function getFacade() { + return $this->getViewState('Facade'); + } + + public function onPreRender($param) { + parent::onPreRender($param); + if (!$this->Page->IsPostBack && !$this->Page->IsCallBack) { + $this->_rebindData(); + } + } + + private function _rebindCalendars(array $calendars) { + $this->Calendars->DataSource = $calendars; + $this->Calendars->dataBind(); + } + + private function _rebindCategoryList(array $categories) { + foreach ($this->Calendars->Columns as $column) { + if ($column->ID === 'Category' + && $column instanceof TActiveDropDownListColumn) { + $column->ListDataSource = $categories; + } + } + } + + private function _rebindData($refresh = FALSE) { + $this->_rebindCategoryList( + $this->_getCategories() + ); + $this->_rebindCalendars( + $this->_getCalendars($refresh) + ); + } + + private function _getCalendars($refresh = FALSE) { + if ($refresh) { + $this->clearViewState('Calendars'); + } + $calendars = $this->getViewState( + 'Calendars', + $this->getFacade()->getAll() + ); + $this->setViewState('Calendars', $calendars); + return $calendars; + } + + private function _getCategories() { + $categories = $this->getViewState( + 'Categories', + $this->getFacade()->getCategories() + ); + $this->setViewState('Categories', $categories); + return $categories; + } + + public function editRow($sender, $param) { + $this->Calendars->EditItemIndex = $param->Item->ItemIndex; + $this->_rebindData(); + } + + private function _compileSaveData(TDataGridItem $item) { + return [ + 'CategoryID' => $item->Category->DropDownList->SelectedValue, + 'Visible' => $item->Visible->CheckBox->Checked, + 'CustomName' => $item->CustomName->TextBox->SafeText, + 'CustomUrl' => $item->CustomUrl->TextBox->SafeText, + 'CustomImage' => $item->CustomImage->Value->SafeText + ]; + } + + public function saveRow($sender, $param) { + $calendar = $this->getFacade()->get( + $sender->DataKeys[$param->Item->ItemIndex] + ); + if ($calendar) { + foreach ($calendar as $c) { + $c->saveData($this->_compileSaveData($param->Item)); + } + } else { + throw new TInvalidDataValueException('Calendar not found'); + } + $this->Calendars->EditItemIndex = -1; + $this->_rebindData(TRUE); + } + + public function cancelRowEdit($sender, $param) { + $this->Calendars->EditItemIndex = -1; + $this->_rebindData(); + } + + public function uploadRowFile($sender, $param) { + $fileType = $sender->getFileType(); + if (preg_match('/^image\//', $fileType)) { + $calendar = $this->getFacade()->get($sender->CustomData); + if ($calendar) { + $targetFile = $calendar[0]->getCustomImagePath( + $sender->getLocalName(), + $fileType + ); + if ($sender->saveAs($targetFile)) { + $sender->NamingContainer->CustomImage->Value->Text = basename( + $targetFile + ); + } + } else { + throw new TInvalidDataValueException('Calendar not found'); + } + } else { + throw new TInvalidDataTypeException('Invalid file type'); + } + } + +} + +?> diff --git a/app/php/controls/CalendarScaffold.tpl b/app/php/controls/CalendarScaffold.tpl new file mode 100644 index 0000000..6688869 --- /dev/null +++ b/app/php/controls/CalendarScaffold.tpl @@ -0,0 +1,57 @@ + + + + + + + + + + + + <%# $this->Parent->Data->CustomImageUrl %> + + + + + <%# $this->Parent->Data->CustomImage %> +
+ + <%# $this->Parent->Data->UID %> + +
+
+ +
diff --git a/app/php/controls/HeaderMenu.php b/app/php/controls/HeaderMenu.php new file mode 100644 index 0000000..bffe4d2 --- /dev/null +++ b/app/php/controls/HeaderMenu.php @@ -0,0 +1,16 @@ +Application->getModule('auth')->logout(); + $this->Response->redirect( + $this->Service->ConstructUrl(NULL) + ); + } + +} + +?> diff --git a/app/php/controls/HeaderMenu.tpl b/app/php/controls/HeaderMenu.tpl new file mode 100644 index 0000000..603a231 --- /dev/null +++ b/app/php/controls/HeaderMenu.tpl @@ -0,0 +1,22 @@ + diff --git a/app/php/controls/LoginBox.php b/app/php/controls/LoginBox.php new file mode 100644 index 0000000..33bbcc1 --- /dev/null +++ b/app/php/controls/LoginBox.php @@ -0,0 +1,23 @@ +Page->IsValid) { + $this->Response->redirect( + $this->Application->getModule('auth')->ReturnUrl + ?: $this->Service->constructUrl(NULL) + ); + } + } + + public function validatePassword($sender, $param) { + $param->IsValid = $this->Application->getModule('auth')->login( + $this->Login->Text, + $this->Password->Text + ); + } + +} + +?> diff --git a/app/php/controls/LoginBox.tpl b/app/php/controls/LoginBox.tpl new file mode 100644 index 0000000..d3e1a1e --- /dev/null +++ b/app/php/controls/LoginBox.tpl @@ -0,0 +1,29 @@ +Username: + + +
+Password: + + + +
+ diff --git a/app/php/controls/PasswordChange.php b/app/php/controls/PasswordChange.php new file mode 100644 index 0000000..9f2ac7f --- /dev/null +++ b/app/php/controls/PasswordChange.php @@ -0,0 +1,38 @@ +getControlState('user'); + } + + public function setUserToChange(DbUser $user) { + if ($user->IsGuest) { + throw new TInvalidDataValueException( + 'Password change impossible for guest user' + ); + } + $this->setControlState('user', $user); + } + + public function checkPassword($sender, $param) { + $param->IsValid = DbUser::verifyPassword( + $this->Password->Text, $this->UserToChange->getPassword() + ); + } + + public function changePassword($sender, $param) { + $this->SuccessMessage->Visible = FALSE; + if ($this->Page->IsValid) { + $this->UserToChange->changePassword( + $this->NewPassword->Text + ); + $this->SuccessMessage->Visible = TRUE; + } + } + +} + +?> diff --git a/app/php/controls/PasswordChange.tpl b/app/php/controls/PasswordChange.tpl new file mode 100644 index 0000000..915e8b3 --- /dev/null +++ b/app/php/controls/PasswordChange.tpl @@ -0,0 +1,52 @@ +Change password
+Current password: + + + +
+New password: + + +
+Repeat password: + + + +
+ + diff --git a/app/php/controls/RegistrationForm.php b/app/php/controls/RegistrationForm.php new file mode 100644 index 0000000..71d4df1 --- /dev/null +++ b/app/php/controls/RegistrationForm.php @@ -0,0 +1,26 @@ +IsValid = !User::finder()->countByLogin($this->Login->SafeText); + } + + public function registerUser($sender, $param) { + if ($this->Page->IsValid) { + $newUser = new User(); + $newUser->Login = $this->Login->SafeText; + $newUser->Password = DbUser::generatePassword($this->Password->Text); + $newUser->IsAdmin = $this->Admin->Checked; + $newUser->save(); + $this->Response->redirect( + $this->Service->constructUrl(NULL) + ); + } + } + +} + +?> diff --git a/app/php/controls/RegistrationForm.tpl b/app/php/controls/RegistrationForm.tpl new file mode 100644 index 0000000..ffa4778 --- /dev/null +++ b/app/php/controls/RegistrationForm.tpl @@ -0,0 +1,59 @@ +Username: + + + + +
+Password: + + +
+Repeat password: + + + +
+Admin: + +
+ + diff --git a/app/php/controls/SafeActiveFileUpload.php b/app/php/controls/SafeActiveFileUpload.php new file mode 100644 index 0000000..ada1e34 --- /dev/null +++ b/app/php/controls/SafeActiveFileUpload.php @@ -0,0 +1,12 @@ + diff --git a/app/php/controls/SafeFileUpload.php b/app/php/controls/SafeFileUpload.php new file mode 100644 index 0000000..98e120a --- /dev/null +++ b/app/php/controls/SafeFileUpload.php @@ -0,0 +1,34 @@ +_isSecure; + } + + public function setIsSecure($bool) { + $this->_isSecure = $bool; + } + + public function getFileType() { + $type = parent::getFileType(); + if ($this->getIsSecure()) { + $fileInfo = new finfo(FILEINFO_MIME_TYPE); + return $fileInfo->file($this->getLocalName()); + } + else { + return $type; + } + } + +} + +?> diff --git a/app/php/controls/TimezoneSelect.php b/app/php/controls/TimezoneSelect.php new file mode 100644 index 0000000..3302e2a --- /dev/null +++ b/app/php/controls/TimezoneSelect.php @@ -0,0 +1,49 @@ +getControlState('user'); + } + + public function setUserToChange(DbUser $user) { + if ($user->IsGuest) { + throw new TInvalidDataValueException( + 'Timezone preference change impossible for guest user' + ); + } + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Timezones->DataSource = $this->_getTimezones(); + $this->Timezones->DataValueField = 'Name'; + $this->Timezones->DataTextField = 'Label'; + $this->Timezones->dataBind(); + $this->Timezones->setSelectedValue( + $this->UserToChange->getTimezonePreference()->Name + ); + } + + public function saveTimezone($sender, $param) { + $this->UserToChange->setTimezonePreference($this->Timezones->SelectedValue); + } + + private function _getTimezones() { + $timezones = array_map( + function($tz) { + return new TimezoneDTO($tz); + }, + DateTimeZone::listIdentifiers() + ); + usort($timezones, ['TimezoneDTO', '__compare']); + return $timezones; + } + +} + +?> diff --git a/app/php/controls/TimezoneSelect.tpl b/app/php/controls/TimezoneSelect.tpl new file mode 100644 index 0000000..2d40014 --- /dev/null +++ b/app/php/controls/TimezoneSelect.tpl @@ -0,0 +1,4 @@ + + diff --git a/app/php/controls/UpcomingEvents.php b/app/php/controls/UpcomingEvents.php new file mode 100644 index 0000000..27fa8c6 --- /dev/null +++ b/app/php/controls/UpcomingEvents.php @@ -0,0 +1,35 @@ +getControlState('user'); + } + + public function setUserToDisplay($user) { + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Events->setDataSource( + $this->_getEventsForUser($this->UserToDisplay) + ); + $this->Events->dataBind(); + } + + private function _getEventsForUser(DbUser $user) { + $utc = new DateTimeZone('UTC'); + $dateFrom = new DateTime('now', $utc); + $dateTo = new DateTime('+7 days', $utc); + return EventFacade::getInstance()->getTimeframeListForUser( + $user, + $dateFrom, $dateTo + ); + } + +} + +?> diff --git a/app/php/controls/UpcomingEvents.tpl b/app/php/controls/UpcomingEvents.tpl new file mode 100644 index 0000000..d660f54 --- /dev/null +++ b/app/php/controls/UpcomingEvents.tpl @@ -0,0 +1,10 @@ +Upcoming events: +
+ + + <%# $this->Data->DateString %> + <%# $this->Data->Name %> + (<%# $this->Data->Calendar->Name %>) +
+
+
diff --git a/app/php/controls/UserSelection.php b/app/php/controls/UserSelection.php new file mode 100644 index 0000000..6ae68e4 --- /dev/null +++ b/app/php/controls/UserSelection.php @@ -0,0 +1,39 @@ +getControlState('user'); + } + + public function setUserToDisplay($user) { + $this->setControlState('user', $user); + } + + public function onPreRender($param) { + parent::onPreRender($param); + $this->Categories->setDataSource( + $this->_getUserSelection($this->UserToDisplay) + ); + $this->Categories->dataBind(); + } + + public function categoryDataBind($sender, $param) { + $param->Item->Calendars->setDataSource($param->Item->Data->Calendars); + $param->Item->Calendars->dataBind(); + } + + public function removeFromSelection($sender, $param) { + if (!$this->UserToDisplay->IsGuest) { + } + } + + private function _getUserSelection(DbUser $user) { + return CalendarFacade::getInstance()->getPreferenceList($user); + } + +} + +?> diff --git a/app/php/controls/UserSelection.tpl b/app/php/controls/UserSelection.tpl new file mode 100644 index 0000000..14035ca --- /dev/null +++ b/app/php/controls/UserSelection.tpl @@ -0,0 +1,25 @@ +Selected calendars: +
+ + + <%# $this->Data->Name %>
+ + + + <%# $this->Data->ID %> + <%# !$this->SourceTemplateControl->UserToDisplay->IsGuest %> + + <%# $this->Data->Name %> + + <%# $this->Data->Website %> + +
+
+
+
+
+
diff --git a/app/php/controls/config.xml b/app/php/controls/config.xml new file mode 100644 index 0000000..61d7e5b --- /dev/null +++ b/app/php/controls/config.xml @@ -0,0 +1,6 @@ + + + + + + -- cgit v1.2.3