@@ -49,28 +49,95 @@ public function accountManage() : void {
4949 $ account = new Template ('account ' );
5050 $ this ->mainTemp ->includeTemplate ($ account );
5151
52- // handle pw change
53- if ( !empty ($ _POST ['type ' ]) && $ _POST ['type ' ] === 'change ' ){
54- $ newPw = $ this ->param ->loginPost ('password ' );
52+ $ share = new Share ($ this ->login );
53+
54+ // handle pw change, share add
55+ if ( !empty ($ _POST ['type ' ]) ){
56+ if ($ _POST ['type ' ] === 'change ' ){
57+ $ newPw = $ this ->param ->loginPost ('password ' );
58+ $ account ->setContent ('NOTEDISABLE ' ,'' );
59+ if (!empty ($ newPw )){
60+ if (Login::createNewGroup (
61+ $ this ->login ->getGroupList (),
62+ $ this ->login ->getGroup (),
63+ $ newPw ,
64+ $ this ->login ->isAdmin ()
65+ )){
66+ $ account ->setContent ('NOTEMSG ' ,'Changed password! ' );
67+ }
68+ else {
69+ $ account ->setContent ('NOTEMSG ' ,'Error changing password! ' );
70+ }
71+ }
72+ else {
73+ $ account ->setContent ('NOTEMSG ' ,'Invalid password given! ' );
74+ }
75+ }
76+ else if ($ _POST ['type ' ] === 'share ' ){
77+ $ account ->setContent ('NOTEDISABLE ' ,'' );
78+ if ( !empty ($ _POST ['category ' ]) && !empty ($ _POST ['group ' ]) ){
79+ $ cat = $ _POST ['category ' ];
80+ $ gr = $ this ->param ->loginPost ('group ' );
81+ if ( InputParser::checkCategoryInput ($ cat ) ){
82+ $ share ->addShare ($ cat , $ gr );
83+ if ($ share ->hasError ()){
84+ $ account ->setContent ('NOTEMSG ' , $ share ->getErrorMessage ());
85+ }
86+ else {
87+ $ account ->setContent ('NOTEMSG ' ,'Share was added. ' );
88+ }
89+ }
90+ else {
91+ $ account ->setContent ('NOTEMSG ' ,'Invalid category given. ' );
92+ }
93+ }
94+ else {
95+ $ account ->setContent ('NOTEMSG ' ,'Please give category and user to share with. ' );
96+ }
97+ }
98+ }
99+ else if (!empty ($ _GET ['remove ' ]) && is_string ($ _GET ['remove ' ])
100+ && !empty ($ _GET ['group ' ]) && is_string ($ _GET ['group ' ])
101+ ){
55102 $ account ->setContent ('NOTEDISABLE ' ,'' );
56- if (!empty ($ newPw )){
57- if (Login::createNewGroup (
58- $ this ->login ->getGroupList (),
59- $ this ->login ->getGroup (),
60- $ newPw ,
61- $ this ->login ->isAdmin ()
62- )){
63- $ account ->setContent ('NOTEMSG ' ,'Changed password! ' );
103+ $ gr = preg_replace ('/[^A-Za-z0-9]/ ' , '' , $ _GET ['group ' ]);
104+ $ cat = $ _GET ['remove ' ];
105+
106+ if ( InputParser::checkCategoryInput ($ cat ) ){
107+ $ share ->removeShare ($ cat , $ gr );
108+ if ($ share ->hasError ()){
109+ $ account ->setContent ('NOTEMSG ' , $ share ->getErrorMessage ());
64110 }
65111 else {
66- $ account ->setContent ('NOTEMSG ' ,'Error changing password! ' );
112+ $ account ->setContent ('NOTEMSG ' ,'Share was deleted. ' );
67113 }
68114 }
69115 else {
70- $ account ->setContent ('NOTEMSG ' ,'Invalid password given! ' );
116+ $ account ->setContent ('NOTEMSG ' ,'Invalid category given while deleting share. ' );
71117 }
72118 }
73119
120+ $ d = array ();
121+ foreach ($ share ->getCategoriesAndGroups () as $ n => $ v ){
122+ $ d [$ n ] = array ();
123+ foreach ($ v as $ e ){
124+ $ d [$ n ][] = array (
125+ "NAME " => $ e ,
126+ "VALUE " => $ e
127+ );
128+ }
129+ }
130+ $ account ->setMultipleContent ('Category ' , $ d ['categories ' ]);
131+ $ account ->setMultipleContent ('Group ' , $ d ['groups ' ]);
132+ $ shares = array ();
133+ foreach ($ share ->getShares () as $ s ){
134+ $ shares [] = array (
135+ 'CATEGORY ' => $ s ['category ' ],
136+ 'GROUP ' => $ s ['group ' ]
137+ );
138+ }
139+ $ account ->setMultipleContent ('Shares ' , $ shares );
140+
74141 if ($ this ->login ->isAdmin ()){
75142 $ account ->setContent ('ISADMIN ' , '' );
76143
0 commit comments