]> git.ipfire.org Git - thirdparty/cups.git/blame - scripting/php/Example/phpcups.inc.php4
Load cups into easysw/current.
[thirdparty/cups.git] / scripting / php / Example / phpcups.inc.php4
CommitLineData
ef416fc2 1<?php
2/*
3 * PHP module for the Common UNIX Printing System (CUPS).
4 *
5 * Copyright 1997-2003 by Easy Software Products.
6 *
7 * These coded instructions, statements, and computer programs are the
8 * property of Easy Software Products and are protected by Federal
9 * copyright law. Distribution and use rights are outlined in the file
10 * "LICENSE.txt" which should have been included with this file. If this
11 * file is missing or damaged please contact Easy Software Products
12 * at:
13 *
14 * Attn: CUPS Licensing Information
15 * Easy Software Products
16 * 44141 Airport View Drive, Suite 204
17 * Hollywood, Maryland 20636-3111 USA
18 *
19 * Voice: (301) 373-9603
20 * EMail: cups-info@cups.org
21 * WWW: http://www.cups.org
22 *
23 * Contents:
24 *
25 * Basic CupsPrinter class. Will be extended in next release.
26 *
27 */
28if (!$INCLUDED_PHPCUPS_INC)
29{
30 $INCLUDED_PHPCUPS_INC = True;
31
32
33 class CupsPrinter
34 {
35 var $printer_name;
36 var $printer_server;
37 var $printer_instance;
38 var $is_default;
39 var $printer_options;
40 var $printer_state;
41 var $printer_state_message;
42 var $accepting_jobs;
43 var $queued_job_count;
44 var $description;
45 var $location;
46 var $printer_info;
47 var $printer_more_info;
48 var $make_and_model;
49 var $printer_uri;
50 var $device_uri;
51 var $job_quota_period;
52 var $job_k_limit;
53 var $job_page_limit;
54 var $color_supported;
55 var $pages_per_minute;
56 var $finishings_supported; // Array
57 var $finishings_default;
58 var $printer_type;
59 var $operations_supported; // Array
60 var $multiple_document_jobs_supported;
61 var $multiple_operation_time_out;
62 var $job_priority_supported_lower;
63 var $job_priority_supported_upper;
64 var $job_priority_default;
65 var $copies_supported_lower;
66 var $copies_supported_upper;
67 var $copies_default;
68 var $page_range_supported;
69 var $number_up_supported; // Array
70 var $number_up_default;
71 var $orientation_requested_supported; // Array
72 var $orientation_requested_default;
73 var $media_supported; // Array
74 var $media_default;
75
76 function CupsPrinter()
77 {
78 $this->printer_name = "";
79 $this->printer_destination = "";
80 $this->is_default = 0;
81 $this->options = Array();
82 $this->printer_state = -1;
83 $this->printer_state_message = "";
84 $this->accepting_jobs = FALSE;
85 $this->queued_job_count = 0;
86 $this->description = "";
87 $this->location = "";
88 $this->printer_info = "";
89 $this->printer_more_info = "";
90 $this->make_and_model = "";
91 $this->printer_uri_supported = Array();
92 $this->device_uri = "";
93 $this->job_quota_period = 0;
94 $this->job_k_limit = 0;
95 $this->job_page_limit = 0;
96 $this->color_supported = FALSE;
97 $this->pages_per_minute = 0;
98 $this->finishings_supported = Array();
99 $this->finishings_default = 0;
100 $this->printer_type = 0;
101 $this->operations_supported = Array();
102 $this->multiple_document_jobs_supported = FALSE;
103 $this->multiple_operation_time_out = 0;
104 $this->job_priority_supported_lower = 0;
105 $this->job_priority_supported_upper = 100;
106 $this->job_priority_default = 50;
107 $this->copies_supported_lower = 1;
108 $this->copies_supported_upper = 1;
109 $this->copies_default = 1;
110 $this->page_range_supported = FALSE;
111 $this->number_up_supported = Array();
112 $this->number_up_default = 0;
113 $this->orientation_requested_supported = Array();
114 $this->orientation_requested_default = 3;
115 $this->media_supported = Array();
116 $this->media_default = "";
117
118 } // End of constructor
119
120
121 //
122 // Get the attributes
123 //
124 function getAttributes()
125 {
126 $o_arr = cups_get_dest_options($this->printer_server,
127 $this->printer_name,
128 $this->printer_instance);
129 $this->printer_options = $o_arr;
130
131 $attrs = cups_get_printer_attributes( "localhost", $this->printer_name );
132 while ($obj = current($attrs))
133 {
134 next($attrs);
135
136 if ($obj->name == "printer-state")
137 {
138 $this->printer_state = $obj->value;
139 }
140 else if ($obj->name == "printer-state-message")
141 {
142 $this->printer_state_message = $obj->value;
143 }
144 else if ($obj->name == "printer-location")
145 {
146 $this->location = $obj->value;
147 }
148 else if ($obj->name == "printer-make-and-model")
149 {
150 $this->description = $obj->value;
151 }
152 else if ($obj->name == "printer-uri-supported")
153 {
154 $this->printer_uri_supported[$obj->value] = $obj->value;
155 }
156 else if ($obj->name == "device-uri")
157 {
158 $this->device_uri = $obj->value;
159 }
160 else if ($obj->name == "queued-job-count")
161 {
162 $this->queued_job_count = $obj->value;
163 }
164 else if ($obj->name == "printer-is-accepting-jobs")
165 {
166 $this->accepting_jobs = $obj->value ? TRUE : FALSE;
167 }
168 else if ($obj->name == "color-supported")
169 {
170 $this->color_supported = $obj->value ? TRUE : FALSE;
171 }
172 else if ($obj->name == "pages-per-minute")
173 {
174 $this->pages_per_minute = $obj->value;
175 }
176 else if ($obj->name == "operations-supported")
177 {
178 $this->operations_supported["O$obj->value"] = $obj->value;
179 }
180 else if ($obj->name == "orientation-requested-supported")
181 {
182 $this->orientation_requested_supported["O$obj->value"] = $obj->value;
183 }
184 else if ($obj->name == "orientation-requested-default")
185 {
186 $this->orientation_requested_default = $obj->value;
187 }
188 else if ($obj->name == "finishings-supported")
189 {
190 $this->finishings_supported["F$obj->value"] = $obj->value;
191 }
192 else if ($obj->name == "finishings-default")
193 {
194 $this->finishings_default = $obj->value;
195 }
196 else if ($obj->name == "number-up-supported")
197 {
198 $this->number_up_supported["N$obj->value"] = $obj->value;
199 }
200 else if ($obj->name == "number-up-default")
201 {
202 $this->number_up_default = $obj->value;
203 }
204 else if ($obj->name == "printer-type")
205 {
206 $this->printer_type = $obj->value;
207 }
208 else if ($obj->name == "multiple-document-jobs-suppoted")
209 {
210 $this->multiple_document_jobs_supported = $obj->value ? TRUE : FALSE;
211 }
212 else if ($obj->name == "multiple-operation-time-out")
213 {
214 $this->multiple_operation_time_out = $obj->value;
215 }
216 else if ($obj->name == "job-priority-supported")
217 {
218 $this->job_priority_supported_upper = $obj->value;
219 }
220 else if ($obj->name == "job-priority-default")
221 {
222 $this->job_priority_default = $obj->value;
223 }
224 else if ($obj->name == "copies-supported")
225 {
226 $tmpa = explode("-",$obj->value);
227 if (count($tmpa) > 1)
228 {
229 $this->copies_supported_lower = $tmpa[0];
230 $this->copies_supported_upper = $tmpa[1];
231 }
232 else if (count($tmpa) == 1)
233 {
234 $this->copies_supported_lower = $tmpa[0];
235 $this->copies_supported_upper = $tmpa[0];
236 }
237 }
238 else if ($obj->name == "copies-default")
239 {
240 $this->copies_supported_default = $obj->value;
241 }
242 else if ($obj->name == "page-ranges-supported")
243 {
244 $this->page_ranges_supported = $obj->value ? TRUE : FALSE;
245 }
246 else if ($obj->name == "media-default")
247 {
248 $this->media_default = $obj->value;
249 }
250 else if ($obj->name == "media-supported")
251 {
252 $this->media_supported[$obj->value] = $obj->value;
253 }
254
255 } // while
256
257 } // End of getAttributes
258
259
260 } // End of CupsPrinter class
261
262
263
264
265 //
266 // Get the printer / destination list.
267 //
268 function phpcups_getDestList()
269 {
270 $return_value = Array();
271
272 //
273 // Get the destination objects array.
274 //
275 $p_arr = cups_get_dest_list();
276
277 if (!IS_ARRAY($p_arr))
278 {
279 return(NULL);
280 }
281
282 reset($p_arr);
283
284 while ($p_obj = current($p_arr))
285 {
286 next($p_arr);
287
288 //
289 // Get the options for the current destination.
290 //
291 $o_arr = cups_get_dest_options("localhost",$p_obj->name,$p_obj->instance);
292
293 $p = new CupsPrinter();
294 $p->printer_name = $p_obj->name;
295 $p->printer_instance = $p_obj->instance;
296 $p->is_default = $p_obj->is_default;
297 $p->printer_options = $o_arr;
298 $p->getAttributes();
299
300 $return_value[$p->printer_name] = $p;
301 }
302 return($return_value);
303
304 } // End of phpcups_getDestList()
305
306
307
308
309} // if included.
310?>