function admin_add client_id _SESSION User id this- set client_id clie

  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
function admin_add() {
$client_id=$_SESSION['User']['id'];
$this->set('client_id',$client_id);
$conditions=array('client_id'=>$client_id);
if (empty($this->data)) {
$this->set('addFieldGroups', $this->AddField->AddFieldGroup->find('list', array('conditions'=>$conditions, 'fields'=>array('id', 'name'))));
$id='new';
if($id)
{
$conditions=array('AddFieldOption.add_fields_id'=>intval($id));
$option_array =$this->AddFieldOption->findAll($conditions, null, 'AddFieldOption.order ASC');
// mehrere Optionen [max. 10, dann speichern]
$option_array['new']=array('AddFieldOption');
$option_array['new']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_1']=array('AddFieldOption');
$option_array['new_1']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_2']=array('AddFieldOption');
$option_array['new_2']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_3']=array('AddFieldOption');
$option_array['new_3']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_4']=array('AddFieldOption');
$option_array['new_4']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_4']=array('AddFieldOption');
$option_array['new_4']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_5']=array('AddFieldOption');
$option_array['new_5']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_6']=array('AddFieldOption');
$option_array['new_6']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_7']=array('AddFieldOption');
$option_array['new_7']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_8']=array('AddFieldOption');
$option_array['new_8']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_9']=array('AddFieldOption');
$option_array['new_9']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$this->set('add_options', $option_array);
}
$this->render();
} else {
if(isset($this->data['AddField']['id']))
{
unset($this->data['AddField']['id']);
}
//print_r($this->data);
if ($this->AddField->save($this->data))
{
$newoption_array=array('new', 'new_1', 'new_2', 'new_3', 'new_4', 'new_5', 'new_6', 'new_7', 'new_8');
if(isset($this->data['AddFieldOption']) && is_array($this->data['AddFieldOption']))
{
foreach($this->data['AddFieldOption'] as $option)
{ $addFieldOption=$option;
if(in_array($addFieldOption['id'], $newoption_array))
{
unset($addFieldOption['id']);
unset($addFieldOption['duration']);
}
if(!isset($addFieldOption['active']))
{
$addFieldOption['active']=0;
}
$addFieldOption['add_fields_id']=$this->AddField->id;
if($this->AddFieldOption->save($addFieldOption))
{
$this->AddFieldOption->id = false;
}
}
}
$this->Session->setFlash(__("be_add_field_save",true));
$this->redirect('/admin/AddFields/index');
} else {
//print_r($this->data);
$this->Session->setFlash(__("be_error",true));
$this->set('clients', $this->Client->find('list'));
$this->set('addFieldGroups', $this->AddFieldGroup->find('list',array('conditions'=>$conditions)));
}
}
}
function admin_edit($id = null) {
$client_id=$_SESSION['User']['id'];
$this->set('client_id',$client_id);
$add_options=array();
$this->set('add_options',$add_options);
$redirect_string='/admin*add_fields*edit*'.$id;
if (empty($this->data)) {
if (!$id) {
$this->Session->setFlash(__("be_error_id" ,true));
$this->redirect('/admin/add_fields/index');
}
$this->data = $this->AddField->read(null, $id);
$this->set('clients', $this->Client->find('list'));
// wohin nach loeschen weitergeleitet?
$redirect_string='/admin*add_fields*edit*'.$id;
$this->set('redirect_string',$redirect_string);
$dummy_array=$this->AddField->AddFieldGroup->find('list',array('conditions'=>array('client_id'=>$client_id), 'fields'=>array('id', 'name')));
$this->set('addFieldGroups', $dummy_array);
if($id>0)
{
$conditions=array('AddFieldOption.add_fields_id'=>intval($id));
$option_array =$this->AddFieldOption->findAll($conditions, null, 'AddFieldOption.order ASC');
// mehrere Optionen [max. 10, dann speichern]
$option_array['new']=array('AddFieldOption');
$option_array['new']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_1']=array('AddFieldOption');
$option_array['new_1']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_2']=array('AddFieldOption');
$option_array['new_2']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_3']=array('AddFieldOption');
$option_array['new_3']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_4']=array('AddFieldOption');
$option_array['new_4']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_4']=array('AddFieldOption');
$option_array['new_4']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_5']=array('AddFieldOption');
$option_array['new_5']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_6']=array('AddFieldOption');
$option_array['new_6']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_7']=array('AddFieldOption');
$option_array['new_7']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_8']=array('AddFieldOption');
$option_array['new_8']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$option_array['new_9']=array('AddFieldOption');
$option_array['new_9']['AddFieldOption']=array('add_fields_id'=>$id, 'name'=>'', 'value'=>'', 'attr'=>'', 'active'=>'', 'order'=>'');
$this->set('add_options', $option_array);
}
} else {
if($this->AddField->save($this->data)){
$newoption_array=array('new', 'new_1', 'new_2', 'new_3', 'new_4', 'new_5', 'new_6', 'new_7', 'new_8');
if(isset($this->data['AddFieldOption']) && is_array($this->data['AddFieldOption']))
{
foreach($this->data['AddFieldOption'] as $option)
{ $addFieldOption=$option;
if(in_array($addFieldOption['id'], $newoption_array))
{
unset($addFieldOption['id']);
unset($addFieldOption['duration']);
}
if(!isset($addFieldOption['active']))
{
$addFieldOption['active']=0;
}
if($this->AddFieldOption->save($addFieldOption))
{
$this->AddFieldOption->id = false;
}
}
}
$this->Session->setFlash(__("be_add_field_save",true));
$this->redirect('/admin/add_fields/index');
}
else {
$this->Session->setFlash(__("be_error",true));
$this->set('clients', $this->Client->find('list'));
$dummy=$this->AddFieldGroup->find('list');
$this->set('addFieldGroups', $dummy);
}
}
}