-
Notifications
You must be signed in to change notification settings - Fork 6
/
guifi_devel.inc.php
2131 lines (1822 loc) · 76 KB
/
guifi_devel.inc.php
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// Services output
function guifi_devel_services($service_id=null, $op=null) {
switch($service_id) {
case 'add':
$service_id = 'New';
return drupal_get_form('guifi_devel_services_form',$service_id);
}
switch($op) {
case 'edit':
return drupal_get_form('guifi_devel_services_form',$service_id);
case 'delete':
guifi_log(GUIFILOG_TRACE,'guifi_devel_services_delete()',$service_id);
return drupal_get_form(
'guifi_devel_services_delete_confirm', $service_id);
guifi_devel_services_delete($service_id);
}
$rows = array();
$value = t('Add a new service');
$output = '<form>';
$output .= '<input type="button" id="button" value="'.$value.'" onclick="location.href=\''.url("guifi/menu/devel/service/add").'\'"/>';
$output .= '</form>';
$headers = array(t('Service ID'), t('Text'), t('Description'), t('Edit'), t('Delete'));
$sql = db_query('SELECT * FROM {guifi_types} where type="service" ORDER BY id ASC');
while ($service = db_fetch_object($sql)) {
$rows[] = array($service->id,
$service->text,
$service->description,
l(guifi_img_icon('edit.png'),'guifi/menu/devel/service/'.$service->id.'/edit',
array(
'html' => TRUE,
'title' => t('edit service'),
)).'</td><td>'.
l(guifi_img_icon('drop.png'),'guifi/menu/devel/service/'.$service->id.'/delete',
array(
'html' => TRUE,
'title' => t('delete service'),
)));
}
$output .= theme('table',$headers,$rows,array('class'=>'device-data-med'));
print theme('page',$output, FALSE);
return;
}
// Services Form
function guifi_devel_services_form($form_state, $service_id) {
$sql = db_query('SELECT * FROM {guifi_types} WHERE type = "service" and id = %d', $service_id);
$service = db_fetch_object($sql);
if ($service_id == 'New' ) {
$form['new'] = array('#type' => 'hidden', '#value' => TRUE);
} else {
$form['id'] = array('#type' => 'hidden','#value' => $service_id);
}
$form['text'] = array(
'#type' => 'textfield',
'#size' => 24,
'#maxlength' => 24,
'#title' => t('Text'),
'#required' => TRUE,
'#default_value' => $service->text,
'#description' => t('Text abbreviation of the service.')
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
'#required' => TRUE,
'#default_value' => $service->description,
'#description' => t('Text description of the service.')
);
$form['submit'] = array('#type' => 'submit', '#weight' => 98, '#value' => t('Save'));
$form['cancel'] = array('#type' => 'markup', '#weight' => 99, '#value' => l(t('Cancel'), "guifi/menu/devel/service"),);
return $form;
}
function guifi_devel_services_form_submit($form, &$form_state) {
guifi_log(GUIFILOG_TRACE,'function guifi_devel_services_form_submit()',$form_state);
guifi_devel_services_save($form_state['values']);
drupal_goto('guifi/menu/devel/service');
return;
}
function guifi_devel_services_save($edit) {
global $user;
$to_mail = $edit->notification;
$log ='';
$edit['type'] = 'service';
guifi_log(GUIFILOG_TRACE,'function guifi_devel_services_save()',$edit);
_guifi_db_sql('guifi_types',array('id' => $edit['id'], 'type' => 'service'),$edit,$log,$to_mail);
guifi_notify(
$to_mail,
t('The service !service has been created / updated by !user.',array('!service ' => $edit['model'], '!user' => $user->name)),
$log);
}
function guifi_devel_services_delete_confirm($form_state,$id) {
guifi_log(GUIFILOG_TRACE,'guifi_devel_service_delete_confirm()',$id);
$form['id'] = array('#type' => 'hidden', '#value' => $id);
$qry= db_fetch_object(db_query("SELECT text FROM {guifi_types} WHERE type = 'service' and id = %d", $id));
return confirm_form(
$form,
t('Are you sure you want to delete the service " %service "?',
array('%service' => $qry->text)),
"guifi/menu/devel/service",
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'));
}
function guifi_devel_services_delete_confirm_submit($form, &$form_state) {
global $user;
$depth = 0;
if ($form_state['values']['op'] != t('Delete'))
return;
$to_mail = explode(',',$node->notification);
$log = _guifi_db_delete('guifi_types',array('id' => $form_state['values']['id'], 'type' => 'service'),$to_mail,$depth);
drupal_set_message($log);
guifi_notify(
$to_mail,
t('The service %name has been DELETED by %user.',array('%name' => $form_state['values']['text'], '%user' => $user->name)),
$log);
drupal_goto('guifi/menu/devel/service');
}
// Device Models output
function guifi_devel_devices($devid=null, $op=null) {
switch($devid) {
case 'add':
$devid = 'New';
$jquery1 = HelperMultipleSelect('guifi-devel-devices-form','firmwaresCompatibles', 'firmwaresTots');
drupal_add_js("if (Drupal.jsEnabled) { $jquery1 }", 'inline');
return drupal_get_form('guifi_devel_devices_form',$devid);
}
switch($op) {
case 'edit':
$jquery1 = HelperMultipleSelect('guifi-devel-devices-form','firmwaresCompatibles', 'firmwaresTots');
drupal_add_js("if (Drupal.jsEnabled) { $jquery1 }", 'inline');
return drupal_get_form('guifi_devel_devices_form',$devid);
case 'duplicate':
return drupal_get_form('guifi_devel_devices_duplicate_form',$devid);
case 'delete':
guifi_log(GUIFILOG_TRACE,'guifi_devel_devices_delete()',$devid);
return drupal_get_form(
'guifi_devel_devices_delete_confirm', $devid);
guifi_devel_devices_delete($devid);
}
$rows = array();
$value = t('Add a new device model');
$output = '<form>';
$output .= '<input type="button" id="button" value="'.$value.'" onclick="location.href=\'/guifi/menu/devel/device/add\'"/>';
$output .= '</form>';
$headers = array(t('Manufacturer'), t('Model'), t('Class'), t('#<br>Radios'), t('# Eth<br>ports'),
t('# Opt.<br>ports'), t('Enabled<br>Firms'),
array('data'=>t('Action'),'colspan'=>3));
$sql = db_query('SELECT
m.mid, m.url as model_url , m.model, mf.name as manufacturer_name, mf.url as manufacturer_url
FROM
{guifi_model_specs} m
inner join {guifi_manufacturer} mf on mf.fid = m.fid
ORDER BY mf.name asc , m.model ASC');
$sql = db_query('SELECT
m.mid, m.model_class, m.etherdev_max, m.optoports_max, m.radiodev_max, m.url as model_url , m.model, mf.name as manufacturer_name, mf.url as manufacturer_url, count(usc.id) as enabledUSCs
FROM
{guifi_model_specs} m
inner join {guifi_manufacturer} mf on mf.fid = m.fid
left join {guifi_configuracioUnSolclic} usc on usc.mid = m.mid and usc.enabled = 1
GROUP BY m.mid, model_url, m.model,manufacturer_name, manufacturer_url
ORDER BY mf.name asc , m.model ASC, enabledUSCs desc');
$manufacturer = 'none';
$manufacturers = array();
while ($dev = db_fetch_object($sql)) {
$aclass = array();
if (!empty($dev->model_class)) {
foreach (explode('|',$dev->model_class) as $k => $v)
$aclass[] = t($v);
}
if ($manufacturer != $dev->manufacturer_name) {
$manufacturer = $dev->manufacturer_name;
$manufacturers[] = $manufacturer;
$l_manufacturer = '<a name="M'.count($manufacturers).
'"><a href="'.$dev->manufacturer_url.'">'.$dev->manufacturer_name.'</a>';
} else {
$l_manufacturer = '';
}
$rows[] = array(
$l_manufacturer,
'<a href="'.$dev->model_url.'">'.$dev->mid.'-'.$dev->model.'</a>',
implode(', ',$aclass),
$dev->radiodev_max,
$dev->etherdev_max,
$dev->optoports_max,
$dev->enabledUSCs,
l(guifi_img_icon('edit.png'),'guifi/menu/devel/device/'.$dev->mid.'/edit',
array(
'html' => TRUE,
'attributes' => array('target' => '_blank','title' => t('edit device'))
)),
l(guifi_img_icon('copy.png'),'guifi/menu/devel/device/'.$dev->mid.'/duplicate',
array(
'html' => TRUE,
'attributes' => array('target' => '_blank','title' => t('copy device'))
)),
l(guifi_img_icon('drop.png'),'guifi/menu/devel/device/'.$dev->mid.'/delete',
array(
'html' => TRUE,
'attributes' => array('target' => '_blank','title' => t('delete device'))
)),
);
}
$output .= '<hr>';
foreach ($manufacturers as $k => $v)
$output .= '<a href="#M'.($k + 1).'">'.$v.'</a> - ';
$output .= '<hr>'.theme('table',$headers,$rows,array('class' => 'device-data'));
print theme('page',$output, FALSE);
return;
}
// Duplicate Device Form
function guifi_devel_devices_duplicate_form($form_state, $devid) {
$sql = db_query('SELECT * FROM {guifi_model_specs} WHERE mid = %d', $devid);
$dev = db_fetch_object($sql);
// indicador de new pq volem insertar
$form['new'] = array('#type' => 'hidden', '#value' => TRUE);
// id del que volem copiar les propietats
$form['originalmid'] = array('#type' => 'hidden','#value' => $devid);
$form['model'] = array(
'#type' => 'textfield',
'#title' => t('Model Name'),
'#required' => TRUE,
'#default_value' => 'Copy of '. $dev->model,
'#size' => 32,
'#maxlength' => 50,
'#description' => t('Device model name, please, use a clear and short description.<br />
All Other properties will be automatically transferred.'),
'#prefix' => '<td>',
'#suffix' => '</td>',
'#weight' => $form_weight++,
);
$form['submit'] = array('#type' => 'submit', '#weight' => 99, '#value' => t('Save'));
return $form;
}
// Device Models Form
function guifi_devel_devices_form($form_state, $devid) {
global $user;
if ($devid == 'New' ) {
$form['new'] = array('#type' => 'hidden', '#value' => TRUE);
} else {
$sql = db_query('SELECT * FROM {guifi_model_specs} WHERE mid = %d', $devid);
$dev = db_fetch_object($sql);
$dev->arr_model_class = explode('|',$dev->model_class);
$form['mid'] = array('#type' => 'hidden','#value' => $devid);
}
$query = db_query('SELECT * FROM {guifi_manufacturer}');
while ($manufacturers = db_fetch_array($query)) {
$manuf_array[$manufacturers["fid"]] = $manufacturers["name"];
}
$form_weight=0;
$form['general'] = array(
'#type' => 'fieldset',
'#title' => (isset($form['new'])) ? t('General'):
t('General').' ('.$dev->model.' - '.implode(', ',$dev->arr_model_class).')',
'#attributes' => array('class'=>"model-item"),
'#collapsible' => TRUE,
'#collapsed' => (isset($form['new'])) ? FALSE : TRUE,
);
$form['general']['model'] = array(
'#type' => 'textfield',
'#title' => t('Model Name'),
'#required' => TRUE,
'#default_value' => $dev->model,
'#size' => 32,
'#maxlength' => 50,
'#description' => t('Device model name, please,<br>use a clear and short description.'),
// '#prefix' => '<div>',
// '#suffix' => '</div>',
'#weight' => $form_weight++,
);
$form['general']['fid'] = array(
'#type' => 'select',
'#title' => t('Manufacturer'),
'#required' => TRUE,
'#default_value' => $dev->fid,
'#options' => $manuf_array,
'#description' => t('Select Device Manufacturer.'),
'#weight' => $form_weight++,
);
$form['general']['arr_model_class'] = array(
'#type'=>'select',
'#title'=>t('Model Class'),
'#required' => TRUE,
'#options'=>guifi_types('model_class'),
'#multiple'=>true,
'#size'=>8,
'#default_value'=>explode('|',$dev->model_class),
'#description' => t('Once saved, available fieldsets will change depending on the class selected.'),
'#prefix' => '<div>',
'#suffix' => '</div>',
'#weight' => $form_weight++,
);
$form['general']['url'] = array(
'#type' => 'textfield',
'#title' => t('URL'),
'#required' => TRUE,
'#default_value' => $dev->url,
'#size' => 80,
'#maxlength' => 128,
'#description' => t('Url where we can see a specs from device model.'),
'#weight' => $form_weight++,
);
$form['general']['rackeable'] = array(
'#type' => 'select',
'#title' => t('Rackeable'),
'#required' => TRUE,
'#default_value' => $dev->rackeable,
'#options' => array('no',1,2,3,4,5,6,7,8,9,10,11,12),
'#description' => t("Not rackeable or<br>number of U's"),
'#weight' => $form_weight++,
);
$form['general']['notification'] = array(
'#type' => 'textfield',
'#size' => 80,
'#maxlength' => 1024,
'#title' => t('contact'),
'#required' => FALSE,
'#element_validate' => array('guifi_emails_validate'),
'#default_value' => (empty($dev->notification)) ? $user->mail : $dev->notification,
'#weight' => $form_weight++,
// '#prefix'=>'<br><br>',
'#description' => t('Mailid where changes on the device will be notified, if many, separated by \',\'<br />used for network administration.'),
);
$form['continue'] = array(
'#type' => 'submit',
'#weight' => 99, '#value' => t('Save & continue edit'));
$form['submit'] = array(
'#type' => 'submit',
'#weight' => 100, '#value' => t('Save'));
if (isset($form['new'])) {
return $form;
}
$form['ethernet'] = array(
'#type' => 'fieldset',
'#title' => ($dev->etherdev_max) ?
t('Ethernet').' ('.$dev->etherdev_max.' ports)' :
t('Ethernet'),
'#attributes' => array('class'=>"model-item"),
'#collapsible' => TRUE,
'#collapsed' => ($dev->etherdev_max) ? TRUE: FALSE,
'#weight' => $form_weight++,
);
$form['ethernet']['etherdev_max'] = array(
'#type' => 'textfield',
'#title' => t('Ethernet Ports'),
'#required' => TRUE,
'#default_value' => ($dev->etherdev_max) ? ($dev->etherdev_max) : 0,
'#size' => 2,
'#maxlength' => 2,
'#description' => t('# of ethernet ports<br>on this device.'),
'#weight' => $form_weight++,
);
$form['ethernet']['interfaces'] = array(
'#type' => 'textfield',
'#title' => t('Interfaces'),
'#required' => FALSE,
'#default_value' => $dev->interfaces,
'#size' => 80,
'#maxlength' => 240,
'#description' => t('Device interface names for this device model.<br>Use | to split de the names, ex: p1|p2|p3.... Default is port# (1|2|3...|max)'),
'#weight' => $form_weight++,
);
$form['fiber'] = array(
'#type' => 'fieldset',
'#access' => in_array('fiber',$dev->arr_model_class),
'#title' => ($dev->optoports_max) ?
t('Fiber Optics').' ('.$dev->optoports_max.' ports)' :
t('Fiber Optics'),
'#attributes' => array('class'=>"model-item"),
'#collapsible' => TRUE,
'#collapsed' => ($dev->optoports_max) ? TRUE : FALSE,
'#weight' => $form_weight++,
);
$form['fiber']['optoports_max'] = array(
'#type' => 'textfield',
'#access' => in_array('fiber',$dev->arr_model_class),
'#title' => t('Optical ports'),
'#required' => FALSE,
'#default_value' => $dev->optoports_max,
'#size' => 2,
'#maxlength' => 2,
'#description' => t('# of optical ports<br>on this device.'),
'#weight' => $form_weight++,
);
$form['fiber']['opto_interfaces'] = array(
'#type' => 'textfield',
'#access' => in_array('fiber',$dev->arr_model_class),
'#title' => t('Optical Interfaces'),
'#required' => FALSE,
'#default_value' => $dev->opto_interfaces,
'#size' => 80,
'#maxlength' => 240,
'#description' => t('Port numbers with SFP slot<br>Use | to split de the numbers (i.e. 21|22|23|24)<br>Use same names as ethernet for shared ports'),
'#weight' => $form_weight++,
);
$form['wireless'] = array(
'#type' => 'fieldset',
'#access' => in_array('wireless',$dev->arr_model_class),
'#title' => ($dev->radiodev_max) ?
t('Wireless').' ('.$dev->radiodev_max.' ports)' :
t('Wireless'),
'#attributes' => array('class'=>"model-item"),
'#collapsible' => TRUE,
'#collapsed' => ($dev->radiodev_max) ? TRUE : FALSE,
'#weight' => $form_weight++,
);
$form['wireless']['radiodev_max'] = array(
'#type' => 'textfield',
'#access' => in_array('wireless',$dev->arr_model_class),
'#title' => t('Max Radios'),
'#required' => TRUE,
'#default_value' => $dev->radiodev_max,
'#size' => 2,
'#maxlength' => 2,
'#description' => t('Maximum number of radios<br>that can handle this device.'),
'#weight' => $form_weight++,
);
$form['wireless']['winterfaces'] = array(
'#type' => 'textfield',
'#title' => t('Wireless Interfaces'),
'#required' => FALSE,
'#default_value' => $dev->winterfaces,
'#size' => 80,
'#maxlength' => 240,
'#description' => t('Device Wireless interface names for this device model.<br>Use | to split de the names, ex: wlan1|wlan2|wlan3.... Default is port# (1|2|3...|max)'),
'#weight' => $form_weight++,
);
$form['wireless']['AP'] = array(
'#type' => 'select',
'#access' => in_array('wireless',$dev->arr_model_class),
'#title' => t('Acces Point'),
'#required' => TRUE,
'#default_value' => $dev->AP,
'#options' => array('Yes' => t('Yes'), 'No' => t("No")),
'#description' => t('Select yes if this device<br>can be an Access Point.'),
'#weight' => $form_weight++,
);
$form['wireless']['virtualAP'] = array(
'#type' => 'select',
'#access' => in_array('wireless',$dev->arr_model_class),
'#title' => t('HostPot / Vlan'),
'#required' => TRUE,
'#default_value' => $dev->virtualAP,
'#options' => array('Yes' => t('Yes'), 'No' => t("No")),
'#description' => t('Select yes if this device<br>can be a Hostpot or can create vlans.'),
'#weight' => $form_weight++,
);
$form['wireless']['client'] = array(
'#type' => 'select',
'#access' => in_array('wireless',$dev->arr_model_class),
'#title' => t('Statiton capable'),
'#required' => TRUE,
'#options' => array('Yes' => t('Yes'), 'No' => t("No")),
'#default_value' => $dev->client,
'#description' => t('Select yes if this device<br>can be a station.'),
'#weight' => $form_weight++,
);
$form['firmware'] = array(
'#type' => 'fieldset',
'#access' => in_array('wireless' ,$dev->arr_model_class) || in_array('router',$dev->arr_model_class),
'#title' => t('Firmware'),
'#attributes' => array('class'=>"model-item"),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#weight' => $form_weight++,
);
$form['firmware']['supported'] = array(
'#type' => 'select',
'#access' => in_array('wireless' ,$dev->arr_model_class) || in_array('router',$dev->arr_model_class),
'#title' => t('Supported'),
'#required' => TRUE,
'#options' => array('Yes' => t('Yes'), 'Deprecated' => t("Deprecated")),
'#default_value' => $dev->supported,
'#description' => t('Deprecated devices does not have any support and no appear on the device list select form.'),
'#prefix' => '<td>',
'#suffix' => '</td></tr></table>',
'#weight' => $form_weight++,
);
$query = db_query("select
usc.id, usc.mid, usc.fid, f.id as firmware_id, f.nom
from
guifi_firmware f
left join
guifi_configuracioUnSolclic usc ON usc.fid = f.id and usc.mid = %d order by nom asc", $devid);
while ($firmwares = db_fetch_array($query)) {
//echo "<hr>firmwares[fid]=". $firmwares["fid"] ."firmwares[mid]=". $firmwares["mid"]. " firmwares[nom]=". $firmwares["nom"];
//echo "<br>firmwares[fid]=". firmwares["fid"];
if ($firmwares["mid"]==$devid)
$firms_compatibles[$firmwares["firmware_id"]] = $firmwares["nom"];
else
$firms_tots[$firmwares["firmware_id"]] = $firmwares["nom"];
}
$form['firmware']['firmwaresCompatibles'] = array(
'#type' => 'select',
'#access' => in_array('wireless' ,$dev->arr_model_class) || in_array('router',$dev->arr_model_class),
'#title' => t('firmwares compatibles'),
'#default_value' => 0,
'#options' => $firms_compatibles,
'#description' => t('firmwares compatibles amb aquest model.'),
'#size' => 10,
'#multiple' => true,
'#required' => false,
'#validated' => true,
'#prefix' => '<tr><td class="mselects" align="left" colspan="2"><table style="width:575px"><tr><td style="width:250px">',
'#suffix' => '</td><td style="width:50px">',
'#weight' => $form_weight++,
'#attributes'=>array('style'=>'width:250px;height:350px')
);
$disponiblesButtonOne = '<input type="button" value=">" id="associatsButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
$disponiblesButtonAll = '<input type="button" value=">>" id="associatsButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
$associatsButtonOne = '<input type="button" value="<" id="disponiblesButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
$associatsButtonAll = '<input type="button" value="<<" id="disponiblesButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
$botons = $disponiblesButtonOne.'<br>';
$botons .= $disponiblesButtonAll.'<br>';
$botons .= $associatsButtonOne.'<br>';
$botons .= $associatsButtonAll.'<br>';
$form['firmware']['firmwaresTots'] = array(
'#type' => 'select',
'#access' => in_array('wireless' ,$dev->arr_model_class) || in_array('router',$dev->arr_model_class),
'#title' => t('Tots els firmwares'),
'#default_value' => 0,
'#options' => $firms_tots,
'#description' => t('Tots els firmwares.'),
'#size' => 10,
'#multiple' => true,
'#required' => false,
'#validated' => true,
'#prefix' => $botons. '</td><td style="width:250px">',
'#suffix' => '</td></tr></table></td></tr>',
'#weight' => $form_weight++,
'#attributes'=>array('style'=>'width:250px;height:350px')
);
return $form;
}
function guifi_devel_devices_form_submit($form, &$form_state) {
guifi_log(GUIFILOG_TRACE,'function guifi_devel_devices_form_submit()',$form_state['values']);
if (isset($form_state['values']['new']))
$form_state['values']['etherdev_max'] = 0;
$id = guifi_devel_devices_save($form_state['values']);
if ($form_state['values']['op']==t('Save & continue edit'))
drupal_goto('guifi/menu/devel/device/'.$id.'/edit');
else
drupal_goto('guifi/menu/devel/device');
return;
}
function guifi_devel_devices_duplicate_form_submit($form, &$form_state) {
guifi_log(GUIFILOG_TRACE,'function guifi_devel_devices_duplicate_form_submit()',$form_state);
$originalmid = $form_state['values']['originalmid'];
$sql = db_query('SELECT * FROM {guifi_model_specs} WHERE mid = %d', $originalmid);
$originaldev = db_fetch_object($sql);
foreach($originaldev as $property => $value) {
// el nom del model no el volem duplicar
if ($property!='model') $form_state['values'][$property] = $value;
}
// eliminem els camps addicionals del control de formularis
unset($form_state['values']['originalmid']);
unset($form_state['values']['op']);
unset($form_state['values']['submit']);
unset($form_state['values']['form_build_id']);
unset($form_state['values']['form_token']);
unset($form_state['values']['form_id']);
// recuperar els firmwares suportats del model original
$sql= db_query("SELECT distinct(fid) FROM {guifi_configuracioUnSolclic} WHERE mid = %d order by fid asc", $originalmid);
while ($originalFirms = db_fetch_object($sql)) {
$form_state['values']['firmwaresCompatibles'][$originalFirms->fid] = $originalFirms->fid;
}
// desar el nou device
guifi_devel_devices_save($form_state['values'], $originalmid);
drupal_goto('guifi/menu/devel/device');
return;
}
// El parametre OPCIONAL $originalmid serveix per si estem copiant un model , poder aplicar al nou model algunes de les seves propietats
function guifi_devel_devices_save($edit, $originalmid=null) {
global $user;
$edit['model_class'] = implode('|',$edit['arr_model_class']);
$to_mail = $edit['notification'];
$log ='';
guifi_log(GUIFILOG_TRACE,'function guifi_devel_devices_save()',$edit);
// guardem primer perque si vinc de un insert poder tenir el id i operar amb els camps relacionats
$edit2 = _guifi_db_sql('guifi_model_specs',array('mid' => $edit['mid']),$edit,$log,$to_mail);
// si estic fent un model nou, copia de $originalmid vull qeu la consulta dels firmwares es basi en les de l'original
$midFirms = $edit2['mid'];
if ($originalmid){
$midFirms = $originalmid;
}
// recollida de parametresFirmware actuals
$sql= db_query("SELECT distinct(fid), plantilla FROM {guifi_configuracioUnSolclic} WHERE mid = %d order by fid asc", $midFirms);
while ($oldFirms = db_fetch_object($sql)) {
$alreadyPresent[] = $oldFirms->fid;
$plantilles[$oldFirms->fid] = $oldFirms->plantilla;
}
// recollida de firmwares compatibles
if (isset($edit['firmwaresCompatibles'])){
// de tots els que em passen, mirar si ja els tenia a la BD
foreach ($edit['firmwaresCompatibles'] as $firmware) {
// si ja el teniem abans no l'insertem, pero si estem fent una copia aleshores si (quan $originalmid != null)
if (!in_array($firmware, $alreadyPresent)||$originalmid) {
$params = array(
'mid' => $edit2['mid'],
'fid'=> $firmware,
'notification' => $edit['notification'],
'plantilla' => unsolclicDefaultTemplate($edit2['model'], $firmwareName),
'enabled' => 0,
'new' => true
);
// per copiar el valor de la plantilla origen 'planitlla' => $plantilles[$firmware]
// insertem una nova configuracio USC
$params = _guifi_db_sql('guifi_configuracioUnSolclic',array('mid' => $params['mid']),$params,$log,$to_mail);
// TODO si fem el params = de sobre aleshores no cal tornar a el ultim mid, ja em ve del insert!
// recuperem el id del uscid que acabem de crear
$uscid = db_fetch_array(db_query("SELECT max(id) mid FROM {guifi_configuracioUnSolclic} "));
// aqui cal agafar tots els parametres del firmware i entrarlos a la taula guifi_parametresConfiguracioUnsolclic
crearParametresConfiguracioUSC($uscid['mid'], $firmware, $to_mail, $user->id);
}
// guardem els firmwares que hem afegit
$kept[] = $firmware;
}
// de tots els que tenia a la BD, mirar si me'ls han tret i esborrar-los
foreach ($alreadyPresent as $firmware) {
if (!in_array($firmware, $edit['firmwaresCompatibles'])) {
// IMPORTANT abans de esborrar comprovar que no tinguin configuracions USC validades
$sql = db_query('SELECT id as uscid, enabled FROM {guifi_configuracioUnSolclic} WHERE mid=%d and fid=%d ', $edit['mid'], $firmware);
$configuracions = db_fetch_object($sql);
// si la configuracion USC no esta enabled la borrem
if (!$configuracions->enabled) {
// si esborrem la configuracio USC tambe hauriem d'esborrarli els parametres associats
db_query("DELETE FROM {guifi_configuracioUnSolclic} WHERE mid=%d and fid=%d ", $edit['mid'], $firmware);
// si esborrem la configuracio USC tambe hauriem d'esborrarli els parametres associats
db_query("DELETE FROM {guifi_parametresConfiguracioUnsolclic} WHERE uscid=%d", $configuracions->uscid);
$deleted[] = $firmware;
} else {
// si la configuracio USC estava enabled la desem per notificar que no s'ha esobrrat
$kept[] = $firmware;
}
}
}
if (count($kept)>0) {
$guardats = implode(', ', $kept);
$strGuardats = ' Firmwares guardats '. $guardats;
}
if (count($deleted)>0) {
$borrats = implode(', ', $deleted);
$strBorrats = ' Firmwares borrats '. $borrats;
}
}
drupal_set_message( 'Model Actualitzat : '. $edit['model']);
guifi_notify(
$to_mail,
t('The device model !device has been created / updated by !user.',array('!device' => $edit['model'], '!user' => $user->name)),
$log);
return $edit2['mid'];
}
function guifi_devel_devices_delete_confirm($form_state,$mid) {
guifi_log(GUIFILOG_TRACE,'guifi_devel_device_delete_confirm()',$mid);
$form['mid'] = array('#type' => 'hidden', '#value' => $mid);
$qry= db_fetch_object(db_query("SELECT model FROM {guifi_model_specs} WHERE mid = %d", $mid));
return confirm_form(
$form,
t('Are you sure you want to delete the device model " %model "?',
array('%model' => $qry->model)),
'guifi/menu/devel/device',
t('This action cannot be undone.'),
t('Delete'),
t('Cancel'));
}
function guifi_devel_devices_delete_confirm_submit($form, &$form_state) {
global $user;
$depth = 0;
if ($form_state['values']['op'] != t('Delete'))
return;
$to_mail = explode(',',$node->notification);
$log = _guifi_db_delete('guifi_model_specs',array('mid' => $form_state['values']['mid']),$to_mail,$depth);
drupal_set_message($log);
guifi_notify(
$to_mail,
t('The device model %name has been DELETED by %user.',array('%name' => $form_state['values']['model'], '%user' => $user->name)),
$log);
drupal_goto('guifi/menu/devel/device');
}
// Device Firmwares output
function guifi_devel_firmware($firmid=null, $op=null) {
switch($firmid) {
case 'add':
$firmid = 'New';
$jquery1 = HelperMultipleSelect('guifi-devel-firmware-form', 'parametres-associats', 'parametres-disponibles');
drupal_add_js("if (Drupal.jsEnabled) { $jquery1 }", 'inline');
return drupal_get_form('guifi_devel_firmware_form',$firmid);
}
switch($op) {
case 'edit':
$jquery1 = HelperMultipleSelect('guifi-devel-firmware-form', 'parametres-associats', 'parametres-disponibles');
drupal_add_js("if (Drupal.jsEnabled) { $jquery1 }", 'inline');
$sortida = drupal_get_form('guifi_devel_firmware_form',$firmid);
return $sortida;
case 'delete':
guifi_log(GUIFILOG_TRACE,'guifi_devel_firmware_delete()',$firmid);
return drupal_get_form(
'guifi_devel_firmware_delete_confirm', $firmid);
guifi_devel_firmware_delete($firmid);
}
$rows = array();
$value = t('Add a new firmware');
$output = '<from>';
$output .= '<input type="button" id="button" value="'.$value.'" onclick="location.href=\'/guifi/menu/devel/firmware/add\'"/>';
$output .= '</form>';
$headers = array(t('Id'), t('Name'), t('Description'), t('Enabled'), t('Manages'), t('#USC'),
array('data'=>t('Operations'),'colspan'=>'2')); //, t('Edit'), t('Delete'));
$sql= db_query('select
f.id, f.nom, f.descripcio, f.relations, f.enabled, f.managed,
count(usc.fid) as enabledUSC
from
{guifi_firmware{ f
left join {guifi_configuracioUnSolclic} usc on usc.fid = f.id and usc.enabled = 1
group by f.id, f.nom, f.descripcio, f.relations, f.enabled
order by enabled desc ,nom asc');
while ($firmware = db_fetch_object($sql)) {
($firmware->enabled) ? $enabled='Enabled' : $enabled='Disabled';
$rows[] = array($firmware->id,
$firmware->nom,
$firmware->descripcio,
array('data'=>t($enabled),'class'=>$enabled),
str_replace('|',', ',$firmware->managed),
$firmware->enabledUSC,
l(guifi_img_icon('edit.png'),'guifi/menu/devel/firmware/'.$firmware->id.'/edit',
array(
'html' => TRUE,
'attributes'=>array('title' => t('edit firmware')),
)),
l(guifi_img_icon('drop.png'),'guifi/menu/devel/firmware/'.$firmware->id.'/delete',
array(
'html' => TRUE,
'attributes'=>array('title' => t('delete firmware')),
)));
}
$output .= theme('table',$headers,$rows,array('class'=>'device-data'));
print theme('page',$output, FALSE);
return;
}
// Firmwares Form
function guifi_devel_firmware_form($form_state, $firmid) {
global $user;
$firmware = guifi_get_firmware($firmid);
if ($firmid == 'New' ) {
$form['new'] = array('#type' => 'hidden', '#value' => TRUE);
} else {
$form['id'] = array('#type' => 'hidden','#value' => $firmid);
}
$form['relations'] = array('#type' => 'hidden', '#value' => $firmware->relations);
$form['nom'] = array(
'#type' => 'textfield',
'#title' => t('Firmware short name'),
'#required' => TRUE,
'#default_value' => $firmware->nom,
'#size' => 32,
'#maxlength' => 32,
'#description' => t('The firmware name, please, use a clear and short name. ex: "FirmwarevXX" where XX = version'),
);
$form['managed'] = array(
'#type' => 'checkboxes',
'#title' => t('Manageability'),
'#default_value' => $firmware->managed,
'#description' => t('Capabilities'),
'#options'=> array(
'vlans' => t('vlans'),
'aggregations'=>t('aggregations'),
'tunnels'=>t('tunnels')
),
);
$form['enabled'] = array(
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#default_value' => $firmware->enabled,
'#description' => t('Check if firmware is avialable for use'),
);
$form['notification'] = array(
'#type' => 'textfield',
'#size' => 60,
'#maxlength' => 1024,
'#title' => t('contact'),
'#required' => TRUE,
'#element_validate' => array('guifi_emails_validate'),
'#default_value' => (empty($firmware->notification)) ?
$user->mail : $firmware->notification,
'#description' => t('Mailid where changes on the device will be notified, if many, separated by \',\'<br />used for network administration.'),
);
$form['descripcio'] = array(
'#type' => 'textarea',
'#title' => t('Firmware Description'),
'#required' => TRUE,
'#default_value' => $firmware->descripcio,
'#size' => 64,
'#maxlength' => 64,
'#description' => t('The firmware description, please, use a clear and short description. ex: "FirmwarevXX from creator"'),
);
$query = db_query(" select
pf.fid, pf.pid, p.id, p.nom
from
guifi_parametres p
left join
guifi_parametresFirmware pf ON pf.pid = p.id and pf.fid = %d
order by p.nom asc",$firmid);
while ($parametres = db_fetch_array($query)) {
if ($parametres["pid"])
$params_associats[$parametres["pid"]] = $parametres["nom"];
else
$params_disponibles[$parametres["id"]] = $parametres["nom"];
}
$form['parametres_associats'] = array(
'#type' => 'select',
'#title' => t('Parametres associats'),
'#default_value' => 0,
'#options' => $params_associats,
'#description' => t('Parametres associats a la definició d\'aquest firmware.'),
'#size' => 10,
'#multiple' => true,
'#required' => false,
'#validated' => true,
'#prefix' => '<table style="width:575px"><tr><td style="width:250px">',
'#suffix' => '</td><td style="width:50px">',
'#weight' => $form_weight++,
'#attributes'=>array('style'=>'width:250px;height:350px')
);
$disponiblesButtonOne = '<input type="button" value=">" id="associatsButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
$disponiblesButtonAll = '<input type="button" value=">>" id="associatsButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
$associatsButtonOne = '<input type="button" value="<" id="disponiblesButtonOne" class="selectButtons" style="width:40px;margin:5px 0;">';
$associatsButtonAll = '<input type="button" value="<<" id="disponiblesButtonAll" class="selectButtons" style="width:40px;margin:5px 0;">';
$botons = $disponiblesButtonOne.'<br>';
$botons .= $disponiblesButtonAll.'<br>';
$botons .= $associatsButtonOne.'<br>';
$botons .= $associatsButtonAll.'<br>';
$form['parametres_disponibles'] = array(
'#type' => 'select',
'#title' => t('Parametres disponibles'),
'#default_value' => 0,
'#options' => $params_disponibles,
'#description' => t('Parametres disponibles per a definir aquest firmware'),
'#size' => 10,
'#multiple' => true,
'#required' => false,
'#validated' => true,
'#prefix' => $botons. '</td><td>',
'#suffix' => '</td></tr></table>',
'#weight' => $form_weight++,
'#attributes'=>array('style'=>'width:250px;height:350px')
);
$form['submit'] = array(
'#type' => 'submit',
'#weight' => 99, '#value' => t('Save')
);
//$form['submit'] = array('#type' => 'submit', '#weight' => $form_weight, '#value' => t('Save'));
return $form;
}
function guifi_devel_firmware_form_submit($form, &$form_state) {
guifi_log(GUIFILOG_TRACE,'function guifi_devel_firmware_form_submit()',$form_state);
guifi_devel_firmware_save($form_state['values']);
drupal_goto('guifi/menu/devel/firmware');
return;
}
function guifi_devel_firmware_save($edit) {
global $user;
$to_mail = $user->mail;