1
+ <?php
2
+ /**
3
+ * AuthorsController
4
+ *
5
+ * PUBLIC: PRIVATE
6
+ * ----------- ------------------
7
+ * __construct
8
+ * indexAction
9
+ * editAction
10
+ * updateAction
11
+ *
12
+ */
13
+ class AuthorsController extends CController
14
+ {
15
+ public function __construct ()
16
+ {
17
+ parent ::__construct ();
18
+
19
+ // block access to this controller for not-logged users
20
+ CAuth::handleLogin ();
21
+
22
+ $ this ->_loggedId = CAuth::getLoggedId ();
23
+
24
+ $ settings = Settings::model ()->findByPk (1 );
25
+ $ this ->view ->setMetaTags ('title ' , 'Account | ' .$ settings ->metatag_title );
26
+ $ this ->view ->setMetaTags ('keywords ' , $ settings ->metatag_keywords );
27
+ $ this ->view ->setMetaTags ('description ' , $ settings ->metatag_description );
28
+ $ this ->view ->blogName = $ settings ->blog_name ;
29
+ $ this ->view ->blogSlogan = $ settings ->slogan ;
30
+ $ this ->view ->blogFooter = $ settings ->footer ;
31
+
32
+ $ this ->view ->activeLink = 'home ' ;
33
+ $ this ->view ->viewRightMenu = false ;
34
+ $ this ->view ->errorField = '' ;
35
+ $ this ->view ->actionMessage = '' ;
36
+ }
37
+
38
+ public function indexAction ()
39
+ {
40
+ $ this ->view ->setMetaTags ('title ' , 'Dashboard | ' .$ this ->view ->blogName );
41
+ $ this ->view ->mainHeader = 'Welcome to Admin Panel! ' ;
42
+ $ this ->view ->mainText = 'The administrator panel is an integrated place to manage your site.
43
+ Use navigation menu links from the left to access required page. ' ;
44
+ $ this ->view ->render ('authors/index ' );
45
+ }
46
+
47
+
48
+ public function editAction ()
49
+ {
50
+ $ this ->view ->activeLink = 'author ' ;
51
+
52
+ $ author = Authors::model ()->findByPk ($ this ->_loggedId );
53
+ if (empty ($ this ->_loggedId ) || !$ author ){
54
+ $ this ->redirect ('authors/index ' );
55
+ }
56
+
57
+ $ this ->view ->login = $ author ->login ;
58
+ $ this ->view ->password = '' ;
59
+ $ this ->view ->passwordRetype = '' ;
60
+ $ this ->view ->email = $ author ->email ;
61
+ $ this ->view ->aboutText = $ author ->about_text ;
62
+ $ this ->view ->avatarFile = $ author ->avatar_file ;
63
+
64
+ $ this ->view ->render ('authors/edit ' );
65
+ }
66
+
67
+ public function updateAction ()
68
+ {
69
+ $ this ->view ->activeLink = 'author ' ;
70
+ $ cRequest = A::app ()->getRequest ();
71
+ $ msg = '' ;
72
+ $ errorType = '' ;
73
+
74
+ if ($ cRequest ->getPost ('act ' ) == 'send ' ){
75
+
76
+ $ author = Authors::model ()->findByPk ($ this ->_loggedId );
77
+
78
+ $ this ->view ->login = $ cRequest ->getPost ('login ' );
79
+ $ this ->view ->password = $ cRequest ->getPost ('password ' );
80
+ $ this ->view ->passwordRetype = $ cRequest ->getPost ('passwordRetype ' );
81
+ $ this ->view ->email = $ cRequest ->getPost ('email ' );
82
+ $ this ->view ->aboutText = $ cRequest ->getPost ('aboutText ' );
83
+ $ this ->view ->avatarFile = !empty ($ _FILES ['avatar ' ]['name ' ]) ? $ _FILES ['avatar ' ]['name ' ] : $ author ->avatar_file ;
84
+
85
+ $ result = CWidget::create ('CFormValidation ' , array (
86
+ 'fields ' =>array (
87
+ 'password ' =>array ('title ' =>'Password ' , 'validation ' =>array ('required ' =>false , 'type ' =>'password ' , 'minLength ' =>6 , 'maxlength ' =>20 )),
88
+ 'passwordRetype ' =>array ('title ' =>'Repeat Password ' , 'validation ' =>array ('required ' =>false , 'type ' =>'confirm ' , 'confirmField ' =>'password ' , 'minLength ' =>6 , 'maxlength ' =>20 )),
89
+ 'email ' =>array ('title ' =>'Email ' , 'validation ' =>array ('required ' =>true , 'type ' =>'email ' , 'maxLength ' =>100 )),
90
+ 'aboutText ' =>array ('title ' =>'About Me ' , 'validation ' =>array ('required ' =>true , 'type ' =>'any ' , 'maxLength ' =>300 )),
91
+ 'avatar ' =>array ('title ' =>'Avatar ' , 'validation ' =>array ('required ' =>false , 'type ' =>'image ' , 'targetPath ' =>'templates/default/images/authors/ ' , 'maxSize ' =>'100k ' , 'mimeType ' =>'image/jpeg, image/png, image/gif, image/jpg ' )),
92
+ ),
93
+ ));
94
+ if ($ result ['error ' ]){
95
+ $ msg = $ result ['errorMessage ' ];
96
+ $ this ->view ->errorField = $ result ['errorField ' ];
97
+ $ errorType = 'validation ' ;
98
+
99
+ if ($ this ->view ->errorField == 'avatar ' ){
100
+ $ this ->view ->avatarFile = $ author ->avatar_file ;
101
+ }
102
+ }else {
103
+ $ author ->email = $ this ->view ->email ;
104
+ $ author ->about_text = $ this ->view ->aboutText ;
105
+ unset($ author ->password );
106
+ unset($ author ->avatar_file );
107
+ if ($ this ->view ->password != '' ){
108
+ $ author ->password = ((CConfig::get ('password.encryption ' )) ? CHash::create (CConfig::get ('password.encryptAlgorithm ' ), $ this ->view ->password , CConfig::get ('password.hashKey ' )) : $ this ->view ->password );
109
+ }
110
+ if ($ this ->view ->avatarFile != '' ){
111
+ $ author ->avatar_file = $ this ->view ->avatarFile ;
112
+ }
113
+
114
+ if (APPHP_MODE == 'demo ' ){
115
+ $ msg = '<b>:(</b> Sorry, but update operation is blocked in DEMO version! ' ;
116
+ $ errorType = 'warning ' ;
117
+ }else {
118
+ if ($ author ->save ()){
119
+ $ msg = 'Author settings have been successfully saved! ' ;
120
+ $ errorType = 'success ' ;
121
+ $ this ->view ->password = '' ;
122
+ $ this ->view ->passwordRetype = '' ;
123
+ }else {
124
+ $ msg = 'An error occurred while saving the settings! Please re-enter. ' ;
125
+ $ this ->view ->errorField = '' ;
126
+ $ errorType = 'error ' ;
127
+ }
128
+ }
129
+ }
130
+ }else {
131
+ $ this ->redirect ('authors/edit ' );
132
+ }
133
+ if (!empty ($ msg )){
134
+ $ this ->view ->actionMessage = CWidget::create ('CMessage ' , array ($ errorType , $ msg , array ('button ' =>true )));
135
+ }
136
+
137
+ $ this ->view ->render ('authors/edit ' );
138
+ }
139
+
140
+ }
0 commit comments