AdministratorController.php
8.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
/**
* @package anc_album
* @category magento
* @mailto code [at] netz.coop
* @author netz.coop eG*
* @copyright (c) 2014, netz.coop eG
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class Anc_Album_Adminhtml_AdministratorController extends Mage_Adminhtml_Controller_Action {//Mage_Core_Controller_Front_Action
protected function _initAction() {
$this->loadLayout();
return $this;
}
/**
* Block/Template Funktion
*
* fnc ist in "mein Benutzerkonto" laut @see app/design/frontend/layout/anc_image.xml als link aufrufbar,
* * durch selbige anc_image.xml bekommt die fnc das template @see app/design/frontend/template/ancimage/customer_owngallery.phtml beigesteuert
*/
public function owngalleryAction() {
$this->loadLayout();
$this->getLayout()->getBlock('root')->setTemplate('page/1column.phtml');
$this->renderLayout();
}
/**
* param - $this->getRequest()->getParams()['id'] -- id des zu bearbeiteten ncimage
*
* Block/Template Funktion
*
*/
// public function showncimageformAction() {
//
// if (Mage::getSingleton('customer/session')->isLoggedIn()) {
// $params=$this->getRequest()->getParams();
// if(is_array($params) && array_key_exists('id', $params)) {
//
// $ncimage = Mage::helper('anc_image/ncmodel')->getNcImage($params['id']);
//D::li($ncimage, '$ncimage'.$params['id']);
// if(is_object($ncimage)) {
//
// if(array_key_exists('name', $params)) {
// $ncimage->setName($params['name']);
// }
// if(array_key_exists('comment', $params)) {
// $ncimage->setComment($params['comment']);
// }
//
// $ncimage = Mage::helper('anc_image/ncmodel')->saveNcImage($ncimage);
// D::compareFe($ncimage,$params, '$ncimage, $this->getParams()');
//
// }
//
// }
//
// $this->loadLayout();
// $this->getLayout()->getBlock('root')->setTemplate('page/empty.phtml');
//// $this->getLayout()->getBlock('content')->append(
//// $this->getLayout()->createBlock('anc_image/owngallery')->setTemplate('anc/image/customer_showNcImageForm.phtml')
//// );
// $this->renderLayout();
// } else {
// echo('nicht eingeloggt');
// }
//
// }
public function simpleowngalleryAction() {
// D::li('simpleowngalleryAction');
$this->loadLayout();
$this->getLayout()->getBlock('root')->setTemplate('page/empty.phtml');
$this->renderLayout();
}
/**
* @param _POST[id] => $this->getRequest()->getParams()[id] -- anc_image/ncimage id
*
*/
// public function deleteNcImageAction() {
// $params=$this->getRequest()->getParams();
// $json_rueckgabe = array();
// if(array_key_exists('id', $params) && $params['id']) {
// $param_id = $params['id'];
//
// $ncimage = Mage::helper('anc_image/ncmodel')->getNcImage($param_id);
//
// if(Mage::helper('anc_image/ncmodel')->deleteNcImage($ncimage)) {
// $json_rueckgabe['status'] = 'OK';
// $json_rueckgabe['message'] = 'Das Bild ('.$ncimage->getId().' wurde gelöscht)!';
//
// } else {
// $json_rueckgabe['status'] = 'ERROR';
// $json_rueckgabe['message'] = 'Es ist beim Löschen ein Fehler aufgetreten!';
// }
//
// } else {
// $json_rueckgabe['status'] = 'ERROR';
// $json_rueckgabe['message'] = 'Keine ID angegeben!';
// }
//
// echo json_encode($json_rueckgabe);
// }
/**
* http://mag19.lc/index.php/printconfigproduct/adminhtml_tasks/nutzen/qid/1/oid/1/key/312677a8ed3fab83712794fd4cf5a157/
* @param optional _POST[id] => $this->getRequest()->getParams()[id] -- anc_image/ncimage id
*
* fnc wird übers formular von owngalleryAction() bzw customer_owngallery.phtml
* bei einem datei upload aufgerufen und verarbeitet die post werte
* * kopiert datei in entsprechendes kunden verzeichniss
* * speichert dateiname im model / in tabelle
*/
public function uploadImageAction() {
D::li('uploadImageAction');
$params=$this->getRequest()->getParams();
// D::s($params,'$params',5,1);
if(array_key_exists('id', $params)) {
$param_id = $params['id'];
} else {
$param_id = false;
}
$json_rueckgabe = array();
/* Get the customer data */
// $customer = Mage::getSingleton('customer/session')->getCustomer();
// $userArray = Mage::getSingleton('admin/session')->getData();
//// $admin_id = Mage::getSingleton('admin/session')->getUser()->getId();
// D::li('$admin_id: '.$admin_id);
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$user = Mage::getSingleton('admin/session');
// $userId = $user->getUser()->getUserId();
if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') {
try
{
// $path = Mage::helper('anc_image/ncimage')->getPathForNewNcImage(true); Achtung true war glaube ich eh überflüssig .. fnc hat sich geändert
$path = Mage::helper('anc_image/ncimage')->getPathForNewNcImage('original');
$fname = $_FILES['file']['name']; //file name
$uploader = new Varien_File_Uploader('file'); //load class
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); //Allowed extension for file
$uploader->setAllowCreateFolders(true); //for creating the directory if not exists
$uploader->setAllowRenameFiles(true); //if true, uploaded file's name will be changed, if file with the same name already exists directory.
$uploader->setFilesDispersion(false);
$uploader->save($path,$fname); //save the file on the specified path
// den modifizierten namen, falls datei schon existierte
$fname = $uploader->getUploadedFileName();
if(is_file($path.DS.$fname)) {
/**
* datei wird ersetzt
*/
if($param_id) {
$ncimage = Mage::helper('anc_image/ncmodel')->getNcImage($param_id);
if(Mage::helper('anc_image/ncmodel')->deleteNcImageFiles($ncimage)) {
} else {
$json_rueckgabe['status'] = 'ERROR';
$json_rueckgabe['message'] = 'Sie habe nicht die Berechtigung!';
echo json_encode($json_rueckgabe);
return;
}
} else {
$ncimage = Mage::getModel('anc_image/ncimage');
}
$ncimage->setData('customer_id',$user->getUserId());
$ncimage->setData('file',$fname);
$ncimage->save();
$ncimage->setData('path', Mage::helper('anc_image/ncimage')->getNcImagePath($ncimage->getId(), 'relative', 'original'));
$ncimage->save();
if($ncimage->getId()) {
$json_rueckgabe['model'] = 'anc_image/ncimage';
$json_rueckgabe['file'] = $fname;
$json_rueckgabe['id'] = $ncimage->getId();
$json_rueckgabe['path'] = $ncimage->getPath();
$json_rueckgabe['status'] = 'OK';
$json_rueckgabe['message'] = 'upload erfolgreich !! ('.$ncimage->getId().'/'.$uploader->getUploadedFileName().')';
} else {
$json_rueckgabe['status'] = 'ERROR';
$json_rueckgabe['message'] = 'Datei konnte nicht in die Datenbank eingetragen werden';
}
} else {
$json_rueckgabe['status'] = 'ERROR';
$json_rueckgabe['message'] = 'Datei konnte nicht auf dem Server gespeichert werden';
}
} catch (Exception $e) {
$json_rueckgabe['status'] = 'ERROR';
$json_rueckgabe['message'] = $e->getMessage();
}
} else {
$json_rueckgabe['status'] = 'ERROR';
$json_rueckgabe['message'] = 'ubermittlungsprobleme: Datei konnte nicht gespeichert werden (vielleicht war die Datei groesser als '.@ini_get('post_max_size').' MB)';
}
echo json_encode($json_rueckgabe);
}
protected function _isAllowed() {
return Mage::getSingleton('admin/session')->isAllowed('administrator/*');
}
}