Improve LaTeX
[misc/hallinta-metro] / abteilung.php
1 <?php
2
3 JavaScript::instance()->add("Hallinta.closeDialogAfterInsert = false;");
4 JavaScript::instance()->add("Hallinta.closeDialogAfterSave = false;");
5
6 $jscode = <<<EOC
7 function move_callback(data)
8 {
9     grid_update(Hallinta.grid);
10 }
11
12 function move_up(id)
13 {
14     ajax_request('function', 'callback=up&id='+id, move_callback);
15 }
16
17 function move_down(id)
18 {
19     ajax_request('function', 'callback=down&id='+id, move_callback);
20 }
21 EOC;
22 JavaScript::instance()->add($jscode);
23
24 $mask = array(
25               'table' => 'metro_abteilung',
26               'title' => 'Abteilungen',
27               'sort' => 1,
28               'list' => array(
29                               'id' => array(
30                                             'name' => 'ID',
31                                             'visible' => false,
32                                             ),
33                               'sort' => array(
34                                             'name' => 'Sort',
35                                             'width' => 50,
36                                             ),
37                               'gang' => array(
38                                             'name' => 'Gang',
39                                             'filter' => 't1',
40                                             'width' => 50,
41                                             ),
42                               'name' => array(
43                                             'name' => 'Name',
44                                             'filter' => 't',
45                                             'width' => 200,
46                                             ),
47                               'up' => array(
48                                             'name' => 'Up',
49                                             'width' => 25,
50                                             'specs' => array('ClassName' => 'aligncenter', 'canSort' => false),
51                                             'control' => "new Rico.TableColumn.link('javascript:move_up({0})')",
52                                             'sql' => "'<img src=\"masks/metro/up.png\" title=\"Move up Abteilung from this on\">'",
53                                             ),
54                               'down' => array(
55                                             'name' => 'Dn',
56                                             'width' => 25,
57                                             'specs' => array('ClassName' => 'aligncenter', 'canSort' => false),
58                                             'control' => "new Rico.TableColumn.link('javascript:move_down({0})')",
59                                             'sql' => "'<img src=\"masks/metro/down.png\" title=\"Move down Abteilung from this on\">'",
60                                             ),
61                               ),
62               'edit' => array(
63                               'sort' => array(
64                                             'name' => 'Sortierung',
65                                             'type' => 'text',
66                                             'size' => 5,
67                                             'null' => true,
68                                             ),
69                               'gang' => array(
70                                             'name' => 'Gang',
71                                             'type' => 'text',
72                                             'size' => 5,
73                                             'required' => true,
74                                             ),
75                               'name' => array(
76                                             'name' => 'Name',
77                                             'type' => 'text',
78                                             'size' => 25,
79                                             'required' => true,
80                                             ),
81                               ),
82               'callbacks' => array(
83                                    'up' => cb_up,
84                                    'down' => cb_down,
85                                 ),
86               );
87
88 function cb_up()
89 {
90   global $db;
91
92   $sql = sprintf("UPDATE metro_abteilung SET sort = sort-1 WHERE sort >= (SELECT sort FROM metro_abteilung WHERE id = %d)",
93                  $_POST['id']);
94   $db->query($sql);
95 }
96
97 function cb_down()
98 {
99   global $db;
100
101   $sql = sprintf("UPDATE metro_abteilung SET sort = sort+1 WHERE sort >= (SELECT sort FROM metro_abteilung WHERE id = %d)",
102                  $_POST['id']);
103   $db->query($sql);
104 }