Contents of /mcore-src/trunk/mcore-tools/src/modules/lprng/printing.control.class.in
Parent Directory | Revision Log
Revision 2875 -
(show annotations)
(download)
Fri Aug 14 08:44:14 2020 UTC (4 years, 1 month ago) by niro
File size: 2009 byte(s)
Fri Aug 14 08:44:14 2020 UTC (4 years, 1 month ago) by niro
File size: 2009 byte(s)
-fixed broken table evaluation
1 | # $Id$ |
2 | |
3 | push_config 80_printing_printer |
4 | |
5 | help_printing_printer() |
6 | { |
7 | local serial="${CLASS_ARGV[0]}" |
8 | control_client "${serial}" help printing.printer |
9 | } |
10 | |
11 | set_printing_printer() |
12 | { |
13 | local serial="${CLASS_ARGV[0]}" |
14 | local action="${CLASS_ARGV[1]}" |
15 | local name="${CLASS_ARGV[2]}" |
16 | local port="${CLASS_ARGV[3]}" |
17 | # local ip="${CLASS_ARGV[4]}" |
18 | # local share="${CLASS_ARGV[5]}" |
19 | |
20 | case "${action}" in |
21 | add) enabled=1 ;; |
22 | del) enabled=0 ;; |
23 | *) |
24 | eecho "Unknown action '${action}'" |
25 | return 1 |
26 | ;; |
27 | esac |
28 | |
29 | if [[ -z ${name} ]] |
30 | then |
31 | eecho "No name given" |
32 | return 1 |
33 | fi |
34 | |
35 | id=$(mysqldo "select id from cfg_printers where serial='${serial}' and printer_name='${name}';") |
36 | if [[ -n ${id} ]] |
37 | then |
38 | mysqldo "update cfg_printers set printer_name='${name}', port='${port}',enabled='${enabled}' where id=${id};" |
39 | else |
40 | mysqldo "insert into cfg_printers(serial,printer_name,port,enabled) values('${serial}','${name}','${port}','${enabled}');" |
41 | fi |
42 | } |
43 | |
44 | control_printing_printer() |
45 | { |
46 | local serial="${CLASS_ARGV[0]}" |
47 | push_config_80_printing_printer "${serial}" |
48 | } |
49 | |
50 | push_config_80_printing_printer() |
51 | { |
52 | local serial="$1" |
53 | local values |
54 | local id |
55 | |
56 | values=$(mysqldo "select id from cfg_printers where serial='${serial}';") |
57 | for id in ${values} |
58 | do |
59 | evaluate_table_xml cfg_printers "where id='${id}'" |
60 | if [[ -z ${cfg_printers_printer_name} ]] |
61 | then |
62 | eecho "Name must not be empty id->'${id}'" |
63 | continue |
64 | fi |
65 | if [[ -z ${cfg_printers_enabled} ]] |
66 | then |
67 | eecho "Enabled must not be empty id->'${id}'" |
68 | continue |
69 | fi |
70 | if [[ ${cfg_printers_enabled} = 1 ]] |
71 | then |
72 | control_client "${serial}" set printing.printer add "${cfg_printers_printer_name}" "${cfg_printers_port}" |
73 | elif [[ ${cfg_printers_enabled} = 0 ]] |
74 | then |
75 | control_client "${serial}" set printing.printer del "${cfg_printers_printer_name}" |
76 | # remove from database too |
77 | mysqldo "delete from cfg_printers where id='${id}';" |
78 | else |
79 | eecho "unknown enabled value id->'${id}', cfg_printers_enabled -> '${cfg_printers_enabled}'" |
80 | return 1 |
81 | fi |
82 | done |
83 | } |