Completed
Branch develop (c24f26)
by
unknown
26:13
created
htdocs/includes/restler/framework/Luracast/Restler/HumanReadableCache.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -14,116 +14,116 @@
 block discarded – undo
14 14
  */
15 15
 class HumanReadableCache implements iCache
16 16
 {
17
-    /**
18
-     * @var string path of the folder to hold cache files
19
-     */
20
-    public static $cacheDir;
17
+	/**
18
+	 * @var string path of the folder to hold cache files
19
+	 */
20
+	public static $cacheDir;
21 21
 
22
-    public function __construct()
23
-    {
24
-        if (is_null(self::$cacheDir)) {
25
-            self::$cacheDir = Defaults::$cacheDirectory;
26
-        }
27
-    }
22
+	public function __construct()
23
+	{
24
+		if (is_null(self::$cacheDir)) {
25
+			self::$cacheDir = Defaults::$cacheDirectory;
26
+		}
27
+	}
28 28
 
29
-    /**
30
-     * store data in the cache
31
-     *
32
-     * @param string $name
33
-     * @param mixed  $data
34
-     *
35
-     * @throws \Exception
36
-     * @return boolean true if successful
37
-     */
38
-    public function set($name, $data)
39
-    {
40
-        if (is_array($data)) {
41
-            $s = '$o = array();' . PHP_EOL . PHP_EOL;
42
-            $s .= '// ** THIS IS AN AUTO GENERATED FILE.'
43
-                . ' DO NOT EDIT MANUALLY ** ';
44
-            foreach ($data as $key => $value) {
45
-                $s .= PHP_EOL . PHP_EOL .
46
-                    "//==================== $key ===================="
47
-                    . PHP_EOL . PHP_EOL;
48
-                if (is_array($value)) {
49
-                    $s .= '$o[\'' . $key . '\'] = array();';
50
-                    foreach ($value as $ke => $va) {
51
-                        $s .= PHP_EOL . PHP_EOL . "//==== $key $ke ===="
52
-                            . PHP_EOL . PHP_EOL;
53
-                        $s .= '$o[\'' . $key . '\'][\'' . $ke . '\'] = ' .
54
-                            str_replace('  ', '    ',
55
-                                var_export($va, true)) . ';';
56
-                    }
57
-                } else {
58
-                    $s .= '$o[\'' . $key . '\'] = '
59
-                        . var_export($value, true) . ';';
60
-                }
61
-            }
62
-            $s .= PHP_EOL . 'return $o;';
63
-        } else {
64
-            $s = 'return ' . var_export($data, true) . ';';
65
-        }
66
-        $file = $this->_file($name);
67
-        $r = @file_put_contents($file, "<?php $s");
68
-        @chmod($file, 0777);
69
-        if ($r === false) {
70
-            $this->throwException();
71
-        }
72
-        return $r;
73
-    }
29
+	/**
30
+	 * store data in the cache
31
+	 *
32
+	 * @param string $name
33
+	 * @param mixed  $data
34
+	 *
35
+	 * @throws \Exception
36
+	 * @return boolean true if successful
37
+	 */
38
+	public function set($name, $data)
39
+	{
40
+		if (is_array($data)) {
41
+			$s = '$o = array();' . PHP_EOL . PHP_EOL;
42
+			$s .= '// ** THIS IS AN AUTO GENERATED FILE.'
43
+				. ' DO NOT EDIT MANUALLY ** ';
44
+			foreach ($data as $key => $value) {
45
+				$s .= PHP_EOL . PHP_EOL .
46
+					"//==================== $key ===================="
47
+					. PHP_EOL . PHP_EOL;
48
+				if (is_array($value)) {
49
+					$s .= '$o[\'' . $key . '\'] = array();';
50
+					foreach ($value as $ke => $va) {
51
+						$s .= PHP_EOL . PHP_EOL . "//==== $key $ke ===="
52
+							. PHP_EOL . PHP_EOL;
53
+						$s .= '$o[\'' . $key . '\'][\'' . $ke . '\'] = ' .
54
+							str_replace('  ', '    ',
55
+								var_export($va, true)) . ';';
56
+					}
57
+				} else {
58
+					$s .= '$o[\'' . $key . '\'] = '
59
+						. var_export($value, true) . ';';
60
+				}
61
+			}
62
+			$s .= PHP_EOL . 'return $o;';
63
+		} else {
64
+			$s = 'return ' . var_export($data, true) . ';';
65
+		}
66
+		$file = $this->_file($name);
67
+		$r = @file_put_contents($file, "<?php $s");
68
+		@chmod($file, 0777);
69
+		if ($r === false) {
70
+			$this->throwException();
71
+		}
72
+		return $r;
73
+	}
74 74
 
75
-    /**
76
-     * retrieve data from the cache
77
-     *
78
-     * @param string $name
79
-     * @param bool   $ignoreErrors
80
-     *
81
-     * @return mixed
82
-     */
83
-    public function get($name, $ignoreErrors = false)
84
-    {
85
-        $file = $this->_file($name);
86
-        if (file_exists($file)) {
87
-            return include($file);
88
-        }
89
-    }
75
+	/**
76
+	 * retrieve data from the cache
77
+	 *
78
+	 * @param string $name
79
+	 * @param bool   $ignoreErrors
80
+	 *
81
+	 * @return mixed
82
+	 */
83
+	public function get($name, $ignoreErrors = false)
84
+	{
85
+		$file = $this->_file($name);
86
+		if (file_exists($file)) {
87
+			return include($file);
88
+		}
89
+	}
90 90
 
91
-    /**
92
-     * delete data from the cache
93
-     *
94
-     * @param string $name
95
-     * @param bool   $ignoreErrors
96
-     *
97
-     * @return boolean true if successful
98
-     */
99
-    public function clear($name, $ignoreErrors = false)
100
-    {
101
-        return @unlink($this->_file($name));
102
-    }
91
+	/**
92
+	 * delete data from the cache
93
+	 *
94
+	 * @param string $name
95
+	 * @param bool   $ignoreErrors
96
+	 *
97
+	 * @return boolean true if successful
98
+	 */
99
+	public function clear($name, $ignoreErrors = false)
100
+	{
101
+		return @unlink($this->_file($name));
102
+	}
103 103
 
104
-    /**
105
-     * check if the given name is cached
106
-     *
107
-     * @param string $name
108
-     *
109
-     * @return boolean true if cached
110
-     */
111
-    public function isCached($name)
112
-    {
113
-        return file_exists($this->_file($name));
114
-    }
104
+	/**
105
+	 * check if the given name is cached
106
+	 *
107
+	 * @param string $name
108
+	 *
109
+	 * @return boolean true if cached
110
+	 */
111
+	public function isCached($name)
112
+	{
113
+		return file_exists($this->_file($name));
114
+	}
115 115
 
116
-    private function _file($name)
117
-    {
118
-        return self::$cacheDir . '/' . $name . '.php';
119
-    }
116
+	private function _file($name)
117
+	{
118
+		return self::$cacheDir . '/' . $name . '.php';
119
+	}
120 120
 
121
-    private function throwException()
122
-    {
123
-        throw new \Exception(
124
-            'The cache directory `'
125
-            . self::$cacheDir . '` should exist with write permission.'
126
-        );
127
-    }
121
+	private function throwException()
122
+	{
123
+		throw new \Exception(
124
+			'The cache directory `'
125
+			. self::$cacheDir . '` should exist with write permission.'
126
+		);
127
+	}
128 128
 }
129 129
 
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/Routes.php 1 patch
Indentation   +755 added lines, -755 removed lines patch added patch discarded remove patch
@@ -21,45 +21,45 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class Routes
23 23
 {
24
-    public static $prefixingParameterNames = array(
25
-        'id'
26
-    );
24
+	public static $prefixingParameterNames = array(
25
+		'id'
26
+	);
27 27
 
28
-    public static $fieldTypesByName = array(
29
-        'email'       => 'email',
30
-        'password'    => 'password',
31
-        'phone'       => 'tel',
32
-        'mobile'      => 'tel',
33
-        'tel'         => 'tel',
34
-        'search'      => 'search',
35
-        'date'        => 'date',
36
-        'created_at'  => 'datetime',
37
-        'modified_at' => 'datetime',
38
-        'url'         => 'url',
39
-        'link'        => 'url',
40
-        'href'        => 'url',
41
-        'website'     => 'url',
42
-        'color'       => 'color',
43
-        'colour'      => 'color',
44
-    );
28
+	public static $fieldTypesByName = array(
29
+		'email'       => 'email',
30
+		'password'    => 'password',
31
+		'phone'       => 'tel',
32
+		'mobile'      => 'tel',
33
+		'tel'         => 'tel',
34
+		'search'      => 'search',
35
+		'date'        => 'date',
36
+		'created_at'  => 'datetime',
37
+		'modified_at' => 'datetime',
38
+		'url'         => 'url',
39
+		'link'        => 'url',
40
+		'href'        => 'url',
41
+		'website'     => 'url',
42
+		'color'       => 'color',
43
+		'colour'      => 'color',
44
+	);
45 45
 
46
-    protected static $routes = array();
46
+	protected static $routes = array();
47 47
 
48
-    protected static $models = array();
48
+	protected static $models = array();
49 49
 
50
-    /**
51
-     * Route the public and protected methods of an Api class
52
-     *
53
-     * @param string $className
54
-     * @param string $resourcePath
55
-     * @param int    $version
56
-     *
57
-     * @throws RestException
58
-     */
59
-    public static function addAPIClass($className, $resourcePath = '', $version = 1)
60
-    {
50
+	/**
51
+	 * Route the public and protected methods of an Api class
52
+	 *
53
+	 * @param string $className
54
+	 * @param string $resourcePath
55
+	 * @param int    $version
56
+	 *
57
+	 * @throws RestException
58
+	 */
59
+	public static function addAPIClass($className, $resourcePath = '', $version = 1)
60
+	{
61 61
 
62
-        /*
62
+		/*
63 63
          * Mapping Rules
64 64
          * =============
65 65
          *
@@ -74,749 +74,749 @@  discard block
 block discarded – undo
74 74
          * - If a required parameter is not primitive type
75 75
          *      - Do not include it in URL
76 76
          */
77
-        $class = new ReflectionClass($className);
78
-        $dataName = CommentParser::$embeddedDataName;
79
-        try {
80
-            $classMetadata = CommentParser::parse($class->getDocComment());
81
-        } catch (Exception $e) {
82
-            throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
83
-        }
84
-        $classMetadata['scope'] = $scope = static::scope($class);
85
-        $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
86
-            ReflectionMethod::IS_PROTECTED);
87
-        foreach ($methods as $method) {
88
-            $methodUrl = strtolower($method->getName());
89
-            //method name should not begin with _
90
-            if ($methodUrl[0] == '_') {
91
-                continue;
92
-            }
93
-            $doc = $method->getDocComment();
77
+		$class = new ReflectionClass($className);
78
+		$dataName = CommentParser::$embeddedDataName;
79
+		try {
80
+			$classMetadata = CommentParser::parse($class->getDocComment());
81
+		} catch (Exception $e) {
82
+			throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
83
+		}
84
+		$classMetadata['scope'] = $scope = static::scope($class);
85
+		$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC +
86
+			ReflectionMethod::IS_PROTECTED);
87
+		foreach ($methods as $method) {
88
+			$methodUrl = strtolower($method->getName());
89
+			//method name should not begin with _
90
+			if ($methodUrl[0] == '_') {
91
+				continue;
92
+			}
93
+			$doc = $method->getDocComment();
94 94
 
95
-            try {
96
-                $metadata = CommentParser::parse($doc) + $classMetadata;
97
-            } catch (Exception $e) {
98
-                throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. " . $e->getMessage());
99
-            }
100
-            //@access should not be private
101
-            if (isset($metadata['access'])
102
-                && $metadata['access'] == 'private'
103
-            ) {
104
-                continue;
105
-            }
106
-            $arguments = array();
107
-            $defaults = array();
108
-            $params = $method->getParameters();
109
-            $position = 0;
110
-            $pathParams = array();
111
-            $allowAmbiguity
112
-                = (isset($metadata['smart-auto-routing'])
113
-                    && $metadata['smart-auto-routing'] != 'true')
114
-                || !Defaults::$smartAutoRouting;
115
-            $metadata['resourcePath'] = trim($resourcePath, '/');
116
-            if (isset($classMetadata['description'])) {
117
-                $metadata['classDescription'] = $classMetadata['description'];
118
-            }
119
-            if (isset($classMetadata['classLongDescription'])) {
120
-                $metadata['classLongDescription']
121
-                    = $classMetadata['longDescription'];
122
-            }
123
-            if (!isset($metadata['param'])) {
124
-                $metadata['param'] = array();
125
-            }
126
-            if (isset($metadata['return']['type'])) {
127
-                if ($qualified = Scope::resolve($metadata['return']['type'], $scope))
128
-                    list($metadata['return']['type'], $metadata['return']['children']) =
129
-                        static::getTypeAndModel(new ReflectionClass($qualified), $scope);
130
-            } else {
131
-                //assume return type is array
132
-                $metadata['return']['type'] = 'array';
133
-            }
134
-            foreach ($params as $param) {
135
-                $children = array();
136
-                $type =
137
-                    $param->isArray() ? 'array' : $param->getClass();
138
-                $arguments[$param->getName()] = $position;
139
-                $defaults[$position] = $param->isDefaultValueAvailable() ?
140
-                    $param->getDefaultValue() : null;
141
-                if (!isset($metadata['param'][$position])) {
142
-                    $metadata['param'][$position] = array();
143
-                }
144
-                $m = & $metadata ['param'] [$position];
145
-                $m ['name'] = $param->getName();
146
-                if (!isset($m[$dataName])) {
147
-                    $m[$dataName] = array();
148
-                }
149
-                $p = &$m[$dataName];
150
-                if (empty($m['label']))
151
-                    $m['label'] = Text::title($m['name']);
152
-                if (is_null($type) && isset($m['type'])) {
153
-                    $type = $m['type'];
154
-                }
155
-                if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type == 'string') {
156
-                    $p['type'] = static::$fieldTypesByName[$m['name']];
157
-                }
158
-                $m ['default'] = $defaults [$position];
159
-                $m ['required'] = !$param->isOptional();
160
-                $contentType = Util::nestedValue($p,'type');
161
-                if ($type == 'array' && $contentType && $qualified = Scope::resolve($contentType, $scope)) {
162
-                    list($p['type'], $children, $modelName) = static::getTypeAndModel(
163
-                        new ReflectionClass($qualified), $scope,
164
-                        $className . Text::title($methodUrl), $p
165
-                    );
166
-                }
167
-                if ($type instanceof ReflectionClass) {
168
-                    list($type, $children, $modelName) = static::getTypeAndModel($type, $scope,
169
-                        $className . Text::title($methodUrl), $p);
170
-                } elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
171
-                    list($type, $children, $modelName)
172
-                        = static::getTypeAndModel(new ReflectionClass($qualified), $scope,
173
-                        $className . Text::title($methodUrl), $p);
174
-                }
175
-                if (isset($type)) {
176
-                    $m['type'] = $type;
177
-                }
95
+			try {
96
+				$metadata = CommentParser::parse($doc) + $classMetadata;
97
+			} catch (Exception $e) {
98
+				throw new RestException(500, "Error while parsing comments of `{$className}::{$method->getName()}` method. " . $e->getMessage());
99
+			}
100
+			//@access should not be private
101
+			if (isset($metadata['access'])
102
+				&& $metadata['access'] == 'private'
103
+			) {
104
+				continue;
105
+			}
106
+			$arguments = array();
107
+			$defaults = array();
108
+			$params = $method->getParameters();
109
+			$position = 0;
110
+			$pathParams = array();
111
+			$allowAmbiguity
112
+				= (isset($metadata['smart-auto-routing'])
113
+					&& $metadata['smart-auto-routing'] != 'true')
114
+				|| !Defaults::$smartAutoRouting;
115
+			$metadata['resourcePath'] = trim($resourcePath, '/');
116
+			if (isset($classMetadata['description'])) {
117
+				$metadata['classDescription'] = $classMetadata['description'];
118
+			}
119
+			if (isset($classMetadata['classLongDescription'])) {
120
+				$metadata['classLongDescription']
121
+					= $classMetadata['longDescription'];
122
+			}
123
+			if (!isset($metadata['param'])) {
124
+				$metadata['param'] = array();
125
+			}
126
+			if (isset($metadata['return']['type'])) {
127
+				if ($qualified = Scope::resolve($metadata['return']['type'], $scope))
128
+					list($metadata['return']['type'], $metadata['return']['children']) =
129
+						static::getTypeAndModel(new ReflectionClass($qualified), $scope);
130
+			} else {
131
+				//assume return type is array
132
+				$metadata['return']['type'] = 'array';
133
+			}
134
+			foreach ($params as $param) {
135
+				$children = array();
136
+				$type =
137
+					$param->isArray() ? 'array' : $param->getClass();
138
+				$arguments[$param->getName()] = $position;
139
+				$defaults[$position] = $param->isDefaultValueAvailable() ?
140
+					$param->getDefaultValue() : null;
141
+				if (!isset($metadata['param'][$position])) {
142
+					$metadata['param'][$position] = array();
143
+				}
144
+				$m = & $metadata ['param'] [$position];
145
+				$m ['name'] = $param->getName();
146
+				if (!isset($m[$dataName])) {
147
+					$m[$dataName] = array();
148
+				}
149
+				$p = &$m[$dataName];
150
+				if (empty($m['label']))
151
+					$m['label'] = Text::title($m['name']);
152
+				if (is_null($type) && isset($m['type'])) {
153
+					$type = $m['type'];
154
+				}
155
+				if (isset(static::$fieldTypesByName[$m['name']]) && empty($p['type']) && $type == 'string') {
156
+					$p['type'] = static::$fieldTypesByName[$m['name']];
157
+				}
158
+				$m ['default'] = $defaults [$position];
159
+				$m ['required'] = !$param->isOptional();
160
+				$contentType = Util::nestedValue($p,'type');
161
+				if ($type == 'array' && $contentType && $qualified = Scope::resolve($contentType, $scope)) {
162
+					list($p['type'], $children, $modelName) = static::getTypeAndModel(
163
+						new ReflectionClass($qualified), $scope,
164
+						$className . Text::title($methodUrl), $p
165
+					);
166
+				}
167
+				if ($type instanceof ReflectionClass) {
168
+					list($type, $children, $modelName) = static::getTypeAndModel($type, $scope,
169
+						$className . Text::title($methodUrl), $p);
170
+				} elseif ($type && is_string($type) && $qualified = Scope::resolve($type, $scope)) {
171
+					list($type, $children, $modelName)
172
+						= static::getTypeAndModel(new ReflectionClass($qualified), $scope,
173
+						$className . Text::title($methodUrl), $p);
174
+				}
175
+				if (isset($type)) {
176
+					$m['type'] = $type;
177
+				}
178 178
 
179
-                $m['children'] = $children;
180
-                if (isset($modelName)) {
181
-                    $m['model'] = $modelName;
182
-                }
183
-                if ($m['name'] == Defaults::$fullRequestDataName) {
184
-                    $from = 'body';
185
-                    if (!isset($m['type'])) {
186
-                        $type = $m['type'] = 'array';
187
-                    }
179
+				$m['children'] = $children;
180
+				if (isset($modelName)) {
181
+					$m['model'] = $modelName;
182
+				}
183
+				if ($m['name'] == Defaults::$fullRequestDataName) {
184
+					$from = 'body';
185
+					if (!isset($m['type'])) {
186
+						$type = $m['type'] = 'array';
187
+					}
188 188
 
189
-                } elseif (isset($p['from'])) {
190
-                    $from = $p['from'];
191
-                } else {
192
-                    if ((isset($type) && Util::isObjectOrArray($type))
193
-                    ) {
194
-                        $from = 'body';
195
-                        if (!isset($type)) {
196
-                            $type = $m['type'] = 'array';
197
-                        }
198
-                    } elseif ($m['required'] && in_array($m['name'], static::$prefixingParameterNames)) {
199
-                        $from = 'path';
200
-                    } else {
201
-                        $from = 'body';
202
-                    }
203
-                }
204
-                $p['from'] = $from;
205
-                if (!isset($m['type'])) {
206
-                    $type = $m['type'] = static::type($defaults[$position]);
207
-                }
189
+				} elseif (isset($p['from'])) {
190
+					$from = $p['from'];
191
+				} else {
192
+					if ((isset($type) && Util::isObjectOrArray($type))
193
+					) {
194
+						$from = 'body';
195
+						if (!isset($type)) {
196
+							$type = $m['type'] = 'array';
197
+						}
198
+					} elseif ($m['required'] && in_array($m['name'], static::$prefixingParameterNames)) {
199
+						$from = 'path';
200
+					} else {
201
+						$from = 'body';
202
+					}
203
+				}
204
+				$p['from'] = $from;
205
+				if (!isset($m['type'])) {
206
+					$type = $m['type'] = static::type($defaults[$position]);
207
+				}
208 208
 
209
-                if ($allowAmbiguity || $from == 'path') {
210
-                    $pathParams [] = $position;
211
-                }
212
-                $position++;
213
-            }
214
-            $accessLevel = 0;
215
-            if ($method->isProtected()) {
216
-                $accessLevel = 3;
217
-            } elseif (isset($metadata['access'])) {
218
-                if ($metadata['access'] == 'protected') {
219
-                    $accessLevel = 2;
220
-                } elseif ($metadata['access'] == 'hybrid') {
221
-                    $accessLevel = 1;
222
-                }
223
-            } elseif (isset($metadata['protected'])) {
224
-                $accessLevel = 2;
225
-            }
226
-            /*
209
+				if ($allowAmbiguity || $from == 'path') {
210
+					$pathParams [] = $position;
211
+				}
212
+				$position++;
213
+			}
214
+			$accessLevel = 0;
215
+			if ($method->isProtected()) {
216
+				$accessLevel = 3;
217
+			} elseif (isset($metadata['access'])) {
218
+				if ($metadata['access'] == 'protected') {
219
+					$accessLevel = 2;
220
+				} elseif ($metadata['access'] == 'hybrid') {
221
+					$accessLevel = 1;
222
+				}
223
+			} elseif (isset($metadata['protected'])) {
224
+				$accessLevel = 2;
225
+			}
226
+			/*
227 227
             echo " access level $accessLevel for $className::"
228 228
             .$method->getName().$method->isProtected().PHP_EOL;
229 229
             */
230 230
 
231
-            // take note of the order
232
-            $call = array(
233
-                'url' => null,
234
-                'className' => $className,
235
-                'path' => rtrim($resourcePath, '/'),
236
-                'methodName' => $method->getName(),
237
-                'arguments' => $arguments,
238
-                'defaults' => $defaults,
239
-                'metadata' => $metadata,
240
-                'accessLevel' => $accessLevel,
241
-            );
242
-            // if manual route
243
-            if (preg_match_all(
244
-                '/@url\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)'
245
-                . '[ \t]*\/?(\S*)/s',
246
-                $doc, $matches, PREG_SET_ORDER
247
-            )
248
-            ) {
249
-                foreach ($matches as $match) {
250
-                    $httpMethod = $match[1];
251
-                    $url = rtrim($resourcePath . $match[2], '/');
252
-                    //deep copy the call, as it may change for each @url
253
-                    $copy = unserialize(serialize($call));
254
-                    foreach ($copy['metadata']['param'] as $i => $p) {
255
-                        $inPath =
256
-                            strpos($url, '{' . $p['name'] . '}') ||
257
-                            strpos($url, ':' . $p['name']);
258
-                        if ($inPath) {
259
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'path';
260
-                        } elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') {
261
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'query';
262
-                        } elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] == 'path') {
263
-                            $copy['metadata']['param'][$i][$dataName]['from'] = 'body';
264
-                        }
265
-                    }
266
-                    $url = preg_replace_callback('/{[^}]+}|:[^\/]+/',
267
-                        function ($matches) use ($copy) {
268
-                            $match = trim($matches[0], '{}:');
269
-                            $index = $copy['arguments'][$match];
270
-                            return '{' .
271
-                            Routes::typeChar(isset(
272
-                                $copy['metadata']['param'][$index]['type'])
273
-                                ? $copy['metadata']['param'][$index]['type']
274
-                                : null)
275
-                            . $index . '}';
276
-                        }, $url);
277
-                    static::addPath($url, $copy, $httpMethod, $version);
278
-                }
279
-                //if auto route enabled, do so
280
-            } elseif (Defaults::$autoRoutingEnabled) {
281
-                // no configuration found so use convention
282
-                if (preg_match_all(
283
-                    '/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)/i',
284
-                    $methodUrl, $matches)
285
-                ) {
286
-                    $httpMethod = strtoupper($matches[0][0]);
287
-                    $methodUrl = substr($methodUrl, strlen($httpMethod));
288
-                } else {
289
-                    $httpMethod = 'GET';
290
-                }
291
-                if ($methodUrl == 'index') {
292
-                    $methodUrl = '';
293
-                }
294
-                $url = empty($methodUrl) ? rtrim($resourcePath, '/')
295
-                    : $resourcePath . $methodUrl;
296
-                for ($position = 0; $position < count($params); $position++) {
297
-                    $from = $metadata['param'][$position][$dataName]['from'];
298
-                    if ($from == 'body' && ($httpMethod == 'GET' ||
299
-                            $httpMethod == 'DELETE')
300
-                    ) {
301
-                        $call['metadata']['param'][$position][$dataName]['from']
302
-                            = 'query';
303
-                    }
304
-                }
305
-                if (empty($pathParams) || $allowAmbiguity) {
306
-                    static::addPath($url, $call, $httpMethod, $version);
307
-                }
308
-                $lastPathParam = end($pathParams);
309
-                foreach ($pathParams as $position) {
310
-                    if (!empty($url))
311
-                        $url .= '/';
312
-                    $url .= '{' .
313
-                        static::typeChar(isset($call['metadata']['param'][$position]['type'])
314
-                            ? $call['metadata']['param'][$position]['type']
315
-                            : null)
316
-                        . $position . '}';
317
-                    if ($allowAmbiguity || $position == $lastPathParam) {
318
-                        static::addPath($url, $call, $httpMethod, $version);
319
-                    }
320
-                }
321
-            }
322
-        }
323
-    }
231
+			// take note of the order
232
+			$call = array(
233
+				'url' => null,
234
+				'className' => $className,
235
+				'path' => rtrim($resourcePath, '/'),
236
+				'methodName' => $method->getName(),
237
+				'arguments' => $arguments,
238
+				'defaults' => $defaults,
239
+				'metadata' => $metadata,
240
+				'accessLevel' => $accessLevel,
241
+			);
242
+			// if manual route
243
+			if (preg_match_all(
244
+				'/@url\s+(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)'
245
+				. '[ \t]*\/?(\S*)/s',
246
+				$doc, $matches, PREG_SET_ORDER
247
+			)
248
+			) {
249
+				foreach ($matches as $match) {
250
+					$httpMethod = $match[1];
251
+					$url = rtrim($resourcePath . $match[2], '/');
252
+					//deep copy the call, as it may change for each @url
253
+					$copy = unserialize(serialize($call));
254
+					foreach ($copy['metadata']['param'] as $i => $p) {
255
+						$inPath =
256
+							strpos($url, '{' . $p['name'] . '}') ||
257
+							strpos($url, ':' . $p['name']);
258
+						if ($inPath) {
259
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'path';
260
+						} elseif ($httpMethod == 'GET' || $httpMethod == 'DELETE') {
261
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'query';
262
+						} elseif (empty($p[$dataName]['from']) || $p[$dataName]['from'] == 'path') {
263
+							$copy['metadata']['param'][$i][$dataName]['from'] = 'body';
264
+						}
265
+					}
266
+					$url = preg_replace_callback('/{[^}]+}|:[^\/]+/',
267
+						function ($matches) use ($copy) {
268
+							$match = trim($matches[0], '{}:');
269
+							$index = $copy['arguments'][$match];
270
+							return '{' .
271
+							Routes::typeChar(isset(
272
+								$copy['metadata']['param'][$index]['type'])
273
+								? $copy['metadata']['param'][$index]['type']
274
+								: null)
275
+							. $index . '}';
276
+						}, $url);
277
+					static::addPath($url, $copy, $httpMethod, $version);
278
+				}
279
+				//if auto route enabled, do so
280
+			} elseif (Defaults::$autoRoutingEnabled) {
281
+				// no configuration found so use convention
282
+				if (preg_match_all(
283
+					'/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)/i',
284
+					$methodUrl, $matches)
285
+				) {
286
+					$httpMethod = strtoupper($matches[0][0]);
287
+					$methodUrl = substr($methodUrl, strlen($httpMethod));
288
+				} else {
289
+					$httpMethod = 'GET';
290
+				}
291
+				if ($methodUrl == 'index') {
292
+					$methodUrl = '';
293
+				}
294
+				$url = empty($methodUrl) ? rtrim($resourcePath, '/')
295
+					: $resourcePath . $methodUrl;
296
+				for ($position = 0; $position < count($params); $position++) {
297
+					$from = $metadata['param'][$position][$dataName]['from'];
298
+					if ($from == 'body' && ($httpMethod == 'GET' ||
299
+							$httpMethod == 'DELETE')
300
+					) {
301
+						$call['metadata']['param'][$position][$dataName]['from']
302
+							= 'query';
303
+					}
304
+				}
305
+				if (empty($pathParams) || $allowAmbiguity) {
306
+					static::addPath($url, $call, $httpMethod, $version);
307
+				}
308
+				$lastPathParam = end($pathParams);
309
+				foreach ($pathParams as $position) {
310
+					if (!empty($url))
311
+						$url .= '/';
312
+					$url .= '{' .
313
+						static::typeChar(isset($call['metadata']['param'][$position]['type'])
314
+							? $call['metadata']['param'][$position]['type']
315
+							: null)
316
+						. $position . '}';
317
+					if ($allowAmbiguity || $position == $lastPathParam) {
318
+						static::addPath($url, $call, $httpMethod, $version);
319
+					}
320
+				}
321
+			}
322
+		}
323
+	}
324 324
 
325
-    /**
326
-     * @access private
327
-     */
328
-    public static function typeChar($type = null)
329
-    {
330
-        if (!$type) {
331
-            return 's';
332
-        }
333
-        switch ($type[0]) {
334
-            case 'i':
335
-            case 'f':
336
-                return 'n';
337
-        }
338
-        return 's';
339
-    }
325
+	/**
326
+	 * @access private
327
+	 */
328
+	public static function typeChar($type = null)
329
+	{
330
+		if (!$type) {
331
+			return 's';
332
+		}
333
+		switch ($type[0]) {
334
+			case 'i':
335
+			case 'f':
336
+				return 'n';
337
+		}
338
+		return 's';
339
+	}
340 340
 
341
-    protected static function addPath($path, array $call,
342
-        $httpMethod = 'GET', $version = 1)
343
-    {
344
-        $call['url'] = preg_replace_callback(
345
-            "/\{\S(\d+)\}/",
346
-            function ($matches) use ($call) {
347
-                return '{' .
348
-                $call['metadata']['param'][$matches[1]]['name'] . '}';
349
-            },
350
-            $path
351
-        );
352
-        //check for wildcard routes
353
-        if (substr($path, -1, 1) == '*') {
354
-            $path = rtrim($path, '/*');
355
-            static::$routes["v$version"]['*'][$path][$httpMethod] = $call;
356
-        } else {
357
-            static::$routes["v$version"][$path][$httpMethod] = $call;
358
-            //create an alias with index if the method name is index
359
-            if ($call['methodName'] == 'index')
360
-                static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
361
-        }
362
-    }
341
+	protected static function addPath($path, array $call,
342
+		$httpMethod = 'GET', $version = 1)
343
+	{
344
+		$call['url'] = preg_replace_callback(
345
+			"/\{\S(\d+)\}/",
346
+			function ($matches) use ($call) {
347
+				return '{' .
348
+				$call['metadata']['param'][$matches[1]]['name'] . '}';
349
+			},
350
+			$path
351
+		);
352
+		//check for wildcard routes
353
+		if (substr($path, -1, 1) == '*') {
354
+			$path = rtrim($path, '/*');
355
+			static::$routes["v$version"]['*'][$path][$httpMethod] = $call;
356
+		} else {
357
+			static::$routes["v$version"][$path][$httpMethod] = $call;
358
+			//create an alias with index if the method name is index
359
+			if ($call['methodName'] == 'index')
360
+				static::$routes["v$version"][ltrim("$path/index", '/')][$httpMethod] = $call;
361
+		}
362
+	}
363 363
 
364
-    /**
365
-     * Find the api method for the given url and http method
366
-     *
367
-     * @param string $path       Requested url path
368
-     * @param string $httpMethod GET|POST|PUT|PATCH|DELETE etc
369
-     * @param int    $version    Api Version number
370
-     * @param array  $data       Data collected from the request
371
-     *
372
-     * @throws RestException
373
-     * @return ApiMethodInfo
374
-     */
375
-    public static function find($path, $httpMethod,
376
-        $version = 1, array $data = array())
377
-    {
378
-        $p = Util::nestedValue(static::$routes, "v$version");
379
-        if (!$p) {
380
-            throw new RestException(
381
-                404,
382
-                $version == 1 ? '' : "Version $version is not supported"
383
-            );
384
-        }
385
-        $status = 404;
386
-        $message = null;
387
-        $methods = array();
388
-        if (isset($p[$path][$httpMethod])) {
389
-            //================== static routes ==========================
390
-            return static::populate($p[$path][$httpMethod], $data);
391
-        } elseif (isset($p['*'])) {
392
-            //================== wildcard routes ========================
393
-            uksort($p['*'], function ($a, $b) {
394
-                return strlen($b) - strlen($a);
395
-            });
396
-            foreach ($p['*'] as $key => $value) {
397
-                if (strpos($path, $key) === 0 && isset($value[$httpMethod])) {
398
-                    //path found, convert rest of the path to parameters
399
-                    $path = substr($path, strlen($key) + 1);
400
-                    $call = ApiMethodInfo::__set_state($value[$httpMethod]);
401
-                    $call->parameters = empty($path)
402
-                        ? array()
403
-                        : explode('/', $path);
404
-                    return $call;
405
-                }
406
-            }
407
-        }
408
-        //================== dynamic routes =============================
409
-        //add newline char if trailing slash is found
410
-        if (substr($path, -1) == '/')
411
-            $path .= PHP_EOL;
412
-        //if double slash is found fill in newline char;
413
-        $path = str_replace('//', '/' . PHP_EOL . '/', $path);
414
-        ksort($p);
415
-        foreach ($p as $key => $value) {
416
-            if (!isset($value[$httpMethod])) {
417
-                continue;
418
-            }
419
-            $regex = str_replace(array('{', '}'),
420
-                array('(?P<', '>[^/]+)'), $key);
421
-            if (preg_match_all(":^$regex$:i", $path, $matches, PREG_SET_ORDER)) {
422
-                $matches = $matches[0];
423
-                $found = true;
424
-                foreach ($matches as $k => $v) {
425
-                    if (is_numeric($k)) {
426
-                        unset($matches[$k]);
427
-                        continue;
428
-                    }
429
-                    $index = intval(substr($k, 1));
430
-                    $details = $value[$httpMethod]['metadata']['param'][$index];
431
-                    if ($k[0] == 's' || strpos($k, static::pathVarTypeOf($v)) === 0) {
432
-                        //remove the newlines
433
-                        $data[$details['name']] = trim($v, PHP_EOL);
434
-                    } else {
435
-                        $status = 400;
436
-                        $message = 'invalid value specified for `'
437
-                            . $details['name'] . '`';
438
-                        $found = false;
439
-                        break;
440
-                    }
441
-                }
442
-                if ($found) {
443
-                    return static::populate($value[$httpMethod], $data);
444
-                }
445
-            }
446
-        }
447
-        if ($status == 404) {
448
-            //check if other methods are allowed
449
-            if (isset($p[$path])) {
450
-                $status = 405;
451
-                $methods = array_keys($p[$path]);
452
-            }
453
-        }
454
-        if ($status == 405) {
455
-            header('Allow: ' . implode(', ', $methods));
456
-        }
457
-        throw new RestException($status, $message);
458
-    }
364
+	/**
365
+	 * Find the api method for the given url and http method
366
+	 *
367
+	 * @param string $path       Requested url path
368
+	 * @param string $httpMethod GET|POST|PUT|PATCH|DELETE etc
369
+	 * @param int    $version    Api Version number
370
+	 * @param array  $data       Data collected from the request
371
+	 *
372
+	 * @throws RestException
373
+	 * @return ApiMethodInfo
374
+	 */
375
+	public static function find($path, $httpMethod,
376
+		$version = 1, array $data = array())
377
+	{
378
+		$p = Util::nestedValue(static::$routes, "v$version");
379
+		if (!$p) {
380
+			throw new RestException(
381
+				404,
382
+				$version == 1 ? '' : "Version $version is not supported"
383
+			);
384
+		}
385
+		$status = 404;
386
+		$message = null;
387
+		$methods = array();
388
+		if (isset($p[$path][$httpMethod])) {
389
+			//================== static routes ==========================
390
+			return static::populate($p[$path][$httpMethod], $data);
391
+		} elseif (isset($p['*'])) {
392
+			//================== wildcard routes ========================
393
+			uksort($p['*'], function ($a, $b) {
394
+				return strlen($b) - strlen($a);
395
+			});
396
+			foreach ($p['*'] as $key => $value) {
397
+				if (strpos($path, $key) === 0 && isset($value[$httpMethod])) {
398
+					//path found, convert rest of the path to parameters
399
+					$path = substr($path, strlen($key) + 1);
400
+					$call = ApiMethodInfo::__set_state($value[$httpMethod]);
401
+					$call->parameters = empty($path)
402
+						? array()
403
+						: explode('/', $path);
404
+					return $call;
405
+				}
406
+			}
407
+		}
408
+		//================== dynamic routes =============================
409
+		//add newline char if trailing slash is found
410
+		if (substr($path, -1) == '/')
411
+			$path .= PHP_EOL;
412
+		//if double slash is found fill in newline char;
413
+		$path = str_replace('//', '/' . PHP_EOL . '/', $path);
414
+		ksort($p);
415
+		foreach ($p as $key => $value) {
416
+			if (!isset($value[$httpMethod])) {
417
+				continue;
418
+			}
419
+			$regex = str_replace(array('{', '}'),
420
+				array('(?P<', '>[^/]+)'), $key);
421
+			if (preg_match_all(":^$regex$:i", $path, $matches, PREG_SET_ORDER)) {
422
+				$matches = $matches[0];
423
+				$found = true;
424
+				foreach ($matches as $k => $v) {
425
+					if (is_numeric($k)) {
426
+						unset($matches[$k]);
427
+						continue;
428
+					}
429
+					$index = intval(substr($k, 1));
430
+					$details = $value[$httpMethod]['metadata']['param'][$index];
431
+					if ($k[0] == 's' || strpos($k, static::pathVarTypeOf($v)) === 0) {
432
+						//remove the newlines
433
+						$data[$details['name']] = trim($v, PHP_EOL);
434
+					} else {
435
+						$status = 400;
436
+						$message = 'invalid value specified for `'
437
+							. $details['name'] . '`';
438
+						$found = false;
439
+						break;
440
+					}
441
+				}
442
+				if ($found) {
443
+					return static::populate($value[$httpMethod], $data);
444
+				}
445
+			}
446
+		}
447
+		if ($status == 404) {
448
+			//check if other methods are allowed
449
+			if (isset($p[$path])) {
450
+				$status = 405;
451
+				$methods = array_keys($p[$path]);
452
+			}
453
+		}
454
+		if ($status == 405) {
455
+			header('Allow: ' . implode(', ', $methods));
456
+		}
457
+		throw new RestException($status, $message);
458
+	}
459 459
 
460
-    public static function findAll(array $excludedPaths = array(), array $excludedHttpMethods = array(), $version = 1)
461
-    {
462
-        $map = array();
463
-        $all = Util::nestedValue(self::$routes, "v$version");
464
-        $filter = array();
465
-        if (isset($all['*'])) {
466
-            $all = $all['*'] + $all;
467
-            unset($all['*']);
468
-        }
469
-        if(is_array($all)){
470
-            foreach ($all as $fullPath => $routes) {
471
-                foreach ($routes as $httpMethod => $route) {
472
-                    if (in_array($httpMethod, $excludedHttpMethods)) {
473
-                        continue;
474
-                    }
475
-                    foreach ($excludedPaths as $exclude) {
476
-                        if (empty($exclude)) {
477
-                            if ($fullPath == $exclude || $fullPath == 'index')
478
-                                continue 2;
479
-                        } elseif (Text::beginsWith($fullPath, $exclude)) {
480
-                            continue 2;
481
-                        }
482
-                    }
483
-                    $hash = "$httpMethod " . $route['url'];
484
-                    if (!isset($filter[$hash])) {
485
-                        $route['httpMethod'] = $httpMethod;
486
-                        $map[$route['metadata']['resourcePath']][]
487
-                            = array('access' => static::verifyAccess($route), 'route' => $route, 'hash' => $hash);
488
-                        $filter[$hash] = true;
489
-                    }
490
-                }
491
-            }
492
-        }
493
-        return $map;
494
-    }
460
+	public static function findAll(array $excludedPaths = array(), array $excludedHttpMethods = array(), $version = 1)
461
+	{
462
+		$map = array();
463
+		$all = Util::nestedValue(self::$routes, "v$version");
464
+		$filter = array();
465
+		if (isset($all['*'])) {
466
+			$all = $all['*'] + $all;
467
+			unset($all['*']);
468
+		}
469
+		if(is_array($all)){
470
+			foreach ($all as $fullPath => $routes) {
471
+				foreach ($routes as $httpMethod => $route) {
472
+					if (in_array($httpMethod, $excludedHttpMethods)) {
473
+						continue;
474
+					}
475
+					foreach ($excludedPaths as $exclude) {
476
+						if (empty($exclude)) {
477
+							if ($fullPath == $exclude || $fullPath == 'index')
478
+								continue 2;
479
+						} elseif (Text::beginsWith($fullPath, $exclude)) {
480
+							continue 2;
481
+						}
482
+					}
483
+					$hash = "$httpMethod " . $route['url'];
484
+					if (!isset($filter[$hash])) {
485
+						$route['httpMethod'] = $httpMethod;
486
+						$map[$route['metadata']['resourcePath']][]
487
+							= array('access' => static::verifyAccess($route), 'route' => $route, 'hash' => $hash);
488
+						$filter[$hash] = true;
489
+					}
490
+				}
491
+			}
492
+		}
493
+		return $map;
494
+	}
495 495
 
496
-    public static function verifyAccess($route)
497
-    {
498
-        if ($route['accessLevel'] < 2)
499
-            return true;
500
-        /** @var Restler $r */
501
-        $r = Scope::get('Restler');
502
-        $authenticated = $r->_authenticated;
503
-        if (!$authenticated && $route['accessLevel'] > 1)
504
-            return false;
505
-        if (
506
-            $authenticated &&
507
-            Defaults::$accessControlFunction &&
508
-            (!call_user_func(Defaults::$accessControlFunction, $route['metadata']))
509
-        ) {
510
-            return false;
511
-        }
512
-        return true;
513
-    }
496
+	public static function verifyAccess($route)
497
+	{
498
+		if ($route['accessLevel'] < 2)
499
+			return true;
500
+		/** @var Restler $r */
501
+		$r = Scope::get('Restler');
502
+		$authenticated = $r->_authenticated;
503
+		if (!$authenticated && $route['accessLevel'] > 1)
504
+			return false;
505
+		if (
506
+			$authenticated &&
507
+			Defaults::$accessControlFunction &&
508
+			(!call_user_func(Defaults::$accessControlFunction, $route['metadata']))
509
+		) {
510
+			return false;
511
+		}
512
+		return true;
513
+	}
514 514
 
515 515
 
516
-    /**
517
-     * Populates the parameter values
518
-     *
519
-     * @param array $call
520
-     * @param       $data
521
-     *
522
-     * @return ApiMethodInfo
523
-     *
524
-     * @access private
525
-     */
526
-    protected static function populate(array $call, $data)
527
-    {
528
-        $call['parameters'] = $call['defaults'];
529
-        $p = & $call['parameters'];
530
-        $dataName = CommentParser::$embeddedDataName;
531
-        foreach ($data as $key => $value) {
532
-            if (isset($call['arguments'][$key])) {
533
-                $p[$call['arguments'][$key]] = $value;
534
-            }
535
-        }
536
-        if (Defaults::$smartParameterParsing) {
537
-            if (
538
-                ($m = Util::nestedValue($call, 'metadata', 'param', 0)) &&
539
-                !array_key_exists($m['name'], $data) &&
540
-                array_key_exists(Defaults::$fullRequestDataName, $data) &&
541
-                !is_null($d = $data[Defaults::$fullRequestDataName]) &&
542
-                isset($m['type']) &&
543
-                static::typeMatch($m['type'], $d)
544
-            ) {
545
-                $p[0] = $d;
546
-            } else {
547
-                $bodyParamCount = 0;
548
-                $lastBodyParamIndex = -1;
549
-                $lastM = null;
550
-                foreach ($call['metadata']['param'] as $k => $m) {
551
-                    if ($m[$dataName]['from'] == 'body') {
552
-                        $bodyParamCount++;
553
-                        $lastBodyParamIndex = $k;
554
-                        $lastM = $m;
555
-                    }
556
-                }
557
-                if (
558
-                    $bodyParamCount == 1 &&
559
-                    !array_key_exists($lastM['name'], $data) &&
560
-                    array_key_exists(Defaults::$fullRequestDataName, $data) &&
561
-                    !is_null($d = $data[Defaults::$fullRequestDataName])
562
-                ) {
563
-                    $p[$lastBodyParamIndex] = $d;
564
-                }
565
-            }
566
-        }
567
-        $r = ApiMethodInfo::__set_state($call);
568
-        $modifier = "_modify_{$r->methodName}_api";
569
-        if (method_exists($r->className, $modifier)) {
570
-            $stage = end(Scope::get('Restler')->getEvents());
571
-            if (empty($stage))
572
-                $stage = 'setup';
573
-            $r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
574
-        }
575
-        return $r;
576
-    }
516
+	/**
517
+	 * Populates the parameter values
518
+	 *
519
+	 * @param array $call
520
+	 * @param       $data
521
+	 *
522
+	 * @return ApiMethodInfo
523
+	 *
524
+	 * @access private
525
+	 */
526
+	protected static function populate(array $call, $data)
527
+	{
528
+		$call['parameters'] = $call['defaults'];
529
+		$p = & $call['parameters'];
530
+		$dataName = CommentParser::$embeddedDataName;
531
+		foreach ($data as $key => $value) {
532
+			if (isset($call['arguments'][$key])) {
533
+				$p[$call['arguments'][$key]] = $value;
534
+			}
535
+		}
536
+		if (Defaults::$smartParameterParsing) {
537
+			if (
538
+				($m = Util::nestedValue($call, 'metadata', 'param', 0)) &&
539
+				!array_key_exists($m['name'], $data) &&
540
+				array_key_exists(Defaults::$fullRequestDataName, $data) &&
541
+				!is_null($d = $data[Defaults::$fullRequestDataName]) &&
542
+				isset($m['type']) &&
543
+				static::typeMatch($m['type'], $d)
544
+			) {
545
+				$p[0] = $d;
546
+			} else {
547
+				$bodyParamCount = 0;
548
+				$lastBodyParamIndex = -1;
549
+				$lastM = null;
550
+				foreach ($call['metadata']['param'] as $k => $m) {
551
+					if ($m[$dataName]['from'] == 'body') {
552
+						$bodyParamCount++;
553
+						$lastBodyParamIndex = $k;
554
+						$lastM = $m;
555
+					}
556
+				}
557
+				if (
558
+					$bodyParamCount == 1 &&
559
+					!array_key_exists($lastM['name'], $data) &&
560
+					array_key_exists(Defaults::$fullRequestDataName, $data) &&
561
+					!is_null($d = $data[Defaults::$fullRequestDataName])
562
+				) {
563
+					$p[$lastBodyParamIndex] = $d;
564
+				}
565
+			}
566
+		}
567
+		$r = ApiMethodInfo::__set_state($call);
568
+		$modifier = "_modify_{$r->methodName}_api";
569
+		if (method_exists($r->className, $modifier)) {
570
+			$stage = end(Scope::get('Restler')->getEvents());
571
+			if (empty($stage))
572
+				$stage = 'setup';
573
+			$r = Scope::get($r->className)->$modifier($r, $stage) ? : $r;
574
+		}
575
+		return $r;
576
+	}
577 577
 
578
-    /**
579
-     * @access private
580
-     */
581
-    protected static function pathVarTypeOf($var)
582
-    {
583
-        if (is_numeric($var)) {
584
-            return 'n';
585
-        }
586
-        if ($var === 'true' || $var === 'false') {
587
-            return 'b';
588
-        }
589
-        return 's';
590
-    }
578
+	/**
579
+	 * @access private
580
+	 */
581
+	protected static function pathVarTypeOf($var)
582
+	{
583
+		if (is_numeric($var)) {
584
+			return 'n';
585
+		}
586
+		if ($var === 'true' || $var === 'false') {
587
+			return 'b';
588
+		}
589
+		return 's';
590
+	}
591 591
 
592
-    protected static function typeMatch($type, $var)
593
-    {
594
-        switch ($type) {
595
-            case 'boolean':
596
-            case 'bool':
597
-                return is_bool($var);
598
-            case 'array':
599
-            case 'object':
600
-                return is_array($var);
601
-            case 'string':
602
-            case 'int':
603
-            case 'integer':
604
-            case 'float':
605
-            case 'number':
606
-                return is_scalar($var);
607
-        }
608
-        return true;
609
-    }
592
+	protected static function typeMatch($type, $var)
593
+	{
594
+		switch ($type) {
595
+			case 'boolean':
596
+			case 'bool':
597
+				return is_bool($var);
598
+			case 'array':
599
+			case 'object':
600
+				return is_array($var);
601
+			case 'string':
602
+			case 'int':
603
+			case 'integer':
604
+			case 'float':
605
+			case 'number':
606
+				return is_scalar($var);
607
+		}
608
+		return true;
609
+	}
610 610
 
611
-    protected static function parseMagic(ReflectionClass $class, $forResponse = true)
612
-    {
613
-        if (!$c = CommentParser::parse($class->getDocComment())) {
614
-            return false;
615
-        }
616
-        $p = 'property';
617
-        $r = empty($c[$p]) ? array() : $c[$p];
618
-        $p .= '-' . ($forResponse ? 'read' : 'write');
619
-        if (!empty($c[$p])) {
620
-            $r = array_merge($r, $c[$p]);
621
-        }
611
+	protected static function parseMagic(ReflectionClass $class, $forResponse = true)
612
+	{
613
+		if (!$c = CommentParser::parse($class->getDocComment())) {
614
+			return false;
615
+		}
616
+		$p = 'property';
617
+		$r = empty($c[$p]) ? array() : $c[$p];
618
+		$p .= '-' . ($forResponse ? 'read' : 'write');
619
+		if (!empty($c[$p])) {
620
+			$r = array_merge($r, $c[$p]);
621
+		}
622 622
 
623
-        return $r;
624
-    }
623
+		return $r;
624
+	}
625 625
 
626
-    /**
627
-     * Get the type and associated model
628
-     *
629
-     * @param ReflectionClass $class
630
-     * @param array           $scope
631
-     *
632
-     * @throws RestException
633
-     * @throws \Exception
634
-     * @return array
635
-     *
636
-     * @access protected
637
-     */
638
-    protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix='', array $rules=array())
639
-    {
640
-        $className = $class->getName();
641
-        $dataName = CommentParser::$embeddedDataName;
642
-        if (isset(static::$models[$prefix.$className])) {
643
-            return static::$models[$prefix.$className];
644
-        }
645
-        $children = array();
646
-        try {
647
-            if ($magic_properties = static::parseMagic($class, empty($prefix))) {
648
-                foreach ($magic_properties as $prop) {
649
-                    if (!isset($prop['name'])) {
650
-                        throw new Exception('@property comment is not properly defined in ' . $className . ' class');
651
-                    }
652
-                    if (!isset($prop[$dataName]['label'])) {
653
-                        $prop[$dataName]['label'] = Text::title($prop['name']);
654
-                    }
655
-                    if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] == 'string' && !isset($prop[$dataName]['type'])) {
656
-                        $prop[$dataName]['type'] = static::$fieldTypesByName[$prop['name']];
657
-                    }
658
-                    $children[$prop['name']] = $prop;
659
-                }
660
-            } else {
661
-                $props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
662
-                foreach ($props as $prop) {
663
-                    $name = $prop->getName();
664
-                    $child = array('name' => $name);
665
-                    if ($c = $prop->getDocComment()) {
666
-                        $child += Util::nestedValue(CommentParser::parse($c), 'var') ?: array();
667
-                    } else {
668
-                        $o = $class->newInstance();
669
-                        $p = $prop->getValue($o);
670
-                        if (is_object($p)) {
671
-                            $child['type'] = get_class($p);
672
-                        } elseif (is_array($p)) {
673
-                            $child['type'] = 'array';
674
-                            if (count($p)) {
675
-                                $pc = reset($p);
676
-                                if (is_object($pc)) {
677
-                                    $child['contentType'] = get_class($pc);
678
-                                }
679
-                            }
680
-                        }
681
-                    }
682
-                    $child += array(
683
-                        'type'  => isset(static::$fieldTypesByName[$child['name']])
684
-                            ? static::$fieldTypesByName[$child['name']]
685
-                            : 'string',
686
-                        'label' => Text::title($child['name'])
687
-                    );
688
-                    isset($child[$dataName])
689
-                        ? $child[$dataName] += array('required' => true)
690
-                        : $child[$dataName]['required'] = true;
691
-                    if ($prop->class != $className && $qualified = Scope::resolve($child['type'], $scope)) {
692
-                        list($child['type'], $child['children'])
693
-                            = static::getTypeAndModel(new ReflectionClass($qualified), $scope);
694
-                    } elseif (
695
-                        ($contentType = Util::nestedValue($child, $dataName, 'type')) &&
696
-                        ($qualified = Scope::resolve($contentType, $scope))
697
-                    ) {
698
-                        list($child['contentType'], $child['children'])
699
-                            = static::getTypeAndModel(new ReflectionClass($qualified), $scope);
700
-                    }
701
-                    $children[$name] = $child;
702
-                }
703
-            }
704
-        } catch (Exception $e) {
705
-            if (Text::endsWith($e->getFile(), 'CommentParser.php')) {
706
-                throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
707
-            }
708
-            throw $e;
709
-        }
710
-        if ($properties = Util::nestedValue($rules, 'properties')) {
711
-            if (is_string($properties)) {
712
-                $properties = array($properties);
713
-            }
714
-            $c = array();
715
-            foreach ($properties as $property) {
716
-                if (isset($children[$property])) {
717
-                    $c[$property] = $children[$property];
718
-                }
719
-            }
720
-            $children = $c;
721
-        }
722
-        if ($required = Util::nestedValue($rules, 'required')) {
723
-            //override required on children
724
-            if (is_bool($required)) {
725
-                // true means all are required false means none are required
726
-                $required = $required ? array_keys($children) : array();
727
-            } elseif (is_string($required)) {
728
-                $required = array($required);
729
-            }
730
-            $required = array_fill_keys($required, true);
731
-            foreach ($children as $name => $child) {
732
-                $children[$name][$dataName]['required'] = isset($required[$name]);
733
-            }
734
-        }
735
-        static::$models[$prefix.$className] = array($className, $children, $prefix.$className);
736
-        return static::$models[$prefix.$className];
737
-    }
626
+	/**
627
+	 * Get the type and associated model
628
+	 *
629
+	 * @param ReflectionClass $class
630
+	 * @param array           $scope
631
+	 *
632
+	 * @throws RestException
633
+	 * @throws \Exception
634
+	 * @return array
635
+	 *
636
+	 * @access protected
637
+	 */
638
+	protected static function getTypeAndModel(ReflectionClass $class, array $scope, $prefix='', array $rules=array())
639
+	{
640
+		$className = $class->getName();
641
+		$dataName = CommentParser::$embeddedDataName;
642
+		if (isset(static::$models[$prefix.$className])) {
643
+			return static::$models[$prefix.$className];
644
+		}
645
+		$children = array();
646
+		try {
647
+			if ($magic_properties = static::parseMagic($class, empty($prefix))) {
648
+				foreach ($magic_properties as $prop) {
649
+					if (!isset($prop['name'])) {
650
+						throw new Exception('@property comment is not properly defined in ' . $className . ' class');
651
+					}
652
+					if (!isset($prop[$dataName]['label'])) {
653
+						$prop[$dataName]['label'] = Text::title($prop['name']);
654
+					}
655
+					if (isset(static::$fieldTypesByName[$prop['name']]) && $prop['type'] == 'string' && !isset($prop[$dataName]['type'])) {
656
+						$prop[$dataName]['type'] = static::$fieldTypesByName[$prop['name']];
657
+					}
658
+					$children[$prop['name']] = $prop;
659
+				}
660
+			} else {
661
+				$props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
662
+				foreach ($props as $prop) {
663
+					$name = $prop->getName();
664
+					$child = array('name' => $name);
665
+					if ($c = $prop->getDocComment()) {
666
+						$child += Util::nestedValue(CommentParser::parse($c), 'var') ?: array();
667
+					} else {
668
+						$o = $class->newInstance();
669
+						$p = $prop->getValue($o);
670
+						if (is_object($p)) {
671
+							$child['type'] = get_class($p);
672
+						} elseif (is_array($p)) {
673
+							$child['type'] = 'array';
674
+							if (count($p)) {
675
+								$pc = reset($p);
676
+								if (is_object($pc)) {
677
+									$child['contentType'] = get_class($pc);
678
+								}
679
+							}
680
+						}
681
+					}
682
+					$child += array(
683
+						'type'  => isset(static::$fieldTypesByName[$child['name']])
684
+							? static::$fieldTypesByName[$child['name']]
685
+							: 'string',
686
+						'label' => Text::title($child['name'])
687
+					);
688
+					isset($child[$dataName])
689
+						? $child[$dataName] += array('required' => true)
690
+						: $child[$dataName]['required'] = true;
691
+					if ($prop->class != $className && $qualified = Scope::resolve($child['type'], $scope)) {
692
+						list($child['type'], $child['children'])
693
+							= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
694
+					} elseif (
695
+						($contentType = Util::nestedValue($child, $dataName, 'type')) &&
696
+						($qualified = Scope::resolve($contentType, $scope))
697
+					) {
698
+						list($child['contentType'], $child['children'])
699
+							= static::getTypeAndModel(new ReflectionClass($qualified), $scope);
700
+					}
701
+					$children[$name] = $child;
702
+				}
703
+			}
704
+		} catch (Exception $e) {
705
+			if (Text::endsWith($e->getFile(), 'CommentParser.php')) {
706
+				throw new RestException(500, "Error while parsing comments of `$className` class. " . $e->getMessage());
707
+			}
708
+			throw $e;
709
+		}
710
+		if ($properties = Util::nestedValue($rules, 'properties')) {
711
+			if (is_string($properties)) {
712
+				$properties = array($properties);
713
+			}
714
+			$c = array();
715
+			foreach ($properties as $property) {
716
+				if (isset($children[$property])) {
717
+					$c[$property] = $children[$property];
718
+				}
719
+			}
720
+			$children = $c;
721
+		}
722
+		if ($required = Util::nestedValue($rules, 'required')) {
723
+			//override required on children
724
+			if (is_bool($required)) {
725
+				// true means all are required false means none are required
726
+				$required = $required ? array_keys($children) : array();
727
+			} elseif (is_string($required)) {
728
+				$required = array($required);
729
+			}
730
+			$required = array_fill_keys($required, true);
731
+			foreach ($children as $name => $child) {
732
+				$children[$name][$dataName]['required'] = isset($required[$name]);
733
+			}
734
+		}
735
+		static::$models[$prefix.$className] = array($className, $children, $prefix.$className);
736
+		return static::$models[$prefix.$className];
737
+	}
738 738
 
739
-    /**
740
-     * Import previously created routes from cache
741
-     *
742
-     * @param array $routes
743
-     */
744
-    public static function fromArray(array $routes)
745
-    {
746
-        static::$routes = $routes;
747
-    }
739
+	/**
740
+	 * Import previously created routes from cache
741
+	 *
742
+	 * @param array $routes
743
+	 */
744
+	public static function fromArray(array $routes)
745
+	{
746
+		static::$routes = $routes;
747
+	}
748 748
 
749
-    /**
750
-     * Export current routes for cache
751
-     *
752
-     * @return array
753
-     */
754
-    public static function toArray()
755
-    {
756
-        return static::$routes;
757
-    }
749
+	/**
750
+	 * Export current routes for cache
751
+	 *
752
+	 * @return array
753
+	 */
754
+	public static function toArray()
755
+	{
756
+		return static::$routes;
757
+	}
758 758
 
759
-    public static function type($var)
760
-    {
761
-        if (is_object($var)) return get_class($var);
762
-        if (is_array($var)) return 'array';
763
-        if (is_bool($var)) return 'boolean';
764
-        if (is_numeric($var)) return is_float($var) ? 'float' : 'int';
765
-        return 'string';
766
-    }
759
+	public static function type($var)
760
+	{
761
+		if (is_object($var)) return get_class($var);
762
+		if (is_array($var)) return 'array';
763
+		if (is_bool($var)) return 'boolean';
764
+		if (is_numeric($var)) return is_float($var) ? 'float' : 'int';
765
+		return 'string';
766
+	}
767 767
 
768
-    public static function scope(ReflectionClass $class)
769
-    {
770
-        $namespace = $class->getNamespaceName();
771
-        $imports = array(
772
-            '*' => empty($namespace) ? '' : $namespace . '\\'
773
-        );
774
-        $file = file_get_contents($class->getFileName());
775
-        $tokens = token_get_all($file);
776
-        $namespace = '';
777
-        $alias = '';
778
-        $reading = false;
779
-        $last = 0;
780
-        foreach ($tokens as $token) {
781
-            if (is_string($token)) {
782
-                if ($reading && ',' == $token) {
783
-                    //===== STOP =====//
784
-                    $reading = false;
785
-                    if (!empty($namespace))
786
-                        $imports[$alias] = trim($namespace, '\\');
787
-                    //===== START =====//
788
-                    $reading = true;
789
-                    $namespace = '';
790
-                    $alias = '';
791
-                } else {
792
-                    //===== STOP =====//
793
-                    $reading = false;
794
-                    if (!empty($namespace))
795
-                        $imports[$alias] = trim($namespace, '\\');
796
-                }
797
-            } elseif (T_USE == $token[0]) {
798
-                //===== START =====//
799
-                $reading = true;
800
-                $namespace = '';
801
-                $alias = '';
802
-            } elseif ($reading) {
803
-                //echo token_name($token[0]) . ' ' . $token[1] . PHP_EOL;
804
-                switch ($token[0]) {
805
-                    case T_WHITESPACE:
806
-                        continue 2;
807
-                    case T_STRING:
808
-                        $alias = $token[1];
809
-                        if (T_AS == $last) {
810
-                            break;
811
-                        }
812
-                    //don't break;
813
-                    case T_NS_SEPARATOR:
814
-                        $namespace .= $token[1];
815
-                        break;
816
-                }
817
-                $last = $token[0];
818
-            }
819
-        }
820
-        return $imports;
821
-    }
768
+	public static function scope(ReflectionClass $class)
769
+	{
770
+		$namespace = $class->getNamespaceName();
771
+		$imports = array(
772
+			'*' => empty($namespace) ? '' : $namespace . '\\'
773
+		);
774
+		$file = file_get_contents($class->getFileName());
775
+		$tokens = token_get_all($file);
776
+		$namespace = '';
777
+		$alias = '';
778
+		$reading = false;
779
+		$last = 0;
780
+		foreach ($tokens as $token) {
781
+			if (is_string($token)) {
782
+				if ($reading && ',' == $token) {
783
+					//===== STOP =====//
784
+					$reading = false;
785
+					if (!empty($namespace))
786
+						$imports[$alias] = trim($namespace, '\\');
787
+					//===== START =====//
788
+					$reading = true;
789
+					$namespace = '';
790
+					$alias = '';
791
+				} else {
792
+					//===== STOP =====//
793
+					$reading = false;
794
+					if (!empty($namespace))
795
+						$imports[$alias] = trim($namespace, '\\');
796
+				}
797
+			} elseif (T_USE == $token[0]) {
798
+				//===== START =====//
799
+				$reading = true;
800
+				$namespace = '';
801
+				$alias = '';
802
+			} elseif ($reading) {
803
+				//echo token_name($token[0]) . ' ' . $token[1] . PHP_EOL;
804
+				switch ($token[0]) {
805
+					case T_WHITESPACE:
806
+						continue 2;
807
+					case T_STRING:
808
+						$alias = $token[1];
809
+						if (T_AS == $last) {
810
+							break;
811
+						}
812
+					//don't break;
813
+					case T_NS_SEPARATOR:
814
+						$namespace .= $token[1];
815
+						break;
816
+				}
817
+				$last = $token[0];
818
+			}
819
+		}
820
+		return $imports;
821
+	}
822 822
 }
Please login to merge, or discard this patch.
includes/restler/framework/Luracast/Restler/iProvideMultiVersionApi.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@
 block discarded – undo
9 9
  */
10 10
 interface iProvideMultiVersionApi
11 11
 {
12
-    /**
13
-     * Maximum api version supported by the api class
14
-     * @return int
15
-     */
16
-    public static function __getMaximumSupportedVersion();
12
+	/**
13
+	 * Maximum api version supported by the api class
14
+	 * @return int
15
+	 */
16
+	public static function __getMaximumSupportedVersion();
17 17
 }
18 18
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/iCompose.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -16,21 +16,21 @@
 block discarded – undo
16 16
  *
17 17
  */
18 18
 interface iCompose {
19
-    /**
20
-     * Result of an api call is passed to this method
21
-     * to create a standard structure for the data
22
-     *
23
-     * @param mixed $result can be a primitive or array or object
24
-     */
25
-    public function response($result);
19
+	/**
20
+	 * Result of an api call is passed to this method
21
+	 * to create a standard structure for the data
22
+	 *
23
+	 * @param mixed $result can be a primitive or array or object
24
+	 */
25
+	public function response($result);
26 26
 
27
-    /**
28
-     * When the api call results in RestException this method
29
-     * will be called to return the error message
30
-     *
31
-     * @param RestException $exception exception that has reasons for failure
32
-     *
33
-     * @return
34
-     */
35
-    public function message(RestException $exception);
27
+	/**
28
+	 * When the api call results in RestException this method
29
+	 * will be called to return the error message
30
+	 *
31
+	 * @param RestException $exception exception that has reasons for failure
32
+	 *
33
+	 * @return
34
+	 */
35
+	public function message(RestException $exception);
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/EventDispatcher.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,84 +15,84 @@
 block discarded – undo
15 15
 
16 16
 class EventDispatcher
17 17
 {
18
-    private $listeners = array();
19
-    protected static $_waitList = array();
18
+	private $listeners = array();
19
+	protected static $_waitList = array();
20 20
 
21
-    public static $self;
22
-    protected $events = array();
21
+	public static $self;
22
+	protected $events = array();
23 23
 
24
-    public function __construct() {
25
-        static::$self = $this;
26
-        if (!empty(static::$_waitList)) {
27
-            foreach (static::$_waitList as $param) {
28
-                call_user_func_array(array($this,$param[0]), $param[1]);
29
-            }
30
-        }
31
-    }
24
+	public function __construct() {
25
+		static::$self = $this;
26
+		if (!empty(static::$_waitList)) {
27
+			foreach (static::$_waitList as $param) {
28
+				call_user_func_array(array($this,$param[0]), $param[1]);
29
+			}
30
+		}
31
+	}
32 32
 
33
-    public static function __callStatic($eventName, $params)
34
-    {
35
-        if (0 === strpos($eventName, 'on')) {
36
-            if(static::$self){
37
-                return call_user_func_array(array(static::$self, $eventName), $params);
38
-            }
39
-            static::$_waitList[] = func_get_args();
40
-            return false;
41
-        }
42
-    }
33
+	public static function __callStatic($eventName, $params)
34
+	{
35
+		if (0 === strpos($eventName, 'on')) {
36
+			if(static::$self){
37
+				return call_user_func_array(array(static::$self, $eventName), $params);
38
+			}
39
+			static::$_waitList[] = func_get_args();
40
+			return false;
41
+		}
42
+	}
43 43
 
44
-    public function __call($eventName, $params)
45
-    {
46
-        if (0 === strpos($eventName, 'on')) {
47
-            if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName]))
48
-                $this->listeners[$eventName] = array();
49
-            $this->listeners[$eventName][] = $params[0];
50
-        }
51
-        return $this;
52
-    }
44
+	public function __call($eventName, $params)
45
+	{
46
+		if (0 === strpos($eventName, 'on')) {
47
+			if (!isset($this->listeners[$eventName]) || !is_array($this->listeners[$eventName]))
48
+				$this->listeners[$eventName] = array();
49
+			$this->listeners[$eventName][] = $params[0];
50
+		}
51
+		return $this;
52
+	}
53 53
 
54
-    public static function addListener($eventName, Closure $callback)
55
-    {
56
-        return static::$eventName($callback);
57
-    }
54
+	public static function addListener($eventName, Closure $callback)
55
+	{
56
+		return static::$eventName($callback);
57
+	}
58 58
 
59
-    public function on(array $eventHandlers)
60
-    {
61
-        for (
62
-            $count = count($eventHandlers),
63
-                $events = array_map(
64
-                    'ucfirst',
65
-                    $keys = array_keys(
66
-                        $eventHandlers = array_change_key_case(
67
-                            $eventHandlers,
68
-                            CASE_LOWER
69
-                        )
70
-                    )
71
-                ),
72
-                $i = 0;
73
-            $i < $count;
74
-            call_user_func(
75
-                array($this, "on{$events[$i]}"),
76
-                $eventHandlers[$keys[$i++]]
77
-            )
78
-        );
79
-    }
59
+	public function on(array $eventHandlers)
60
+	{
61
+		for (
62
+			$count = count($eventHandlers),
63
+				$events = array_map(
64
+					'ucfirst',
65
+					$keys = array_keys(
66
+						$eventHandlers = array_change_key_case(
67
+							$eventHandlers,
68
+							CASE_LOWER
69
+						)
70
+					)
71
+				),
72
+				$i = 0;
73
+			$i < $count;
74
+			call_user_func(
75
+				array($this, "on{$events[$i]}"),
76
+				$eventHandlers[$keys[$i++]]
77
+			)
78
+		);
79
+	}
80 80
 
81
-    /**
82
-     * Fire an event to notify all listeners
83
-     *
84
-     * @param string $eventName name of the event
85
-     * @param array  $params    event related data
86
-     */
87
-    protected function dispatch($eventName, array $params = array())
88
-    {
89
-        $this->events[] = $eventName;
90
-        $params = func_get_args();
91
-        $eventName = 'on'.ucfirst(array_shift($params));
92
-        if (isset($this->listeners[$eventName]))
93
-            foreach ($this->listeners[$eventName] as $callback)
94
-                call_user_func_array($callback, $params);
95
-    }
81
+	/**
82
+	 * Fire an event to notify all listeners
83
+	 *
84
+	 * @param string $eventName name of the event
85
+	 * @param array  $params    event related data
86
+	 */
87
+	protected function dispatch($eventName, array $params = array())
88
+	{
89
+		$this->events[] = $eventName;
90
+		$params = func_get_args();
91
+		$eventName = 'on'.ucfirst(array_shift($params));
92
+		if (isset($this->listeners[$eventName]))
93
+			foreach ($this->listeners[$eventName] as $callback)
94
+				call_user_func_array($callback, $params);
95
+	}
96 96
 
97 97
 }
98 98
 
Please login to merge, or discard this patch.
htdocs/includes/restler/framework/Luracast/Restler/ExplorerInfo.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
  */
9 9
 class ExplorerInfo
10 10
 {
11
-    public static $title = 'Restler API Explorer';
12
-    public static $description = 'Live API Documentation';
13
-    public static $termsOfService = null;
14
-    public static $contact = array(
15
-        'name'  => 'Restler Support',
16
-        'url'   => 'luracast.com/products/restler',
17
-        'email' => '[email protected]',
18
-    );
19
-    public static $license = array(
20
-        'name' => 'LGPL-2.1',
21
-        'url'  => 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html',
22
-    );
11
+	public static $title = 'Restler API Explorer';
12
+	public static $description = 'Live API Documentation';
13
+	public static $termsOfService = null;
14
+	public static $contact = array(
15
+		'name'  => 'Restler Support',
16
+		'url'   => 'luracast.com/products/restler',
17
+		'email' => '[email protected]',
18
+	);
19
+	public static $license = array(
20
+		'name' => 'LGPL-2.1',
21
+		'url'  => 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html',
22
+	);
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/printipp/CupsPrintIPP.php 1 patch
Indentation   +721 added lines, -721 removed lines patch added patch discarded remove patch
@@ -40,735 +40,735 @@
 block discarded – undo
40 40
 
41 41
 class CupsPrintIPP extends ExtendedPrintIPP
42 42
 {
43
-    public $printers_attributes;
44
-    public $defaults_attributes;
43
+	public $printers_attributes;
44
+	public $defaults_attributes;
45 45
 
46
-    protected $parsed;
47
-    protected $output;
46
+	protected $parsed;
47
+	protected $output;
48 48
 
49
-    public function __construct()
50
-    {
51
-        parent::__construct();
52
-        self::_initTags();
53
-    }
49
+	public function __construct()
50
+	{
51
+		parent::__construct();
52
+		self::_initTags();
53
+	}
54 54
 
55 55
 //
56 56
 // OPERATIONS
57 57
 //
58
-    public function cupsGetDefaults($attributes=array("all"))
59
-    {
60
-        //The CUPS-Get-Default operation returns the default printer URI and attributes
61
-
62
-        $this->jobs = array_merge($this->jobs,array(""));
63
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
64
-        $this->parsed = array();
65
-        unset($this->printer_attributes);
66
-
67
-        if (!isset($this->setup->charset))
68
-        {
69
-            self::setCharset();
70
-        }
71
-
72
-        if (!isset($this->setup->language))
73
-        {
74
-            self::setLanguage('en');
75
-        }
76
-
77
-        self::_setOperationId();
78
-
79
-        for($i = 0 ; $i < count($attributes) ; $i++)
80
-        {
81
-            if ($i == 0)
82
-            {
83
-                $this->meta->attributes = chr(0x44) // Keyword
84
-                                        . self::_giveMeStringLength('requested-attributes')
85
-                                        . 'requested-attributes'
86
-                                        . self::_giveMeStringLength($attributes[0])
87
-                                        . $attributes[0];
88
-            }
89
-            else
90
-            {
91
-                $this->meta->attributes .= chr(0x44) // Keyword
92
-                                        .  chr(0x0).chr(0x0) // zero-length name
93
-                                        .  self::_giveMeStringLength($attributes[$i])
94
-                                        .  $attributes[$i];
95
-            }
96
-        }
97
-
98
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
99
-                         . chr(0x40). chr(0x01) // operation:  cups vendor extension: get defaults
100
-                         . $this->meta->operation_id // request-id
101
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
102
-                         . $this->meta->charset
103
-                         . $this->meta->language
104
-                         . $this->meta->attributes
105
-                         . chr(0x03); // end operations attribute
106
-
107
-        $this->output = $this->stringjob;
108
-
109
-        self::_putDebug("Request: ".$this->output);
110
-
111
-        $post_values = array( "Content-Type" => "application/ipp",
112
-                              "Data" => $this->output);
113
-
114
-        if (self::_sendHttp ($post_values,'/'))
115
-        {
116
-
117
-            if(self::_parseServerOutput())
118
-            {
119
-                self::_parsePrinterAttributes();
120
-            }
121
-        }
122
-
123
-       $this->attributes = &$this->printer_attributes;
124
-
125
-       if (isset($this->printer_attributes->printer_type))
126
-       {
127
-                    $printer_type = $this->printer_attributes->printer_type->_value0;
128
-                    $table = self::_interpretPrinterType($printer_type);
129
-
130
-                    for($i = 0 ; $i < count($table) ; $i++ )
131
-                    {
132
-                        $index = '_value'.$i;
133
-                        $this->printer_attributes->printer_type->$index = $table[$i];
134
-                        }
135
-                    }
136
-
137
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
138
-        {
139
-
140
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
141
-            if ($this->serveroutput->status == "successfull-ok")
142
-            {
143
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
144
-            }
145
-            else
146
-            {
147
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
148
-            }
149
-
150
-            return $this->serveroutput->status;
151
-        }
152
-        else
153
-        {
154
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
155
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
156
-            }
157
-    return false;
158
-    }
159
-
160
-
161
-    public function cupsAcceptJobs($printer_uri)
162
-    {
163
-    //The CUPS-Get-Default operation returns the default printer URI and attributes
164
-
165
-        $this->jobs = array_merge($this->jobs,array(""));
166
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
167
-        $this->parsed = array();
168
-        unset($this->printer_attributes);
169
-
170
-        if (!isset($this->setup->charset))
171
-        {
172
-            self::setCharset();
173
-        }
174
-
175
-        if (!isset($this->setup->language))
176
-        {
177
-            self::setLanguage('en');
178
-        }
179
-
180
-        self::_setOperationId();
181
-
182
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
183
-                         . chr(0x40). chr(0x08) // operation:  cups vendor extension: Accept-Jobs
184
-                         . $this->meta->operation_id // request-id
185
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
186
-                         . $this->meta->charset
187
-                         . $this->meta->language
188
-                         . chr(0x45) // uri
189
-                         . self::_giveMeStringLength('printer-uri')
190
-                         . 'printer-uri'
191
-                         . self::_giveMeStringLength($printer_uri)
192
-                         . $printer_uri
193
-                         . chr(0x03); // end operations attribute
194
-
195
-        $this->output = $this->stringjob;
196
-
197
-        self::_putDebug("Request: ".$this->output);
198
-
199
-        $post_values = array( "Content-Type" => "application/ipp",
200
-                              "Data" => $this->output);
201
-
202
-        if (self::_sendHttp ($post_values,'/admin/'))
203
-        {
204
-
205
-            if(self::_parseServerOutput())
206
-            {
207
-                self::_parseAttributes();
208
-            }
209
-        }
210
-
211
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
212
-        {
213
-
214
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
215
-            if ($this->serveroutput->status == "successfull-ok")
216
-            {
217
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
218
-            }
219
-            else
220
-            {
221
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
222
-            }
223
-
224
-            return $this->serveroutput->status;
225
-        }
226
-        else
227
-        {
228
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
229
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
230
-            }
231
-    return false;
232
-    }
233
-
234
-
235
-    public function cupsRejectJobs($printer_uri,$printer_state_message)
236
-    {
237
-    //The CUPS-Get-Default operation returns the default printer URI and attributes
238
-
239
-        $this->jobs = array_merge($this->jobs,array(""));
240
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
241
-        $this->parsed = array();
242
-        unset($this->attributes);
243
-
244
-        if (!isset($this->setup->charset))
245
-        {
246
-            self::setCharset();
247
-        }
248
-
249
-        if (!isset($this->setup->language))
250
-        {
251
-            self::setLanguage('en');
252
-        }
253
-
254
-        self::_setOperationId();
255
-
256
-        $message = "";
257
-        if ($printer_state_message)
258
-        {
259
-            $message = chr(0x04) // start printer-attributes
260
-                     . chr(0x41) // textWithoutLanguage
261
-                     . self::_giveMeStringLength("printer-state-message")
262
-                     . "printer-state-message"
263
-                     . self::_giveMeStringLength($printer_state_message)
264
-                     . $printer_state_message;
265
-        }
266
-
267
-       $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
268
-                         . chr(0x40). chr(0x09) // operation:  cups vendor extension: Reject-Jobs
269
-                         . $this->meta->operation_id // request-id
270
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
271
-                         . $this->meta->charset
272
-                         . $this->meta->language
273
-                         . chr(0x45) // uri
274
-                         . self::_giveMeStringLength('printer-uri')
275
-                         . 'printer-uri'
276
-                         . self::_giveMeStringLength($printer_uri)
277
-                         . $printer_uri
278
-                         . $message
279
-                         . chr(0x03); // end operations attribute
280
-
281
-        $this->output = $this->stringjob;
282
-
283
-        self::_putDebug("Request: ".$this->output);
284
-
285
-        $post_values = array( "Content-Type" => "application/ipp",
286
-                              "Data" => $this->output);
287
-
288
-        if (self::_sendHttp ($post_values,'/admin/'))
289
-        {
290
-
291
-            if(self::_parseServerOutput())
292
-            {
293
-                self::_parseAttributes();
294
-            }
295
-        }
296
-
297
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
298
-        {
299
-
300
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
301
-            if ($this->serveroutput->status == "successfull-ok")
302
-            {
303
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
304
-            }
305
-            else
306
-            {
307
-                self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
308
-            }
309
-
310
-            return $this->serveroutput->status;
311
-        }
312
-        else
313
-        {
314
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
315
-            self::_errorLog("getting defaults : OPERATION FAILED",1);
316
-        }
317
-        return false;
318
-    }
319
-
320
-
321
-    public function getPrinters($printer_location=false,$printer_info=false,$attributes=array())
322
-    {
323
-        if (count($attributes) == 0)
324
-        {
325
-            true;
326
-        }
327
-        $attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
-        $this->jobs = array_merge($this->jobs,array(""));
329
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
330
-
331
-        unset ($this->printers_attributes);
332
-
333
-        if (!isset($this->setup->charset))
334
-        {
335
-            self::setCharset();
336
-        }
337
-
338
-        if (!isset($this->setup->language))
339
-        {
340
-            self::setLanguage('en-us');
341
-        }
342
-
343
-        self::_setOperationId();
344
-
345
-        $this->meta->attributes='';
346
-
347
-        if ($printer_location)
348
-        {
349
-            $this->meta->attributes .= chr(0x41) // textWithoutLanguage
350
-                                    . self::_giveMeStringLength('printer-location')
351
-                                    . 'printer-location'
352
-                                    . self::_giveMeStringLength($printer_location)
353
-                                    . $printer_location;
354
-        }
355
-
356
-        if ($printer_info)
357
-        {
358
-            $this->meta->attributes .= chr(0x41) // textWithoutLanguage
359
-                                    . self::_giveMeStringLength('printer-info')
360
-                                    . 'printer-info'
361
-                                    . self::_giveMeStringLength($printer_info)
362
-                                    . $printer_info;
363
-        }
364
-
365
-        for($i = 0 ; $i < count($attributes) ; $i++)
366
-        {
367
-            if ($i == 0)
368
-            {
369
-                $this->meta->attributes .= chr(0x44) // Keyword
370
-                                        . self::_giveMeStringLength('requested-attributes')
371
-                                        . 'requested-attributes'
372
-                                        . self::_giveMeStringLength($attributes[0])
373
-                                        . $attributes[0];
374
-            }
375
-            else
376
-            {
377
-                $this->meta->attributes .= chr(0x44) // Keyword
378
-                                        .  chr(0x0).chr(0x0) // zero-length name
379
-                                        .  self::_giveMeStringLength($attributes[$i])
380
-                                        .  $attributes[$i];
381
-            }
382
-        }
383
-
384
-        $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
385
-                         . chr(0x40). chr(0x02) // operation:  cups vendor extension: get printers
386
-                         . $this->meta->operation_id //           request-id
387
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
388
-                         . $this->meta->charset
389
-                         . $this->meta->language
390
-                         . $this->meta->attributes
391
-                         . chr(0x03); // end operations attribute
392
-
393
-        $this->output = $this->stringjob;
394
-
395
-        $post_values = array( "Content-Type" => "application/ipp",
396
-                              "Data" => $this->output);
397
-
398
-        if (self::_sendHttp ($post_values,'/'))
399
-        {
400
-
401
-            if(self::_parseServerOutput())
402
-            {
403
-                $this->_getAvailablePrinters();
404
-            }
405
-        }
406
-
407
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
408
-        {
409
-
410
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
411
-            if ($this->serveroutput->status == "successfull-ok")
412
-            {
413
-                self::_errorLog("getting printers: ".$this->serveroutput->status,3);
414
-            }
415
-            else
416
-            {
417
-                self::_errorLog("getting printers: ".$this->serveroutput->status,1);
418
-            }
419
-            return $this->serveroutput->status;
420
-        }
421
-        else
422
-        {
423
-            $this->status = array_merge($this->status,array("OPERATION FAILED"));
424
-            self::_errorLog("getting printers : OPERATION FAILED",1);
425
-        }
426
-        return false;
427
-    }
428
-
429
-
430
-    public function cupsGetPrinters ()
431
-    {
432
-        // alias for getPrinters();
433
-        self::getPrinters();
434
-    }
435
-
436
-
437
-    public function getPrinterAttributes()
438
-    {
439
-        // complete informations from parent with Cups-specific stuff
440
-
441
-        if(!$result = parent::getPrinterAttributes())
442
-        {
443
-            return FALSE;
444
-        }
445
-        if(!isset($this->printer_attributes))
446
-        {
447
-            return FALSE;
448
-        }
449
-
450
-        if (isset ($this->printer_attributes->printer_type))
451
-        {
452
-            $printer_type = $this->printer_attributes->printer_type->_value0;
453
-            $table = self::_interpretPrinterType($printer_type);
454
-
455
-            for($i = 0 ; $i < count($table) ; $i++ )
456
-            {
457
-                $index = '_value'.$i;
458
-                $this->printer_attributes->printer_type->$index = $table[$i];
459
-            }
460
-        }
461
-
462
-        return $result;
463
-    }
58
+	public function cupsGetDefaults($attributes=array("all"))
59
+	{
60
+		//The CUPS-Get-Default operation returns the default printer URI and attributes
61
+
62
+		$this->jobs = array_merge($this->jobs,array(""));
63
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
64
+		$this->parsed = array();
65
+		unset($this->printer_attributes);
66
+
67
+		if (!isset($this->setup->charset))
68
+		{
69
+			self::setCharset();
70
+		}
71
+
72
+		if (!isset($this->setup->language))
73
+		{
74
+			self::setLanguage('en');
75
+		}
76
+
77
+		self::_setOperationId();
78
+
79
+		for($i = 0 ; $i < count($attributes) ; $i++)
80
+		{
81
+			if ($i == 0)
82
+			{
83
+				$this->meta->attributes = chr(0x44) // Keyword
84
+										. self::_giveMeStringLength('requested-attributes')
85
+										. 'requested-attributes'
86
+										. self::_giveMeStringLength($attributes[0])
87
+										. $attributes[0];
88
+			}
89
+			else
90
+			{
91
+				$this->meta->attributes .= chr(0x44) // Keyword
92
+										.  chr(0x0).chr(0x0) // zero-length name
93
+										.  self::_giveMeStringLength($attributes[$i])
94
+										.  $attributes[$i];
95
+			}
96
+		}
97
+
98
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
99
+						 . chr(0x40). chr(0x01) // operation:  cups vendor extension: get defaults
100
+						 . $this->meta->operation_id // request-id
101
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
102
+						 . $this->meta->charset
103
+						 . $this->meta->language
104
+						 . $this->meta->attributes
105
+						 . chr(0x03); // end operations attribute
106
+
107
+		$this->output = $this->stringjob;
108
+
109
+		self::_putDebug("Request: ".$this->output);
110
+
111
+		$post_values = array( "Content-Type" => "application/ipp",
112
+							  "Data" => $this->output);
113
+
114
+		if (self::_sendHttp ($post_values,'/'))
115
+		{
116
+
117
+			if(self::_parseServerOutput())
118
+			{
119
+				self::_parsePrinterAttributes();
120
+			}
121
+		}
122
+
123
+	   $this->attributes = &$this->printer_attributes;
124
+
125
+	   if (isset($this->printer_attributes->printer_type))
126
+	   {
127
+					$printer_type = $this->printer_attributes->printer_type->_value0;
128
+					$table = self::_interpretPrinterType($printer_type);
129
+
130
+					for($i = 0 ; $i < count($table) ; $i++ )
131
+					{
132
+						$index = '_value'.$i;
133
+						$this->printer_attributes->printer_type->$index = $table[$i];
134
+						}
135
+					}
136
+
137
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
138
+		{
139
+
140
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
141
+			if ($this->serveroutput->status == "successfull-ok")
142
+			{
143
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
144
+			}
145
+			else
146
+			{
147
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
148
+			}
149
+
150
+			return $this->serveroutput->status;
151
+		}
152
+		else
153
+		{
154
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
155
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
156
+			}
157
+	return false;
158
+	}
159
+
160
+
161
+	public function cupsAcceptJobs($printer_uri)
162
+	{
163
+	//The CUPS-Get-Default operation returns the default printer URI and attributes
164
+
165
+		$this->jobs = array_merge($this->jobs,array(""));
166
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
167
+		$this->parsed = array();
168
+		unset($this->printer_attributes);
169
+
170
+		if (!isset($this->setup->charset))
171
+		{
172
+			self::setCharset();
173
+		}
174
+
175
+		if (!isset($this->setup->language))
176
+		{
177
+			self::setLanguage('en');
178
+		}
179
+
180
+		self::_setOperationId();
181
+
182
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
183
+						 . chr(0x40). chr(0x08) // operation:  cups vendor extension: Accept-Jobs
184
+						 . $this->meta->operation_id // request-id
185
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
186
+						 . $this->meta->charset
187
+						 . $this->meta->language
188
+						 . chr(0x45) // uri
189
+						 . self::_giveMeStringLength('printer-uri')
190
+						 . 'printer-uri'
191
+						 . self::_giveMeStringLength($printer_uri)
192
+						 . $printer_uri
193
+						 . chr(0x03); // end operations attribute
194
+
195
+		$this->output = $this->stringjob;
196
+
197
+		self::_putDebug("Request: ".$this->output);
198
+
199
+		$post_values = array( "Content-Type" => "application/ipp",
200
+							  "Data" => $this->output);
201
+
202
+		if (self::_sendHttp ($post_values,'/admin/'))
203
+		{
204
+
205
+			if(self::_parseServerOutput())
206
+			{
207
+				self::_parseAttributes();
208
+			}
209
+		}
210
+
211
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
212
+		{
213
+
214
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
215
+			if ($this->serveroutput->status == "successfull-ok")
216
+			{
217
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
218
+			}
219
+			else
220
+			{
221
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
222
+			}
223
+
224
+			return $this->serveroutput->status;
225
+		}
226
+		else
227
+		{
228
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
229
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
230
+			}
231
+	return false;
232
+	}
233
+
234
+
235
+	public function cupsRejectJobs($printer_uri,$printer_state_message)
236
+	{
237
+	//The CUPS-Get-Default operation returns the default printer URI and attributes
238
+
239
+		$this->jobs = array_merge($this->jobs,array(""));
240
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
241
+		$this->parsed = array();
242
+		unset($this->attributes);
243
+
244
+		if (!isset($this->setup->charset))
245
+		{
246
+			self::setCharset();
247
+		}
248
+
249
+		if (!isset($this->setup->language))
250
+		{
251
+			self::setLanguage('en');
252
+		}
253
+
254
+		self::_setOperationId();
255
+
256
+		$message = "";
257
+		if ($printer_state_message)
258
+		{
259
+			$message = chr(0x04) // start printer-attributes
260
+					 . chr(0x41) // textWithoutLanguage
261
+					 . self::_giveMeStringLength("printer-state-message")
262
+					 . "printer-state-message"
263
+					 . self::_giveMeStringLength($printer_state_message)
264
+					 . $printer_state_message;
265
+		}
266
+
267
+	   $this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
268
+						 . chr(0x40). chr(0x09) // operation:  cups vendor extension: Reject-Jobs
269
+						 . $this->meta->operation_id // request-id
270
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
271
+						 . $this->meta->charset
272
+						 . $this->meta->language
273
+						 . chr(0x45) // uri
274
+						 . self::_giveMeStringLength('printer-uri')
275
+						 . 'printer-uri'
276
+						 . self::_giveMeStringLength($printer_uri)
277
+						 . $printer_uri
278
+						 . $message
279
+						 . chr(0x03); // end operations attribute
280
+
281
+		$this->output = $this->stringjob;
282
+
283
+		self::_putDebug("Request: ".$this->output);
284
+
285
+		$post_values = array( "Content-Type" => "application/ipp",
286
+							  "Data" => $this->output);
287
+
288
+		if (self::_sendHttp ($post_values,'/admin/'))
289
+		{
290
+
291
+			if(self::_parseServerOutput())
292
+			{
293
+				self::_parseAttributes();
294
+			}
295
+		}
296
+
297
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
298
+		{
299
+
300
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
301
+			if ($this->serveroutput->status == "successfull-ok")
302
+			{
303
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,3);
304
+			}
305
+			else
306
+			{
307
+				self::_errorLog("getting defaults: ".$this->serveroutput->status,1);
308
+			}
309
+
310
+			return $this->serveroutput->status;
311
+		}
312
+		else
313
+		{
314
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
315
+			self::_errorLog("getting defaults : OPERATION FAILED",1);
316
+		}
317
+		return false;
318
+	}
319
+
320
+
321
+	public function getPrinters($printer_location=false,$printer_info=false,$attributes=array())
322
+	{
323
+		if (count($attributes) == 0)
324
+		{
325
+			true;
326
+		}
327
+		$attributes=array('printer-uri-supported', 'printer-location', 'printer-info', 'printer-type', 'color-supported', 'printer-name');
328
+		$this->jobs = array_merge($this->jobs,array(""));
329
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
330
+
331
+		unset ($this->printers_attributes);
332
+
333
+		if (!isset($this->setup->charset))
334
+		{
335
+			self::setCharset();
336
+		}
337
+
338
+		if (!isset($this->setup->language))
339
+		{
340
+			self::setLanguage('en-us');
341
+		}
342
+
343
+		self::_setOperationId();
344
+
345
+		$this->meta->attributes='';
346
+
347
+		if ($printer_location)
348
+		{
349
+			$this->meta->attributes .= chr(0x41) // textWithoutLanguage
350
+									. self::_giveMeStringLength('printer-location')
351
+									. 'printer-location'
352
+									. self::_giveMeStringLength($printer_location)
353
+									. $printer_location;
354
+		}
355
+
356
+		if ($printer_info)
357
+		{
358
+			$this->meta->attributes .= chr(0x41) // textWithoutLanguage
359
+									. self::_giveMeStringLength('printer-info')
360
+									. 'printer-info'
361
+									. self::_giveMeStringLength($printer_info)
362
+									. $printer_info;
363
+		}
364
+
365
+		for($i = 0 ; $i < count($attributes) ; $i++)
366
+		{
367
+			if ($i == 0)
368
+			{
369
+				$this->meta->attributes .= chr(0x44) // Keyword
370
+										. self::_giveMeStringLength('requested-attributes')
371
+										. 'requested-attributes'
372
+										. self::_giveMeStringLength($attributes[0])
373
+										. $attributes[0];
374
+			}
375
+			else
376
+			{
377
+				$this->meta->attributes .= chr(0x44) // Keyword
378
+										.  chr(0x0).chr(0x0) // zero-length name
379
+										.  self::_giveMeStringLength($attributes[$i])
380
+										.  $attributes[$i];
381
+			}
382
+		}
383
+
384
+		$this->stringjob = chr(0x01) . chr(0x01) // IPP version 1.1
385
+						 . chr(0x40). chr(0x02) // operation:  cups vendor extension: get printers
386
+						 . $this->meta->operation_id //           request-id
387
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
388
+						 . $this->meta->charset
389
+						 . $this->meta->language
390
+						 . $this->meta->attributes
391
+						 . chr(0x03); // end operations attribute
392
+
393
+		$this->output = $this->stringjob;
394
+
395
+		$post_values = array( "Content-Type" => "application/ipp",
396
+							  "Data" => $this->output);
397
+
398
+		if (self::_sendHttp ($post_values,'/'))
399
+		{
400
+
401
+			if(self::_parseServerOutput())
402
+			{
403
+				$this->_getAvailablePrinters();
404
+			}
405
+		}
406
+
407
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
408
+		{
409
+
410
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
411
+			if ($this->serveroutput->status == "successfull-ok")
412
+			{
413
+				self::_errorLog("getting printers: ".$this->serveroutput->status,3);
414
+			}
415
+			else
416
+			{
417
+				self::_errorLog("getting printers: ".$this->serveroutput->status,1);
418
+			}
419
+			return $this->serveroutput->status;
420
+		}
421
+		else
422
+		{
423
+			$this->status = array_merge($this->status,array("OPERATION FAILED"));
424
+			self::_errorLog("getting printers : OPERATION FAILED",1);
425
+		}
426
+		return false;
427
+	}
428
+
429
+
430
+	public function cupsGetPrinters ()
431
+	{
432
+		// alias for getPrinters();
433
+		self::getPrinters();
434
+	}
435
+
436
+
437
+	public function getPrinterAttributes()
438
+	{
439
+		// complete informations from parent with Cups-specific stuff
440
+
441
+		if(!$result = parent::getPrinterAttributes())
442
+		{
443
+			return FALSE;
444
+		}
445
+		if(!isset($this->printer_attributes))
446
+		{
447
+			return FALSE;
448
+		}
449
+
450
+		if (isset ($this->printer_attributes->printer_type))
451
+		{
452
+			$printer_type = $this->printer_attributes->printer_type->_value0;
453
+			$table = self::_interpretPrinterType($printer_type);
454
+
455
+			for($i = 0 ; $i < count($table) ; $i++ )
456
+			{
457
+				$index = '_value'.$i;
458
+				$this->printer_attributes->printer_type->$index = $table[$i];
459
+			}
460
+		}
461
+
462
+		return $result;
463
+	}
464 464
 
465 465
 //
466 466
 // SETUP
467 467
 //
468
-    protected function _initTags ()
469
-    {
470
-        // override parent with specific cups attributes
471
-
472
-        $operation_tags = array ();
473
-        $this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
474
-
475
-        $job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
476
-                            "blackplot" => array("tag" => "boolean"),
477
-                            "brightness" => array("tag" => "integer"),
478
-                            "columns" => array("tag" => "integer"),
479
-                            "cpi" => array("tag" => "enum"),
480
-                            "fitplot" => array("tag" => "boolean"),
481
-                            "gamma" => array("tag" => "integer"),
482
-                            "hue" => array("tag" => "integer"),
483
-                            "lpi" => array("tag" => "enum"),
484
-                            "mirror" => array("tag","boolean"),
485
-                            "natural-scaling" => array("tag" => "integer"),
486
-                            "number-up-layout" => array("tag" => "keyword"),
487
-                            "page-border" => array("tag" => "keyword"),
488
-                            "page-bottom" => array("tag" => "integer"),
489
-                            "page-label" => array("tag" => "textWithoutLanguage"),
490
-                            "page-left" => array("tag" => "integer"),
491
-                            "page-right" => array("tag" => "integer"),
492
-                            "page-set" => array("tag" => "keyword"),
493
-                            "page-top" => array("tag" => "integer"),
494
-                            "penwidth" => array("tag" => "integer"),
495
-                            "position" => array("tag" => "keyword"),
496
-                            "ppi" => array("tag" => "integer"),
497
-                            "prettyprint" => array("tag","boolean"),
498
-                            "saturation" => array("tag" => "integer"),
499
-                            "scaling" => array("tag" => "integer"),
500
-                            "wrap" => array("tag","boolean"),
501
-
502
-                            );
503
-        $this->job_tags = array_merge ($this->job_tags, $job_tags);
504
-    }
505
-
506
-    //
507
-    // REQUEST BUILDING
508
-    //
509
-    protected function _enumBuild ($tag,$value)
510
-    {
511
-        $value_built = parent::_enumBuild($tag,$value);
512
-
513
-        switch ($tag)
514
-        {
515
-           case "cpi":
516
-                switch ($value)
517
-                {
518
-                    case '10':
519
-                        $value_built = chr(10);
520
-                        break;
521
-                    case '12':
522
-                        $value_built = chr(12);
523
-                        break;
524
-                    case '17':
525
-                        $value_built = chr(17);
526
-                        break;
527
-                    default:
528
-                        $value_built = chr(10);
529
-                }
530
-            break;
531
-            case "lpi":
532
-                switch ($value)
533
-                {
534
-                    case '6':
535
-                        $value_built = chr(6);
536
-                        break;
537
-                    case '8':
538
-                        $value_built = chr(8);
539
-                        break;
540
-                    default:
541
-                        $value_built = chr(6);
542
-                }
543
-            break;
544
-            }
545
-
546
-        $prepend = '';
547
-        while ((strlen($value_built) + strlen($prepend)) < 4)
548
-            $prepend .= chr(0);
549
-        return $prepend.$value_built;
550
-    }
551
-
552
-    //
553
-    // RESPONSE PARSING
554
-    //
555
-    private function _getAvailablePrinters ()
556
-    {
557
-        $this->available_printers = array();
558
-        $this->printer_map = array();
559
-        $k = 0;
560
-        $this->printers_attributes = new \stdClass();
561
-
562
-        for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
563
-        {
564
-            if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes")
565
-            {
566
-                $phpname = "_printer".$k;
567
-                $this->printers_attributes->$phpname = new \stdClass();
568
-                for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
569
-                {
570
-
571
-                    $value = $this->serveroutput->response[$i][$j]['value'];
572
-                    $name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
573
-
574
-                    switch ($name)
575
-                    {
576
-                        case "printer_uri_supported":
577
-                            $this->available_printers = array_merge($this->available_printers,array($value));
578
-                            break;
579
-                        case "printer_type":
580
-                            $table = self::_interpretPrinterType($value);
581
-                            $this->printers_attributes->$phpname->$name = new \stdClass();
582
-
583
-                            for($l = 0 ; $l < count($table) ; $l++ )
584
-                            {
585
-                                $index = '_value'.$l;
586
-                                $this->printers_attributes->$phpname->$name->$index = $table[$l];
587
-                            }
588
-
589
-                            break;
590
-                        case '':
591
-                            break;
592
-                        case 'printer_name':
593
-                            $this->printer_map[$value] = $k;
594
-                            break;
595
-                        default:
596
-                            $this->printers_attributes->$phpname->$name = $value;
597
-                            break;
598
-                    }
599
-                }
600
-                $k ++;
601
-            }
602
-        }
603
-    }
604
-
605
-    protected function _getEnumVendorExtensions ($value_parsed)
606
-    {
607
-        switch ($value_parsed)
608
-        {
609
-            case 0x4002:
610
-                $value = 'Get-Availables-Printers';
611
-                break;
612
-            default:
613
-                $value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
614
-                break;
615
-        }
616
-
617
-        if (isset($value))
618
-        {
619
-            return ($value);
620
-        }
621
-
622
-        return sprintf('Unknown: 0x%x',$value_parsed);
623
-    }
624
-
625
-
626
-    private function _interpretPrinterType($value)
627
-    {
628
-        $value_parsed = 0;
629
-        for ($i = strlen($value) ; $i > 0 ; $i --)
630
-        {
631
-            $value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
632
-        }
633
-
634
-        $type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
635
-        $type[6] = $type[7] = $type[8] = $type[9] = $type[10] = '';
636
-        $type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
637
-        $type[16] = $type[17] = $type[18] = $type[19] = '';
638
-
639
-        if ($value_parsed %2 == 1)
640
-        {
641
-            $type[0] = 'printer-class';
642
-            $value_parsed -= 1;
643
-        }
644
-
645
-        if ($value_parsed %4 == 2 )
646
-        {
647
-            $type[1] = 'remote-destination';
648
-            $value_parsed -= 2;
649
-        }
650
-
651
-        if ($value_parsed %8 == 4 )
652
-        {
653
-            $type[2] = 'print-black';
654
-            $value_parsed -= 4;
655
-        }
656
-
657
-        if ($value_parsed %16 == 8 )
658
-        {
659
-            $type[3] = 'print-color';
660
-            $value_parsed -= 8;
661
-        }
662
-
663
-        if ($value_parsed %32 == 16)
664
-        {
665
-            $type[4] = 'hardware-print-on-both-sides';
666
-            $value_parsed -= 16;
667
-        }
668
-
669
-        if ($value_parsed %64 == 32)
670
-        {
671
-            $type[5] = 'hardware-staple-output';
672
-            $value_parsed -= 32;
673
-        }
674
-
675
-        if ($value_parsed %128 == 64)
676
-        {
677
-            $type[6] = 'hardware-fast-copies';
678
-            $value_parsed -= 64;
679
-        }
680
-
681
-        if ($value_parsed %256 == 128)
682
-        {
683
-            $type[7] = 'hardware-fast-copy-collation';
684
-            $value_parsed -= 128;
685
-        }
686
-
687
-        if ($value_parsed %512 == 256)
688
-        {
689
-            $type[8] = 'punch-output';
690
-            $value_parsed -= 256;
691
-        }
692
-
693
-        if ($value_parsed %1024 == 512)
694
-        {
695
-            $type[9] = 'cover-output';
696
-            $value_parsed -= 512;
697
-        }
698
-
699
-        if ($value_parsed %2048 == 1024)
700
-        {
701
-            $type[10] = 'bind-output';
702
-            $value_parsed -= 1024;
703
-        }
704
-
705
-        if ($value_parsed %4096 == 2048)
706
-        {
707
-            $type[11] = 'sort-output';
708
-            $value_parsed -= 2048;
709
-        }
710
-
711
-        if ($value_parsed %8192 == 4096)
712
-        {
713
-            $type[12] = 'handle-media-up-to-US-Legal-A4';
714
-            $value_parsed -= 4096;
715
-        }
716
-
717
-        if ($value_parsed %16384 == 8192)
718
-        {
719
-            $type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
720
-            $value_parsed -= 8192;
721
-        }
722
-
723
-        if ($value_parsed %32768 == 16384)
724
-        {
725
-            $type[14] = 'handle-media-larger-than-ISO_C-A2';
726
-            $value_parsed -= 16384;
727
-        }
728
-
729
-        if ($value_parsed %65536 == 32768)
730
-        {
731
-            $type[15] = 'handle-user-defined-media-sizes';
732
-            $value_parsed -= 32768;
733
-        }
734
-
735
-        if ($value_parsed %131072 == 65536)
736
-        {
737
-            $type[16] = 'implicit-server-generated-class';
738
-            $value_parsed -= 65536;
739
-        }
740
-
741
-        if ($value_parsed %262144 == 131072)
742
-        {
743
-            $type[17] = 'network-default-printer';
744
-            $value_parsed -= 131072;
745
-        }
746
-
747
-        if ($value_parsed %524288 == 262144)
748
-        {
749
-            $type[18] = 'fax-device';
750
-            $value_parsed -= 262144;
751
-        }
752
-
753
-        return $type;
754
-    }
755
-
756
-
757
-    protected function _interpretEnum($attribute_name,$value)
758
-    {
759
-        $value_parsed = self::_interpretInteger($value);
760
-
761
-        switch ($attribute_name)
762
-        {
763
-            case 'cpi':
764
-            case 'lpi':
765
-                $value = $value_parsed;
766
-                break;
767
-            default:
768
-                $value = parent::_interpretEnum($attribute_name,$value);
769
-                break;
770
-        }
771
-
772
-        return $value;
773
-    }
468
+	protected function _initTags ()
469
+	{
470
+		// override parent with specific cups attributes
471
+
472
+		$operation_tags = array ();
473
+		$this->operation_tags = array_merge ($this->operation_tags, $operation_tags);
474
+
475
+		$job_tags = array ( "job-billing" => array("tag" => "textWithoutLanguage"),
476
+							"blackplot" => array("tag" => "boolean"),
477
+							"brightness" => array("tag" => "integer"),
478
+							"columns" => array("tag" => "integer"),
479
+							"cpi" => array("tag" => "enum"),
480
+							"fitplot" => array("tag" => "boolean"),
481
+							"gamma" => array("tag" => "integer"),
482
+							"hue" => array("tag" => "integer"),
483
+							"lpi" => array("tag" => "enum"),
484
+							"mirror" => array("tag","boolean"),
485
+							"natural-scaling" => array("tag" => "integer"),
486
+							"number-up-layout" => array("tag" => "keyword"),
487
+							"page-border" => array("tag" => "keyword"),
488
+							"page-bottom" => array("tag" => "integer"),
489
+							"page-label" => array("tag" => "textWithoutLanguage"),
490
+							"page-left" => array("tag" => "integer"),
491
+							"page-right" => array("tag" => "integer"),
492
+							"page-set" => array("tag" => "keyword"),
493
+							"page-top" => array("tag" => "integer"),
494
+							"penwidth" => array("tag" => "integer"),
495
+							"position" => array("tag" => "keyword"),
496
+							"ppi" => array("tag" => "integer"),
497
+							"prettyprint" => array("tag","boolean"),
498
+							"saturation" => array("tag" => "integer"),
499
+							"scaling" => array("tag" => "integer"),
500
+							"wrap" => array("tag","boolean"),
501
+
502
+							);
503
+		$this->job_tags = array_merge ($this->job_tags, $job_tags);
504
+	}
505
+
506
+	//
507
+	// REQUEST BUILDING
508
+	//
509
+	protected function _enumBuild ($tag,$value)
510
+	{
511
+		$value_built = parent::_enumBuild($tag,$value);
512
+
513
+		switch ($tag)
514
+		{
515
+		   case "cpi":
516
+				switch ($value)
517
+				{
518
+					case '10':
519
+						$value_built = chr(10);
520
+						break;
521
+					case '12':
522
+						$value_built = chr(12);
523
+						break;
524
+					case '17':
525
+						$value_built = chr(17);
526
+						break;
527
+					default:
528
+						$value_built = chr(10);
529
+				}
530
+			break;
531
+			case "lpi":
532
+				switch ($value)
533
+				{
534
+					case '6':
535
+						$value_built = chr(6);
536
+						break;
537
+					case '8':
538
+						$value_built = chr(8);
539
+						break;
540
+					default:
541
+						$value_built = chr(6);
542
+				}
543
+			break;
544
+			}
545
+
546
+		$prepend = '';
547
+		while ((strlen($value_built) + strlen($prepend)) < 4)
548
+			$prepend .= chr(0);
549
+		return $prepend.$value_built;
550
+	}
551
+
552
+	//
553
+	// RESPONSE PARSING
554
+	//
555
+	private function _getAvailablePrinters ()
556
+	{
557
+		$this->available_printers = array();
558
+		$this->printer_map = array();
559
+		$k = 0;
560
+		$this->printers_attributes = new \stdClass();
561
+
562
+		for ($i = 0 ; (array_key_exists($i,$this->serveroutput->response)) ; $i ++)
563
+		{
564
+			if (($this->serveroutput->response[$i]['attributes']) == "printer-attributes")
565
+			{
566
+				$phpname = "_printer".$k;
567
+				$this->printers_attributes->$phpname = new \stdClass();
568
+				for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
569
+				{
570
+
571
+					$value = $this->serveroutput->response[$i][$j]['value'];
572
+					$name = str_replace("-","_",$this->serveroutput->response[$i][$j]['name']);
573
+
574
+					switch ($name)
575
+					{
576
+						case "printer_uri_supported":
577
+							$this->available_printers = array_merge($this->available_printers,array($value));
578
+							break;
579
+						case "printer_type":
580
+							$table = self::_interpretPrinterType($value);
581
+							$this->printers_attributes->$phpname->$name = new \stdClass();
582
+
583
+							for($l = 0 ; $l < count($table) ; $l++ )
584
+							{
585
+								$index = '_value'.$l;
586
+								$this->printers_attributes->$phpname->$name->$index = $table[$l];
587
+							}
588
+
589
+							break;
590
+						case '':
591
+							break;
592
+						case 'printer_name':
593
+							$this->printer_map[$value] = $k;
594
+							break;
595
+						default:
596
+							$this->printers_attributes->$phpname->$name = $value;
597
+							break;
598
+					}
599
+				}
600
+				$k ++;
601
+			}
602
+		}
603
+	}
604
+
605
+	protected function _getEnumVendorExtensions ($value_parsed)
606
+	{
607
+		switch ($value_parsed)
608
+		{
609
+			case 0x4002:
610
+				$value = 'Get-Availables-Printers';
611
+				break;
612
+			default:
613
+				$value = sprintf('Unknown(Cups extension for operations): 0x%x',$value_parsed);
614
+				break;
615
+		}
616
+
617
+		if (isset($value))
618
+		{
619
+			return ($value);
620
+		}
621
+
622
+		return sprintf('Unknown: 0x%x',$value_parsed);
623
+	}
624
+
625
+
626
+	private function _interpretPrinterType($value)
627
+	{
628
+		$value_parsed = 0;
629
+		for ($i = strlen($value) ; $i > 0 ; $i --)
630
+		{
631
+			$value_parsed += pow(256,($i - 1)) * ord($value[strlen($value) - $i]);
632
+		}
633
+
634
+		$type[0] = $type[1] = $type[2] = $type[3] = $type[4] = $type[5] = '';
635
+		$type[6] = $type[7] = $type[8] = $type[9] = $type[10] = '';
636
+		$type[11] = $type[12] = $type[13] = $type[14] = $type[15] = '';
637
+		$type[16] = $type[17] = $type[18] = $type[19] = '';
638
+
639
+		if ($value_parsed %2 == 1)
640
+		{
641
+			$type[0] = 'printer-class';
642
+			$value_parsed -= 1;
643
+		}
644
+
645
+		if ($value_parsed %4 == 2 )
646
+		{
647
+			$type[1] = 'remote-destination';
648
+			$value_parsed -= 2;
649
+		}
650
+
651
+		if ($value_parsed %8 == 4 )
652
+		{
653
+			$type[2] = 'print-black';
654
+			$value_parsed -= 4;
655
+		}
656
+
657
+		if ($value_parsed %16 == 8 )
658
+		{
659
+			$type[3] = 'print-color';
660
+			$value_parsed -= 8;
661
+		}
662
+
663
+		if ($value_parsed %32 == 16)
664
+		{
665
+			$type[4] = 'hardware-print-on-both-sides';
666
+			$value_parsed -= 16;
667
+		}
668
+
669
+		if ($value_parsed %64 == 32)
670
+		{
671
+			$type[5] = 'hardware-staple-output';
672
+			$value_parsed -= 32;
673
+		}
674
+
675
+		if ($value_parsed %128 == 64)
676
+		{
677
+			$type[6] = 'hardware-fast-copies';
678
+			$value_parsed -= 64;
679
+		}
680
+
681
+		if ($value_parsed %256 == 128)
682
+		{
683
+			$type[7] = 'hardware-fast-copy-collation';
684
+			$value_parsed -= 128;
685
+		}
686
+
687
+		if ($value_parsed %512 == 256)
688
+		{
689
+			$type[8] = 'punch-output';
690
+			$value_parsed -= 256;
691
+		}
692
+
693
+		if ($value_parsed %1024 == 512)
694
+		{
695
+			$type[9] = 'cover-output';
696
+			$value_parsed -= 512;
697
+		}
698
+
699
+		if ($value_parsed %2048 == 1024)
700
+		{
701
+			$type[10] = 'bind-output';
702
+			$value_parsed -= 1024;
703
+		}
704
+
705
+		if ($value_parsed %4096 == 2048)
706
+		{
707
+			$type[11] = 'sort-output';
708
+			$value_parsed -= 2048;
709
+		}
710
+
711
+		if ($value_parsed %8192 == 4096)
712
+		{
713
+			$type[12] = 'handle-media-up-to-US-Legal-A4';
714
+			$value_parsed -= 4096;
715
+		}
716
+
717
+		if ($value_parsed %16384 == 8192)
718
+		{
719
+			$type[13] = 'handle-media-between-US-Legal-A4-and-ISO_C-A2';
720
+			$value_parsed -= 8192;
721
+		}
722
+
723
+		if ($value_parsed %32768 == 16384)
724
+		{
725
+			$type[14] = 'handle-media-larger-than-ISO_C-A2';
726
+			$value_parsed -= 16384;
727
+		}
728
+
729
+		if ($value_parsed %65536 == 32768)
730
+		{
731
+			$type[15] = 'handle-user-defined-media-sizes';
732
+			$value_parsed -= 32768;
733
+		}
734
+
735
+		if ($value_parsed %131072 == 65536)
736
+		{
737
+			$type[16] = 'implicit-server-generated-class';
738
+			$value_parsed -= 65536;
739
+		}
740
+
741
+		if ($value_parsed %262144 == 131072)
742
+		{
743
+			$type[17] = 'network-default-printer';
744
+			$value_parsed -= 131072;
745
+		}
746
+
747
+		if ($value_parsed %524288 == 262144)
748
+		{
749
+			$type[18] = 'fax-device';
750
+			$value_parsed -= 262144;
751
+		}
752
+
753
+		return $type;
754
+	}
755
+
756
+
757
+	protected function _interpretEnum($attribute_name,$value)
758
+	{
759
+		$value_parsed = self::_interpretInteger($value);
760
+
761
+		switch ($attribute_name)
762
+		{
763
+			case 'cpi':
764
+			case 'lpi':
765
+				$value = $value_parsed;
766
+				break;
767
+			default:
768
+				$value = parent::_interpretEnum($attribute_name,$value);
769
+				break;
770
+		}
771
+
772
+		return $value;
773
+	}
774 774
 }
775 775
\ No newline at end of file
Please login to merge, or discard this patch.
htdocs/includes/printipp/PrintIPP.php 1 patch
Indentation   +1976 added lines, -1976 removed lines patch added patch discarded remove patch
@@ -44,1944 +44,1944 @@  discard block
 block discarded – undo
44 44
 
45 45
 class PrintIPP extends BasicIPP
46 46
 {
47
-    public function __construct()
48
-    {
49
-        parent::__construct();
50
-    }
47
+	public function __construct()
48
+	{
49
+		parent::__construct();
50
+	}
51 51
 
52 52
 // OPERATIONS
53
-    public function printJob()
54
-    {
55
-        self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
56
-
57
-        if (!$this->_stringJob())
58
-        {
59
-            return FALSE;
60
-        }
61
-
62
-        if (is_readable($this->data))
63
-        {
64
-            self::_putDebug( _("Printing a FILE\n"),3); 
65
-
66
-            $this->output = $this->stringjob;
67
-
68
-            if ($this->setup->datatype == "TEXT")
69
-            {
70
-                $this->output .= chr(0x16);
71
-            }
72
-
73
-            $post_values = array( "Content-Type" => "application/ipp",
74
-                                  "Data" => $this->output,
75
-                                  "File" => $this->data);
76
-
77
-            if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
78
-            {
79
-                $post_values = array_merge($post_values,array("Filetype"=>"TEXT"));
80
-            }
81
-        }
82
-        else
83
-        {
84
-            self::_putDebug( _("Printing DATA\n"),3); 
85
-
86
-            $this->output = $this->stringjob;
87
-            $this->output .= $this->datahead;    
88
-            $this->output .= $this->data;
89
-            $this->output .= $this->datatail;
53
+	public function printJob()
54
+	{
55
+		self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
56
+
57
+		if (!$this->_stringJob())
58
+		{
59
+			return FALSE;
60
+		}
61
+
62
+		if (is_readable($this->data))
63
+		{
64
+			self::_putDebug( _("Printing a FILE\n"),3); 
65
+
66
+			$this->output = $this->stringjob;
67
+
68
+			if ($this->setup->datatype == "TEXT")
69
+			{
70
+				$this->output .= chr(0x16);
71
+			}
72
+
73
+			$post_values = array( "Content-Type" => "application/ipp",
74
+								  "Data" => $this->output,
75
+								  "File" => $this->data);
76
+
77
+			if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
78
+			{
79
+				$post_values = array_merge($post_values,array("Filetype"=>"TEXT"));
80
+			}
81
+		}
82
+		else
83
+		{
84
+			self::_putDebug( _("Printing DATA\n"),3); 
85
+
86
+			$this->output = $this->stringjob;
87
+			$this->output .= $this->datahead;    
88
+			$this->output .= $this->data;
89
+			$this->output .= $this->datatail;
90 90
             
91
-            $post_values = array( "Content-Type" => "application/ipp",
92
-                                  "Data" => $this->output);
93
-        }
94
-
95
-        if (self::_sendHttp ($post_values,$this->paths['printers']))
96
-        {
97
-            if(self::_parseServerOutput())
98
-            {
99
-                $this->_getJobId();
100
-                $this->_getJobUri();
101
-                $this->_parseJobAttributes();
102
-            }
103
-            else
104
-            {
105
-                $this->jobs = array_merge($this->jobs,array(''));
106
-                $this->jobs_uri = array_merge($this->jobs_uri,array(''));
107
-                }
108
-            }
109
-
110
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
111
-        {
112
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
113
-
114
-            if ($this->serveroutput->status == "successfull-ok")
115
-            {
116
-              self::_errorLog(sprintf("printing job %s: ",$this->last_job) .$this->serveroutput->status,3);
117
-            }
118
-            else
119
-            {
120
-                $this->jobs = array_merge($this->jobs,array(""));
121
-                $this->jobs_uri = array_merge($this->jobs_uri,array(""));
122
-                self::_errorLog(sprintf("printing job: ",$this->last_job) .$this->serveroutput->status,1);
123
-                if ($this->with_exceptions)
124
-                {
125
-                    throw new ippException(sprintf("job status: %s",
126
-                    $this->serveroutput->status));
127
-                }
128
-            }
129
-            return $this->serveroutput->status; 
130
-        }
131
-
132
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
133
-        $this->jobs = array_merge($this->jobs,array(""));
134
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
135
-        self::_errorLog("printing job : OPERATION FAILED",1);
136
-
137
-        return false;
138
-    }
139
-
140
-    public function cancelJob ($job_uri)
141
-    {
142
-        $this->jobs = array_merge($this->jobs,array(""));
143
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
144
-
145
-        self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
146
-
147
-        if (!$this->_stringCancel($job_uri))
148
-        {
149
-            return FALSE;
150
-        }
151
-
152
-        self::_putDebug( _("Cancelling Job $job_uri\n"),3); 
153
-
154
-        $this->output = $this->stringjob;
155
-
156
-        $post_values = array( "Content-Type"=>"application/ipp",
157
-                              "Data"=>$this->output);
158
-
159
-        if (self::_sendHttp ($post_values,$this->paths['jobs']))
160
-        {
161
-            self::_parseServerOutput();
162
-        }
163
-
164
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
165
-        {
166
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
167
-
168
-            if ($this->serveroutput->status == "successfull-ok")
169
-            {
170
-                self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,3);
171
-            }
172
-            else
173
-            {
174
-                self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,1);
175
-            }
176
-            return $this->serveroutput->status; 
177
-        }
178
-
179
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
180
-        self::_errorLog("cancelling job : OPERATION FAILED",3);
181
-
182
-        return false;
183
-    }
184
-
185
-    public function validateJob ()
186
-    {
187
-        $this->jobs = array_merge($this->jobs,array(""));
188
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
189
-
190
-        $this->serveroutput->response = '';
191
-
192
-        self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
193
-
194
-        self::_putDebug( _("Validate Job\n"),2); 
195
-
196
-        if (!isset($this->setup->charset))
197
-        {
198
-            self::setCharset();
199
-        }
200
-        if (!isset($this->setup->datatype))
201
-        {
202
-            self::setBinary();
203
-        }
204
-
205
-        if (!isset($this->setup->uri))
206
-        {
207
-            $this->getPrinters();
208
-            unset($this->jobs[count($this->jobs) - 1]);
209
-            unset($this->jobs_uri[count($this->jobs_uri) - 1]);
210
-            unset($this->status[count($this->status) - 1]);
211
-
212
-            if (array_key_exists(0,$this->available_printers))
213
-            {
214
-               self::setPrinterURI($this->available_printers[0]);
215
-            }
216
-            else
217
-            {
218
-                trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
219
-                self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
220
-                self::_errorLog(" Printer URI is not set, die",2);
221
-                return FALSE;
222
-                }
223
-            }
224
-
225
-        if (!isset($this->meta->copies))
226
-        {
227
-            self::setCopies(1);
228
-        }
229
-
230
-        if (!isset($this->setup->copies))
231
-        {
232
-            self::setCopies(1);
233
-        }
234
-
235
-        if (!isset($this->setup->language))
236
-        {
237
-            self::setLanguage('en_us');
238
-        }
239
-
240
-        if (!isset($this->setup->mime_media_type))
241
-        {
242
-            self::setMimeMediaType();
243
-        }
244
-
245
-        if ($this->setup->datatype != "TEXT")
246
-        {
247
-            unset ($this->setup->mime_media_type);
248
-        }
249
-
250
-        if (!isset($this->setup->jobname))
251
-        {
252
-            if (is_readable($this->data))
253
-            {
254
-                self::setJobName(basename($this->data),true);
255
-            }
256
-            else
257
-            {
258
-                self::setJobName();
259
-            }
260
-        }
261
-        unset($this->setup->jobname);
262
-
263
-        if (!isset($this->meta->username))
264
-        {
265
-            self::setUserName();
266
-        }
267
-
268
-        if (!isset($this->meta->fidelity))
269
-        {
270
-            $this->meta->fidelity = '';
271
-        }
272
-
273
-        if (!isset($this->meta->document_name))
274
-        {
275
-            $this->meta->document_name = '';
276
-        }
277
-
278
-        if (!isset($this->meta->sides))
279
-        {
280
-            $this->meta->sides = '';
281
-        }
282
-
283
-        if (!isset($this->meta->page_ranges))
284
-        {
285
-            $this->meta->page_ranges = '';
286
-        }
287
-
288
-        $jobattributes = '';
289
-        $operationattributes = '';
290
-        $printerattributes = '';
291
-        self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
292
-
293
-        self::_setOperationId();
294
-
295
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
296
-                         . chr(0x00) . chr (0x04) // Validate-Job | operation-id
297
-                         . $this->meta->operation_id //           request-id
298
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
299
-                         . $this->meta->charset
300
-                         . $this->meta->language
301
-                         . $this->meta->printer_uri
302
-                         . $this->meta->username
303
-                         . $this->meta->jobname
304
-                         . $this->meta->fidelity
305
-                         . $this->meta->document_name
306
-                         . $this->meta->mime_media_type
307
-                         . $operationattributes
308
-                         . chr(0x02) // start job-attributes | job-attributes-tag
309
-                         . $this->meta->copies
310
-                         . $this->meta->sides
311
-                         . $this->meta->page_ranges
312
-                         . $jobattributes
313
-                         . chr(0x03); // end-of-attributes | end-of-attributes-tag
314
-
315
-        self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
316
-
317
-        $this->output = $this->stringjob;
318
-
319
-        $post_values = array( "Content-Type"=>"application/ipp",
320
-                              "Data"=>$this->output);
321
-
322
-        if (self::_sendHttp ($post_values,$this->paths['printers']))
323
-        {
324
-            if(self::_parseServerOutput())
325
-            {
326
-                self::_parseAttributes();
327
-            }
328
-        }
329
-
330
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
331
-        {
332
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
333
-
334
-            if ($this->serveroutput->status == "successfull-ok")
335
-            {
336
-                self::_errorLog("validate job: ".$this->serveroutput->status,3);
337
-            }
338
-            else
339
-            {
340
-                self::_errorLog("validate job: ".$this->serveroutput->status,1);
341
-            }
342
-            return $this->serveroutput->status; 
343
-        }
344
-
345
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
346
-        self::_errorLog("validate job : OPERATION FAILED",3);
347
-
348
-        return false;
349
-    }
350
-
351
-    public function getPrinterAttributes()
352
-    {
353
-        $this->jobs = array_merge($this->jobs,array(""));
354
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
355
-
356
-        $jobattributes = '';
357
-        $operationattributes = '';
358
-        self::_buildValues($operationattributes,$jobattributes,$printerattributes);
359
-        self::_setOperationId();
360
-        $this->parsed = array();
361
-        unset($this->printer_attributes);
362
-
363
-        if (!isset($this->setup->uri))
364
-        {
365
-            $this->getPrinters();
366
-            unset($this->jobs[count($this->jobs) - 1]);
367
-            unset($this->jobs_uri[count($this->jobs_uri) - 1]);
368
-            unset($this->status[count($this->status) - 1]);
369
-
370
-            if (array_key_exists(0,$this->available_printers))
371
-            {
372
-               self::setPrinterURI($this->available_printers[0]);
373
-            }
374
-            else
375
-            {
376
-                trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
377
-                self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
378
-                self::_errorLog(" Printer URI is not set, die",2);
379
-                return FALSE;
380
-                }
381
-            }
382
-
383
-        if (!isset($this->setup->charset))
384
-        {
385
-            self::setCharset();
386
-        }
387
-
388
-        if (!isset($this->setup->language))
389
-        {
390
-            self::setLanguage('en_us');
391
-        }
392
-
393
-        if (!isset($this->meta->username))
394
-        {
395
-            self::setUserName();
396
-        }
397
-
398
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
399
-                         . chr(0x00) . chr (0x0b) // Print-URI | operation-id
400
-                         . $this->meta->operation_id //           request-id
401
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
402
-                         . $this->meta->charset
403
-                         . $this->meta->language
404
-                         . $this->meta->printer_uri
405
-                         . $this->meta->username
406
-                         . $printerattributes
407
-                         . chr(0x03); // end-of-attributes | end-of-attributes-tag
408
-
409
-        self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
410
-
411
-        self::_putDebug(sprintf(_("Getting printer attributes of %s\n"),$this->printer_uri),2); 
412
-
413
-        $this->output = $this->stringjob;
414
-
415
-        $post_values = array( "Content-Type"=>"application/ipp",
416
-                              "Data"=>$this->output);
417
-
418
-        if (self::_sendHttp ($post_values,$this->paths['root']))
419
-        {
420
-            if (self::_parseServerOutput())
421
-            {
422
-                self::_parsePrinterAttributes(); 
423
-            }
424
-        }
425
-
426
-        $this->attributes = &$this->printer_attributes;
427
-
428
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
429
-        {
430
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
431
-
432
-            if  ($this->serveroutput->status == "successfull-ok")
433
-            {
434
-                self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
435
-                                                                        $this->serveroutput->status),3);
436
-            }
437
-            else 
438
-            {
439
-                self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
440
-                                                                        $this->serveroutput->status),1);
441
-            }
442
-
443
-            return $this->serveroutput->status;
444
-        }
445
-
446
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
447
-        self::_errorLog(date("Y-m-d H:i:s : ")
448
-            .basename($_SERVER['PHP_SELF'])
449
-            .sprintf(_("getting printer's attributes of %s : OPERATION FAILED"),
450
-                $this->printer_uri),3);
451
-
452
-        return false;
453
-    }
454
-
455
-    public function getJobs($my_jobs=true,$limit=0,$which_jobs="not-completed",$subset=false)
456
-    {
457
-        $this->jobs = array_merge($this->jobs,array(""));
458
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
459
-
460
-        self::_setOperationId();
461
-        $this->parsed = array();
462
-        unset($this->printer_attributes);
463
-
464
-        if (!isset($this->setup->uri))
465
-        {
466
-            $this->getPrinters();
467
-            unset($this->jobs[count($this->jobs) - 1]);
468
-            unset($this->jobs_uri[count($this->jobs_uri) - 1]);
469
-            unset($this->status[count($this->status) - 1]);
470
-
471
-            if (array_key_exists(0,$this->available_printers))
472
-            {
473
-               self::setPrinterURI($this->available_printers[0]);
474
-            }
475
-            else
476
-            {
477
-                trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
478
-                self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
479
-                self::_errorLog("getJobs: Printer URI is not set, die",2);
480
-                return FALSE;
481
-                }
482
-            }
483
-
484
-        if (!isset($this->setup->charset))
485
-        {
486
-            self::setCharset();
487
-        }
488
-
489
-        if (!isset($this->setup->language))
490
-        {
491
-            self::setLanguage('en_us');
492
-        }
493
-
494
-        if (!isset($this->meta->username))
495
-        {
496
-            self::setUserName();
497
-        }
498
-
499
-        if ($limit)
500
-        {
501
-            $limit = self::_integerBuild($limit);
502
-            $this->meta->limit = chr(0x21) // integer
503
-                               . self::_giveMeStringLength('limit')
504
-                               . 'limit'
505
-                               . self::_giveMeStringLength($limit)
506
-                               . $limit;
507
-        }
508
-        else
509
-        {
510
-            $this->meta->limit = '';
511
-        }
512
-
513
-        if ($which_jobs == 'completed')
514
-        {
515
-                $this->meta->which_jobs = chr(0x44) // keyword
516
-                                        . self::_giveMeStringLength('which-jobs')
517
-                                        . 'which-jobs'
518
-                                        . self::_giveMeStringLength($which_jobs)
519
-                                        . $which_jobs;
520
-        }
521
-        else
522
-        {
523
-            $this->meta->which_jobs = "";
524
-        }
525
-
526
-        if ($my_jobs)
527
-        {
528
-            $this->meta->my_jobs = chr(0x22) // boolean
529
-                                 . self::_giveMeStringLength('my-jobs')
530
-                                 . 'my-jobs'
531
-                                 . self::_giveMeStringLength(chr(0x01))
532
-                                 . chr(0x01);
533
-        }
534
-        else
535
-        {
536
-            $this->meta->my_jobs = '';
537
-        }
538
-
539
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
540
-                         . chr(0x00) . chr (0x0A) // Get-Jobs | operation-id
541
-                         . $this->meta->operation_id //           request-id
542
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
543
-                         . $this->meta->charset
544
-                         . $this->meta->language
545
-                         . $this->meta->printer_uri
546
-                         . $this->meta->username
547
-                         . $this->meta->limit
548
-                         . $this->meta->which_jobs 
549
-                         . $this->meta->my_jobs;
550
-       if ($subset)
551
-       {
552
-           $this->stringjob .=
553
-                          chr(0x44) // keyword
554
-                         . self::_giveMeStringLength('requested-attributes')
555
-                         . 'requested-attributes'
556
-                         . self::_giveMeStringLength('job-uri')
557
-                         . 'job-uri'
558
-                         . chr(0x44) // keyword
559
-                         . self::_giveMeStringLength('')
560
-                         . ''
561
-                         . self::_giveMeStringLength('job-name')
562
-                         . 'job-name'
563
-                         . chr(0x44) // keyword
564
-                         . self::_giveMeStringLength('')
565
-                         . ''
566
-                         . self::_giveMeStringLength('job-state')
567
-                         . 'job-state'
568
-                         . chr(0x44) // keyword
569
-                         . self::_giveMeStringLength('')
570
-                         . ''
571
-                         . self::_giveMeStringLength('job-state-reason')
572
-                         . 'job-state-reason';
573
-        }
574
-        else
575
-        { # cups 1.4.4 doesn't return much of anything without this
576
-            $this->stringjob .=
577
-                          chr(0x44) // keyword
578
-                         . self::_giveMeStringLength('requested-attributes')
579
-                         . 'requested-attributes'
580
-                         . self::_giveMeStringLength('all')
581
-                         . 'all';
582
-        }
583
-        $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
584
-
585
-        self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
586
-
587
-        self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); 
588
-
589
-        $this->output = $this->stringjob;
590
-
591
-        $post_values = array( "Content-Type"=>"application/ipp",
592
-                              "Data"=>$this->output);
593
-
594
-        if (self::_sendHttp ($post_values,$this->paths['jobs']))
595
-        {
596
-            if (self::_parseServerOutput())
597
-            {
598
-                self::_parseJobsAttributes();
599
-            }
600
-        }
601
-
602
-        $this->attributes = &$this->jobs_attributes;
603
-
604
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
605
-        {
606
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
607
-
608
-            if ($this->serveroutput->status == "successfull-ok")
609
-            {
610
-                self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
611
-                            .$this->serveroutput->status,3);
612
-            }
613
-            else
614
-            {
615
-                 self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
616
-                                             .$this->serveroutput->status,1);
617
-            }
618
-
619
-            return $this->serveroutput->status;
620
-        }
621
-
622
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
623
-        self::_errorLog(date("Y-m-d H:i:s : ")
624
-                        .basename($_SERVER['PHP_SELF'])
625
-                        .sprintf(_("getting jobs of %s : OPERATION FAILED"),
626
-                                     $this->printer_uri),3);
627
-
628
-    return false;
629
-    }
630
-
631
-
632
-    public function getJobAttributes($job_uri,$subset=false,$attributes_group="all")
633
-    {
634
-        $this->jobs = array_merge($this->jobs,array(""));
635
-        $this->jobs_uri = array_merge($this->jobs_uri,array(""));
636
-
637
-        if (!$job_uri)
638
-        {
639
-            trigger_error(_("getJobAttributes: Job URI is not set, die."));
640
-            return FALSE;
641
-            }
642
-
643
-        self::_setOperationId();
644
-        $this->parsed = array();
645
-        unset($this->printer_attributes);
646
-
647
-        if (!isset($this->setup->uri))
648
-        {
649
-            $this->getPrinters();
650
-            unset($this->jobs[count($this->jobs) - 1]);
651
-            unset($this->jobs_uri[count($this->jobs_uri) - 1]);
652
-            unset($this->status[count($this->status) - 1]);
653
-
654
-            if (array_key_exists(0,$this->available_printers))
655
-            {
656
-               self::setPrinterURI($this->available_printers[0]);
657
-            }
658
-            else
659
-            {
660
-                trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
661
-                self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
662
-                self::_errorLog("getJobs: Printer URI is not set, die",2);
663
-                return FALSE;
664
-            }
665
-        }
666
-
667
-        if (!isset($this->setup->charset))
668
-        {
669
-            self::setCharset();
670
-        }
671
-
672
-        if (!isset($this->setup->language))
673
-        {
674
-            self::setLanguage('en_us');
675
-        }
676
-
677
-        if (!isset($this->meta->username))
678
-        {
679
-            self::setUserName();
680
-        }
681
-
682
-        $this->meta->job_uri = chr(0x45) // URI
683
-                             . self::_giveMeStringLength('job-uri')
684
-                             . 'job-uri'
685
-                             . self::_giveMeStringLength($job_uri)
686
-                             . $job_uri;
687
-
688
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
689
-                         . chr(0x00) . chr (0x09) // Get-Job-Attributes | operation-id
690
-                         . $this->meta->operation_id //           request-id
691
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
692
-                         . $this->meta->charset
693
-                         . $this->meta->language
694
-                         . $this->meta->job_uri
695
-                         . $this->meta->username;
696
-        if ($subset)
697
-        {
698
-            $this->stringjob .=
699
-                          chr(0x44) // keyword
700
-                         . self::_giveMeStringLength('requested-attributes')
701
-                         . 'requested-attributes'
702
-                         . self::_giveMeStringLength('job-uri')
703
-                         . 'job-uri'
704
-                         . chr(0x44) // keyword
705
-                         . self::_giveMeStringLength('')
706
-                         . ''
707
-                         . self::_giveMeStringLength('job-name')
708
-                         . 'job-name'
709
-                         . chr(0x44) // keyword
710
-                         . self::_giveMeStringLength('')
711
-                         . ''
712
-                         . self::_giveMeStringLength('job-state')
713
-                         . 'job-state'
714
-                         . chr(0x44) // keyword
715
-                         . self::_giveMeStringLength('')
716
-                         . ''
717
-                         . self::_giveMeStringLength('job-state-reason')
718
-                         . 'job-state-reason';
719
-        }
720
-        elseif($attributes_group)
721
-        {
722
-            switch($attributes_group)
723
-            {
724
-                case 'job-template':
725
-                    break;
726
-                case 'job-description':
727
-                    break;
728
-                case 'all':
729
-                    break;
730
-                default:
731
-                    trigger_error(_('not a valid attribute group: ').$attributes_group,E_USER_NOTICE);
732
-                    $attributes_group = '';
733
-                    break;
734
-            }
735
-            $this->stringjob .=
736
-                          chr(0x44) // keyword
737
-                         . self::_giveMeStringLength('requested-attributes')
738
-                         . 'requested-attributes'
739
-                         . self::_giveMeStringLength($attributes_group)
740
-                         . $attributes_group;
741
-        }
742
-        $this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
743
-
744
-        self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
745
-
746
-        self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); 
747
-
748
-        $this->output = $this->stringjob;
749
-
750
-        $post_values = array( "Content-Type"=>"application/ipp",
751
-                              "Data"=>$this->output);
752
-
753
-        if (self::_sendHttp ($post_values,$this->paths['jobs']))
754
-        {
755
-            if (self::_parseServerOutput())
756
-            {
757
-                self::_parseJobAttributes();
758
-            }
759
-        }
760
-
761
-        $this->attributes = &$this->job_attributes;
762
-
763
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
764
-        {
765
-            $this->status = array_merge($this->status,array($this->serveroutput->status));
766
-
767
-            if ($this->serveroutput->status == "successfull-ok")
768
-            {
769
-                self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
770
-                            .$this->serveroutput->status,3);
771
-            }
772
-            else
773
-            {
774
-                 self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
775
-                                             .$this->serveroutput->status,1);
776
-            }
777
-
778
-            return $this->serveroutput->status;
779
-        }
780
-
781
-        $this->status = array_merge($this->status,array("OPERATION FAILED"));
782
-        self::_errorLog(date("Y-m-d H:i:s : ")
783
-                        .basename($_SERVER['PHP_SELF'])
784
-                        .sprintf(_("getting jobs attributes of %s : OPERATION FAILED"),
785
-                                     $job_uri),3);
786
-
787
-        return false;
788
-    }
789
-
790
-    public function getPrinters()
791
-    {
792
-        // placeholder for vendor extension operation (getAvailablePrinters for CUPS)
793
-        $this->jobs = array_merge($this->jobs,array(''));
794
-        $this->jobs_uri = array_merge($this->jobs_uri,array(''));
795
-        $this->status = array_merge($this->status,array(''));    
796
-    }
797
-
798
-    public function generateError ($error)
799
-    {
800
-        switch ($error)
801
-        {
802
-            case "request_body_malformed":
803
-                $this->error_generation->request_body_malformed = chr(0xFF);
804
-                break;
805
-            default:
806
-                true;
807
-                break;
808
-        }
809
-
810
-        trigger_error(sprintf(_('Setting Error %s'),$error),E_USER_NOTICE);
811
-    }
91
+			$post_values = array( "Content-Type" => "application/ipp",
92
+								  "Data" => $this->output);
93
+		}
94
+
95
+		if (self::_sendHttp ($post_values,$this->paths['printers']))
96
+		{
97
+			if(self::_parseServerOutput())
98
+			{
99
+				$this->_getJobId();
100
+				$this->_getJobUri();
101
+				$this->_parseJobAttributes();
102
+			}
103
+			else
104
+			{
105
+				$this->jobs = array_merge($this->jobs,array(''));
106
+				$this->jobs_uri = array_merge($this->jobs_uri,array(''));
107
+				}
108
+			}
109
+
110
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
111
+		{
112
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
113
+
114
+			if ($this->serveroutput->status == "successfull-ok")
115
+			{
116
+			  self::_errorLog(sprintf("printing job %s: ",$this->last_job) .$this->serveroutput->status,3);
117
+			}
118
+			else
119
+			{
120
+				$this->jobs = array_merge($this->jobs,array(""));
121
+				$this->jobs_uri = array_merge($this->jobs_uri,array(""));
122
+				self::_errorLog(sprintf("printing job: ",$this->last_job) .$this->serveroutput->status,1);
123
+				if ($this->with_exceptions)
124
+				{
125
+					throw new ippException(sprintf("job status: %s",
126
+					$this->serveroutput->status));
127
+				}
128
+			}
129
+			return $this->serveroutput->status; 
130
+		}
131
+
132
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
133
+		$this->jobs = array_merge($this->jobs,array(""));
134
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
135
+		self::_errorLog("printing job : OPERATION FAILED",1);
136
+
137
+		return false;
138
+	}
139
+
140
+	public function cancelJob ($job_uri)
141
+	{
142
+		$this->jobs = array_merge($this->jobs,array(""));
143
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
144
+
145
+		self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
146
+
147
+		if (!$this->_stringCancel($job_uri))
148
+		{
149
+			return FALSE;
150
+		}
151
+
152
+		self::_putDebug( _("Cancelling Job $job_uri\n"),3); 
153
+
154
+		$this->output = $this->stringjob;
155
+
156
+		$post_values = array( "Content-Type"=>"application/ipp",
157
+							  "Data"=>$this->output);
158
+
159
+		if (self::_sendHttp ($post_values,$this->paths['jobs']))
160
+		{
161
+			self::_parseServerOutput();
162
+		}
163
+
164
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
165
+		{
166
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
167
+
168
+			if ($this->serveroutput->status == "successfull-ok")
169
+			{
170
+				self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,3);
171
+			}
172
+			else
173
+			{
174
+				self::_errorLog("cancelling job $job_uri: ".$this->serveroutput->status,1);
175
+			}
176
+			return $this->serveroutput->status; 
177
+		}
178
+
179
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
180
+		self::_errorLog("cancelling job : OPERATION FAILED",3);
181
+
182
+		return false;
183
+	}
184
+
185
+	public function validateJob ()
186
+	{
187
+		$this->jobs = array_merge($this->jobs,array(""));
188
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
189
+
190
+		$this->serveroutput->response = '';
191
+
192
+		self::_putDebug( sprintf("*************************\nDate: %s\n*************************\n\n",date('Y-m-d H:i:s')));
193
+
194
+		self::_putDebug( _("Validate Job\n"),2); 
195
+
196
+		if (!isset($this->setup->charset))
197
+		{
198
+			self::setCharset();
199
+		}
200
+		if (!isset($this->setup->datatype))
201
+		{
202
+			self::setBinary();
203
+		}
204
+
205
+		if (!isset($this->setup->uri))
206
+		{
207
+			$this->getPrinters();
208
+			unset($this->jobs[count($this->jobs) - 1]);
209
+			unset($this->jobs_uri[count($this->jobs_uri) - 1]);
210
+			unset($this->status[count($this->status) - 1]);
211
+
212
+			if (array_key_exists(0,$this->available_printers))
213
+			{
214
+			   self::setPrinterURI($this->available_printers[0]);
215
+			}
216
+			else
217
+			{
218
+				trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
219
+				self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
220
+				self::_errorLog(" Printer URI is not set, die",2);
221
+				return FALSE;
222
+				}
223
+			}
224
+
225
+		if (!isset($this->meta->copies))
226
+		{
227
+			self::setCopies(1);
228
+		}
229
+
230
+		if (!isset($this->setup->copies))
231
+		{
232
+			self::setCopies(1);
233
+		}
234
+
235
+		if (!isset($this->setup->language))
236
+		{
237
+			self::setLanguage('en_us');
238
+		}
239
+
240
+		if (!isset($this->setup->mime_media_type))
241
+		{
242
+			self::setMimeMediaType();
243
+		}
244
+
245
+		if ($this->setup->datatype != "TEXT")
246
+		{
247
+			unset ($this->setup->mime_media_type);
248
+		}
249
+
250
+		if (!isset($this->setup->jobname))
251
+		{
252
+			if (is_readable($this->data))
253
+			{
254
+				self::setJobName(basename($this->data),true);
255
+			}
256
+			else
257
+			{
258
+				self::setJobName();
259
+			}
260
+		}
261
+		unset($this->setup->jobname);
262
+
263
+		if (!isset($this->meta->username))
264
+		{
265
+			self::setUserName();
266
+		}
267
+
268
+		if (!isset($this->meta->fidelity))
269
+		{
270
+			$this->meta->fidelity = '';
271
+		}
272
+
273
+		if (!isset($this->meta->document_name))
274
+		{
275
+			$this->meta->document_name = '';
276
+		}
277
+
278
+		if (!isset($this->meta->sides))
279
+		{
280
+			$this->meta->sides = '';
281
+		}
282
+
283
+		if (!isset($this->meta->page_ranges))
284
+		{
285
+			$this->meta->page_ranges = '';
286
+		}
287
+
288
+		$jobattributes = '';
289
+		$operationattributes = '';
290
+		$printerattributes = '';
291
+		self::_buildValues ($operationattributes,$jobattributes,$printerattributes);
292
+
293
+		self::_setOperationId();
294
+
295
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
296
+						 . chr(0x00) . chr (0x04) // Validate-Job | operation-id
297
+						 . $this->meta->operation_id //           request-id
298
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
299
+						 . $this->meta->charset
300
+						 . $this->meta->language
301
+						 . $this->meta->printer_uri
302
+						 . $this->meta->username
303
+						 . $this->meta->jobname
304
+						 . $this->meta->fidelity
305
+						 . $this->meta->document_name
306
+						 . $this->meta->mime_media_type
307
+						 . $operationattributes
308
+						 . chr(0x02) // start job-attributes | job-attributes-tag
309
+						 . $this->meta->copies
310
+						 . $this->meta->sides
311
+						 . $this->meta->page_ranges
312
+						 . $jobattributes
313
+						 . chr(0x03); // end-of-attributes | end-of-attributes-tag
314
+
315
+		self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
316
+
317
+		$this->output = $this->stringjob;
318
+
319
+		$post_values = array( "Content-Type"=>"application/ipp",
320
+							  "Data"=>$this->output);
321
+
322
+		if (self::_sendHttp ($post_values,$this->paths['printers']))
323
+		{
324
+			if(self::_parseServerOutput())
325
+			{
326
+				self::_parseAttributes();
327
+			}
328
+		}
329
+
330
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
331
+		{
332
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
333
+
334
+			if ($this->serveroutput->status == "successfull-ok")
335
+			{
336
+				self::_errorLog("validate job: ".$this->serveroutput->status,3);
337
+			}
338
+			else
339
+			{
340
+				self::_errorLog("validate job: ".$this->serveroutput->status,1);
341
+			}
342
+			return $this->serveroutput->status; 
343
+		}
344
+
345
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
346
+		self::_errorLog("validate job : OPERATION FAILED",3);
347
+
348
+		return false;
349
+	}
350
+
351
+	public function getPrinterAttributes()
352
+	{
353
+		$this->jobs = array_merge($this->jobs,array(""));
354
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
355
+
356
+		$jobattributes = '';
357
+		$operationattributes = '';
358
+		self::_buildValues($operationattributes,$jobattributes,$printerattributes);
359
+		self::_setOperationId();
360
+		$this->parsed = array();
361
+		unset($this->printer_attributes);
362
+
363
+		if (!isset($this->setup->uri))
364
+		{
365
+			$this->getPrinters();
366
+			unset($this->jobs[count($this->jobs) - 1]);
367
+			unset($this->jobs_uri[count($this->jobs_uri) - 1]);
368
+			unset($this->status[count($this->status) - 1]);
369
+
370
+			if (array_key_exists(0,$this->available_printers))
371
+			{
372
+			   self::setPrinterURI($this->available_printers[0]);
373
+			}
374
+			else
375
+			{
376
+				trigger_error(_("_stringJob: Printer URI is not set: die"),E_USER_WARNING);
377
+				self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
378
+				self::_errorLog(" Printer URI is not set, die",2);
379
+				return FALSE;
380
+				}
381
+			}
382
+
383
+		if (!isset($this->setup->charset))
384
+		{
385
+			self::setCharset();
386
+		}
387
+
388
+		if (!isset($this->setup->language))
389
+		{
390
+			self::setLanguage('en_us');
391
+		}
392
+
393
+		if (!isset($this->meta->username))
394
+		{
395
+			self::setUserName();
396
+		}
397
+
398
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
399
+						 . chr(0x00) . chr (0x0b) // Print-URI | operation-id
400
+						 . $this->meta->operation_id //           request-id
401
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
402
+						 . $this->meta->charset
403
+						 . $this->meta->language
404
+						 . $this->meta->printer_uri
405
+						 . $this->meta->username
406
+						 . $printerattributes
407
+						 . chr(0x03); // end-of-attributes | end-of-attributes-tag
408
+
409
+		self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
410
+
411
+		self::_putDebug(sprintf(_("Getting printer attributes of %s\n"),$this->printer_uri),2); 
412
+
413
+		$this->output = $this->stringjob;
414
+
415
+		$post_values = array( "Content-Type"=>"application/ipp",
416
+							  "Data"=>$this->output);
417
+
418
+		if (self::_sendHttp ($post_values,$this->paths['root']))
419
+		{
420
+			if (self::_parseServerOutput())
421
+			{
422
+				self::_parsePrinterAttributes(); 
423
+			}
424
+		}
425
+
426
+		$this->attributes = &$this->printer_attributes;
427
+
428
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
429
+		{
430
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
431
+
432
+			if  ($this->serveroutput->status == "successfull-ok")
433
+			{
434
+				self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
435
+																		$this->serveroutput->status),3);
436
+			}
437
+			else 
438
+			{
439
+				self::_errorLog(sprintf(_("getting printer attributes of %s: %s"),$this->printer_uri,
440
+																		$this->serveroutput->status),1);
441
+			}
442
+
443
+			return $this->serveroutput->status;
444
+		}
445
+
446
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
447
+		self::_errorLog(date("Y-m-d H:i:s : ")
448
+			.basename($_SERVER['PHP_SELF'])
449
+			.sprintf(_("getting printer's attributes of %s : OPERATION FAILED"),
450
+				$this->printer_uri),3);
451
+
452
+		return false;
453
+	}
454
+
455
+	public function getJobs($my_jobs=true,$limit=0,$which_jobs="not-completed",$subset=false)
456
+	{
457
+		$this->jobs = array_merge($this->jobs,array(""));
458
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
459
+
460
+		self::_setOperationId();
461
+		$this->parsed = array();
462
+		unset($this->printer_attributes);
463
+
464
+		if (!isset($this->setup->uri))
465
+		{
466
+			$this->getPrinters();
467
+			unset($this->jobs[count($this->jobs) - 1]);
468
+			unset($this->jobs_uri[count($this->jobs_uri) - 1]);
469
+			unset($this->status[count($this->status) - 1]);
470
+
471
+			if (array_key_exists(0,$this->available_printers))
472
+			{
473
+			   self::setPrinterURI($this->available_printers[0]);
474
+			}
475
+			else
476
+			{
477
+				trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
478
+				self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
479
+				self::_errorLog("getJobs: Printer URI is not set, die",2);
480
+				return FALSE;
481
+				}
482
+			}
483
+
484
+		if (!isset($this->setup->charset))
485
+		{
486
+			self::setCharset();
487
+		}
488
+
489
+		if (!isset($this->setup->language))
490
+		{
491
+			self::setLanguage('en_us');
492
+		}
493
+
494
+		if (!isset($this->meta->username))
495
+		{
496
+			self::setUserName();
497
+		}
498
+
499
+		if ($limit)
500
+		{
501
+			$limit = self::_integerBuild($limit);
502
+			$this->meta->limit = chr(0x21) // integer
503
+							   . self::_giveMeStringLength('limit')
504
+							   . 'limit'
505
+							   . self::_giveMeStringLength($limit)
506
+							   . $limit;
507
+		}
508
+		else
509
+		{
510
+			$this->meta->limit = '';
511
+		}
512
+
513
+		if ($which_jobs == 'completed')
514
+		{
515
+				$this->meta->which_jobs = chr(0x44) // keyword
516
+										. self::_giveMeStringLength('which-jobs')
517
+										. 'which-jobs'
518
+										. self::_giveMeStringLength($which_jobs)
519
+										. $which_jobs;
520
+		}
521
+		else
522
+		{
523
+			$this->meta->which_jobs = "";
524
+		}
525
+
526
+		if ($my_jobs)
527
+		{
528
+			$this->meta->my_jobs = chr(0x22) // boolean
529
+								 . self::_giveMeStringLength('my-jobs')
530
+								 . 'my-jobs'
531
+								 . self::_giveMeStringLength(chr(0x01))
532
+								 . chr(0x01);
533
+		}
534
+		else
535
+		{
536
+			$this->meta->my_jobs = '';
537
+		}
538
+
539
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
540
+						 . chr(0x00) . chr (0x0A) // Get-Jobs | operation-id
541
+						 . $this->meta->operation_id //           request-id
542
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
543
+						 . $this->meta->charset
544
+						 . $this->meta->language
545
+						 . $this->meta->printer_uri
546
+						 . $this->meta->username
547
+						 . $this->meta->limit
548
+						 . $this->meta->which_jobs 
549
+						 . $this->meta->my_jobs;
550
+	   if ($subset)
551
+	   {
552
+		   $this->stringjob .=
553
+						  chr(0x44) // keyword
554
+						 . self::_giveMeStringLength('requested-attributes')
555
+						 . 'requested-attributes'
556
+						 . self::_giveMeStringLength('job-uri')
557
+						 . 'job-uri'
558
+						 . chr(0x44) // keyword
559
+						 . self::_giveMeStringLength('')
560
+						 . ''
561
+						 . self::_giveMeStringLength('job-name')
562
+						 . 'job-name'
563
+						 . chr(0x44) // keyword
564
+						 . self::_giveMeStringLength('')
565
+						 . ''
566
+						 . self::_giveMeStringLength('job-state')
567
+						 . 'job-state'
568
+						 . chr(0x44) // keyword
569
+						 . self::_giveMeStringLength('')
570
+						 . ''
571
+						 . self::_giveMeStringLength('job-state-reason')
572
+						 . 'job-state-reason';
573
+		}
574
+		else
575
+		{ # cups 1.4.4 doesn't return much of anything without this
576
+			$this->stringjob .=
577
+						  chr(0x44) // keyword
578
+						 . self::_giveMeStringLength('requested-attributes')
579
+						 . 'requested-attributes'
580
+						 . self::_giveMeStringLength('all')
581
+						 . 'all';
582
+		}
583
+		$this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
584
+
585
+		self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
586
+
587
+		self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); 
588
+
589
+		$this->output = $this->stringjob;
590
+
591
+		$post_values = array( "Content-Type"=>"application/ipp",
592
+							  "Data"=>$this->output);
593
+
594
+		if (self::_sendHttp ($post_values,$this->paths['jobs']))
595
+		{
596
+			if (self::_parseServerOutput())
597
+			{
598
+				self::_parseJobsAttributes();
599
+			}
600
+		}
601
+
602
+		$this->attributes = &$this->jobs_attributes;
603
+
604
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
605
+		{
606
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
607
+
608
+			if ($this->serveroutput->status == "successfull-ok")
609
+			{
610
+				self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
611
+							.$this->serveroutput->status,3);
612
+			}
613
+			else
614
+			{
615
+				 self::_errorLog(sprintf(_("getting jobs of printer %s: "),$this->printer_uri)
616
+											 .$this->serveroutput->status,1);
617
+			}
618
+
619
+			return $this->serveroutput->status;
620
+		}
621
+
622
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
623
+		self::_errorLog(date("Y-m-d H:i:s : ")
624
+						.basename($_SERVER['PHP_SELF'])
625
+						.sprintf(_("getting jobs of %s : OPERATION FAILED"),
626
+									 $this->printer_uri),3);
627
+
628
+	return false;
629
+	}
630
+
631
+
632
+	public function getJobAttributes($job_uri,$subset=false,$attributes_group="all")
633
+	{
634
+		$this->jobs = array_merge($this->jobs,array(""));
635
+		$this->jobs_uri = array_merge($this->jobs_uri,array(""));
636
+
637
+		if (!$job_uri)
638
+		{
639
+			trigger_error(_("getJobAttributes: Job URI is not set, die."));
640
+			return FALSE;
641
+			}
642
+
643
+		self::_setOperationId();
644
+		$this->parsed = array();
645
+		unset($this->printer_attributes);
646
+
647
+		if (!isset($this->setup->uri))
648
+		{
649
+			$this->getPrinters();
650
+			unset($this->jobs[count($this->jobs) - 1]);
651
+			unset($this->jobs_uri[count($this->jobs_uri) - 1]);
652
+			unset($this->status[count($this->status) - 1]);
653
+
654
+			if (array_key_exists(0,$this->available_printers))
655
+			{
656
+			   self::setPrinterURI($this->available_printers[0]);
657
+			}
658
+			else
659
+			{
660
+				trigger_error(_("getJobs: Printer URI is not set: die"),E_USER_WARNING);
661
+				self::_putDebug( _("_stringJob: Printer URI is not set: die\n"),3);
662
+				self::_errorLog("getJobs: Printer URI is not set, die",2);
663
+				return FALSE;
664
+			}
665
+		}
666
+
667
+		if (!isset($this->setup->charset))
668
+		{
669
+			self::setCharset();
670
+		}
671
+
672
+		if (!isset($this->setup->language))
673
+		{
674
+			self::setLanguage('en_us');
675
+		}
676
+
677
+		if (!isset($this->meta->username))
678
+		{
679
+			self::setUserName();
680
+		}
681
+
682
+		$this->meta->job_uri = chr(0x45) // URI
683
+							 . self::_giveMeStringLength('job-uri')
684
+							 . 'job-uri'
685
+							 . self::_giveMeStringLength($job_uri)
686
+							 . $job_uri;
687
+
688
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
689
+						 . chr(0x00) . chr (0x09) // Get-Job-Attributes | operation-id
690
+						 . $this->meta->operation_id //           request-id
691
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
692
+						 . $this->meta->charset
693
+						 . $this->meta->language
694
+						 . $this->meta->job_uri
695
+						 . $this->meta->username;
696
+		if ($subset)
697
+		{
698
+			$this->stringjob .=
699
+						  chr(0x44) // keyword
700
+						 . self::_giveMeStringLength('requested-attributes')
701
+						 . 'requested-attributes'
702
+						 . self::_giveMeStringLength('job-uri')
703
+						 . 'job-uri'
704
+						 . chr(0x44) // keyword
705
+						 . self::_giveMeStringLength('')
706
+						 . ''
707
+						 . self::_giveMeStringLength('job-name')
708
+						 . 'job-name'
709
+						 . chr(0x44) // keyword
710
+						 . self::_giveMeStringLength('')
711
+						 . ''
712
+						 . self::_giveMeStringLength('job-state')
713
+						 . 'job-state'
714
+						 . chr(0x44) // keyword
715
+						 . self::_giveMeStringLength('')
716
+						 . ''
717
+						 . self::_giveMeStringLength('job-state-reason')
718
+						 . 'job-state-reason';
719
+		}
720
+		elseif($attributes_group)
721
+		{
722
+			switch($attributes_group)
723
+			{
724
+				case 'job-template':
725
+					break;
726
+				case 'job-description':
727
+					break;
728
+				case 'all':
729
+					break;
730
+				default:
731
+					trigger_error(_('not a valid attribute group: ').$attributes_group,E_USER_NOTICE);
732
+					$attributes_group = '';
733
+					break;
734
+			}
735
+			$this->stringjob .=
736
+						  chr(0x44) // keyword
737
+						 . self::_giveMeStringLength('requested-attributes')
738
+						 . 'requested-attributes'
739
+						 . self::_giveMeStringLength($attributes_group)
740
+						 . $attributes_group;
741
+		}
742
+		$this->stringjob .= chr(0x03); // end-of-attributes | end-of-attributes-tag
743
+
744
+		self::_putDebug(sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
745
+
746
+		self::_putDebug(sprintf(_("getting jobs of %s\n"),$this->printer_uri),2); 
747
+
748
+		$this->output = $this->stringjob;
749
+
750
+		$post_values = array( "Content-Type"=>"application/ipp",
751
+							  "Data"=>$this->output);
752
+
753
+		if (self::_sendHttp ($post_values,$this->paths['jobs']))
754
+		{
755
+			if (self::_parseServerOutput())
756
+			{
757
+				self::_parseJobAttributes();
758
+			}
759
+		}
760
+
761
+		$this->attributes = &$this->job_attributes;
762
+
763
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
764
+		{
765
+			$this->status = array_merge($this->status,array($this->serveroutput->status));
766
+
767
+			if ($this->serveroutput->status == "successfull-ok")
768
+			{
769
+				self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
770
+							.$this->serveroutput->status,3);
771
+			}
772
+			else
773
+			{
774
+				 self::_errorLog(sprintf(_("getting job attributes for %s: "),$job_uri)
775
+											 .$this->serveroutput->status,1);
776
+			}
777
+
778
+			return $this->serveroutput->status;
779
+		}
780
+
781
+		$this->status = array_merge($this->status,array("OPERATION FAILED"));
782
+		self::_errorLog(date("Y-m-d H:i:s : ")
783
+						.basename($_SERVER['PHP_SELF'])
784
+						.sprintf(_("getting jobs attributes of %s : OPERATION FAILED"),
785
+									 $job_uri),3);
786
+
787
+		return false;
788
+	}
789
+
790
+	public function getPrinters()
791
+	{
792
+		// placeholder for vendor extension operation (getAvailablePrinters for CUPS)
793
+		$this->jobs = array_merge($this->jobs,array(''));
794
+		$this->jobs_uri = array_merge($this->jobs_uri,array(''));
795
+		$this->status = array_merge($this->status,array(''));    
796
+	}
797
+
798
+	public function generateError ($error)
799
+	{
800
+		switch ($error)
801
+		{
802
+			case "request_body_malformed":
803
+				$this->error_generation->request_body_malformed = chr(0xFF);
804
+				break;
805
+			default:
806
+				true;
807
+				break;
808
+		}
809
+
810
+		trigger_error(sprintf(_('Setting Error %s'),$error),E_USER_NOTICE);
811
+	}
812 812
     
813
-    public function resetError ($error)
814
-    {
815
-        unset ($this->error_generation->$error);
816
-        trigger_error(sprintf(_('Reset Error %s'),$error),E_USER_NOTICE);
817
-    }
818
-
819
-    // SETUP
820
-    protected function _setOperationId ()
821
-    {
822
-            $prepend = '';
823
-            $this->operation_id += 1;
824
-            $this->meta->operation_id = self::_integerBuild($this->operation_id);
825
-            self::_putDebug( "operation id is: ".$this->operation_id."\n",2);
826
-    }
813
+	public function resetError ($error)
814
+	{
815
+		unset ($this->error_generation->$error);
816
+		trigger_error(sprintf(_('Reset Error %s'),$error),E_USER_NOTICE);
817
+	}
818
+
819
+	// SETUP
820
+	protected function _setOperationId ()
821
+	{
822
+			$prepend = '';
823
+			$this->operation_id += 1;
824
+			$this->meta->operation_id = self::_integerBuild($this->operation_id);
825
+			self::_putDebug( "operation id is: ".$this->operation_id."\n",2);
826
+	}
827 827
     
828
-    protected function _setJobId()
829
-    {
830
-
831
-        $this->meta->jobid +=1;
832
-        $prepend = '';
833
-        $prepend_length = 4 - strlen($this->meta->jobid);
834
-        for ($i = 0; $i < $prepend_length ; $i++ )
835
-        {
836
-            $prepend .= '0';
837
-        }
838
-
839
-    return $prepend.$this->meta->jobid;
840
-    }
828
+	protected function _setJobId()
829
+	{
830
+
831
+		$this->meta->jobid +=1;
832
+		$prepend = '';
833
+		$prepend_length = 4 - strlen($this->meta->jobid);
834
+		for ($i = 0; $i < $prepend_length ; $i++ )
835
+		{
836
+			$prepend .= '0';
837
+		}
838
+
839
+	return $prepend.$this->meta->jobid;
840
+	}
841 841
     
842
-    protected function _setJobUri ($job_uri)
843
-    {
844
-        $this->meta->job_uri = chr(0x45) // type uri
845
-                             . chr(0x00).chr(0x07) // name-length
846
-                             . "job-uri"
847
-                             //. chr(0x00).chr(strlen($job_uri))
848
-                             . self::_giveMeStringLength($job_uri)
849
-                             . $job_uri;
842
+	protected function _setJobUri ($job_uri)
843
+	{
844
+		$this->meta->job_uri = chr(0x45) // type uri
845
+							 . chr(0x00).chr(0x07) // name-length
846
+							 . "job-uri"
847
+							 //. chr(0x00).chr(strlen($job_uri))
848
+							 . self::_giveMeStringLength($job_uri)
849
+							 . $job_uri;
850 850
         
851
-        self::_putDebug( "job-uri is: ".$job_uri."\n",2);
852
-    }
853
-
854
-    // RESPONSE PARSING
855
-    protected function _parsePrinterAttributes()
856
-    {
857
-        //if (!preg_match('#successful#',$this->serveroutput->status))
858
-        //   return false;
859
-
860
-        $k = -1;
861
-        $l = 0;
862
-        for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
863
-        {
864
-            for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
865
-            {
866
-                if (!empty($this->serveroutput->response[$i][$j]['name']))
867
-                {
868
-                    $k++;
869
-                    $l = 0;
870
-                    $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
871
-                    $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
872
-                    $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
873
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
874
-                }
875
-                else
876
-                {
877
-                    $l ++;
878
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
879
-                    }
880
-            }
881
-        }
882
-        $this->serveroutput->response = array();
883
-
884
-        $this->printer_attributes = new \stdClass();
885
-        for ($i = 0 ; $i < count($this->parsed) ; $i ++)
886
-        {
887
-                    $name = $this->parsed[$i]['name'];
888
-                    $php_name = str_replace('-','_',$name);
889
-                    $type = $this->parsed[$i]['type'];
890
-                    $range = $this->parsed[$i]['range'];
891
-                    $this->printer_attributes->$php_name = new \stdClass();
892
-                    $this->printer_attributes->$php_name->_type = $type;
893
-                    $this->printer_attributes->$php_name->_range = $range;
894
-                    for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
895
-                    {
896
-                        $value = $this->parsed[$i][$j];
897
-                        $index = '_value'.$j;
898
-                        $this->printer_attributes->$php_name->$index = $value;
899
-                        }
900
-                    }
901
-
902
-        $this->parsed = array();
903
-    }
904
-
905
-    protected function _parseJobsAttributes()
906
-    {
907
-        //if ($this->serveroutput->status != "successfull-ok")
908
-        //    return false;
909
-
910
-        $job = -1;
911
-        $l = 0;
912
-        for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
913
-        {
914
-            if ($this->serveroutput->response[$i]['attributes'] == "job-attributes")
915
-            {
916
-                $job ++;
917
-            }
918
-            $k = -1; 
919
-            for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
920
-            {
921
-                if (!empty($this->serveroutput->response[$i][$j]['name']))
922
-                {
923
-                    $k++;
924
-                    $l = 0;
925
-                    $this->parsed[$job][$k]['range'] = $this->serveroutput->response[$i]['attributes'];
926
-                    $this->parsed[$job][$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
927
-                    $this->parsed[$job][$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
928
-                    $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
929
-                }
930
-                else
931
-                {
932
-                    $l ++;
933
-                    $this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
934
-                }
935
-            }
936
-        }
937
-
938
-        $this->serveroutput->response = array();
939
-        $this->jobs_attributes = new \stdClass();
940
-        for ($job_nbr = 0 ; $job_nbr <= $job ; $job_nbr ++)
941
-        {
942
-            $job_index = "job_".$job_nbr;
943
-            $this->jobs_attributes->$job_index = new \stdClass();
944
-            for ($i = 0 ; $i < count($this->parsed[$job_nbr]) ; $i ++)
945
-            {
946
-                $name = $this->parsed[$job_nbr][$i]['name'];
947
-                $php_name = str_replace('-','_',$name);
948
-                $type = $this->parsed[$job_nbr][$i]['type'];
949
-                $range = $this->parsed[$job_nbr][$i]['range'];
950
-                $this->jobs_attributes->$job_index->$php_name = new \stdClass();
951
-                $this->jobs_attributes->$job_index->$php_name->_type = $type;
952
-                $this->jobs_attributes->$job_index->$php_name->_range = $range;
953
-                for ($j = 0 ; $j < (count($this->parsed[$job_nbr][$i]) - 3) ; $j ++)
954
-                {
955
-                    # This causes incorrect parsing of integer job attributes.
956
-                    # 2010-08-16
957
-                    # bpkroth
958
-                    #$value = self::_interpretAttribute($name,$type,$this->parsed[$job_nbr][$i][$j]);
959
-                    $value = $this->parsed[$job_nbr][$i][$j];
960
-                    $index = '_value'.$j;
961
-                    $this->jobs_attributes->$job_index->$php_name->$index = $value;
962
-                }
963
-            }
964
-        }
965
-
966
-        $this->parsed = array();
967
-    }
968
-
969
-    protected function _readAttribute($attributes_type)
970
-    {
971
-        $tag = ord($this->serveroutput->body[$this->_parsing->offset]);
972
-
973
-        $this->_parsing->offset += 1;
974
-        $j = $this->index;
975
-
976
-        $tag = self::_readTag($tag);
977
-
978
-        switch ($tag)
979
-        {
980
-            case "begCollection": //RFC3382 (BLIND CODE)
981
-                if ($this->end_collection)
982
-                {
983
-                    $this->index --;
984
-                }
985
-                $this->end_collection = false;
986
-                $this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
987
-                self::_putDebug( "tag is: begCollection\n");
988
-                self::_readAttributeName ($attributes_type,$j);
989
-                if (!$this->serveroutput->response[$attributes_type][$j]['name'])
990
-                { // it is a multi-valued collection
991
-                    $this->collection_depth ++;
992
-                    $this->index --;
993
-                    $this->collection_nbr[$this->collection_depth] ++;
994
-                }
995
-                else
996
-                {
997
-                    $this->collection_depth ++;
998
-                    if ($this->collection_depth == 0)
999
-                    {
1000
-                        $this->collection = (object) 'collection';
1001
-                    }
1002
-                    if (array_key_exists($this->collection_depth,$this->collection_nbr))
1003
-                    {
1004
-                        $this->collection_nbr[$this->collection_depth] ++;
1005
-                    }
1006
-                    else
1007
-                    {
1008
-                        $this->collection_nbr[$this->collection_depth] = 0;
1009
-                    }
1010
-                    unset($this->end_collection);
1011
-                }
1012
-                self::_readValue ("begCollection",$attributes_type,$j);
1013
-                break;
1014
-            case "endCollection": //RFC3382 (BLIND CODE)
1015
-                $this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
1016
-                self::_putDebug( "tag is: endCollection\n");
1017
-                self::_readAttributeName ($attributes_type,$j,0);
1018
-                self::_readValue ('name',$attributes_type,$j,0);
1019
-                $this->collection_depth --;
1020
-                $this->collection_key[$this->collection_depth] = 0;
1021
-                $this->end_collection = true;
1022
-                break;
1023
-            case "memberAttrName": // RFC3382 (BLIND CODE)
1024
-                $this->serveroutput->response[$attributes_type][$j]['type'] = "memberAttrName";
1025
-                $this->index -- ;
1026
-                self::_putDebug( "tag is: memberAttrName\n");
1027
-                self::_readCollection ($attributes_type,$j);
1028
-                break;
1029
-
1030
-            default:
1031
-                $this->collection_depth = -1;
1032
-                $this->collection_key = array();
1033
-                $this->collection_nbr = array();
1034
-                $this->serveroutput->response[$attributes_type][$j]['type'] = $tag;
1035
-                self::_putDebug( "tag is: $tag\n");
1036
-                $attribute_name = self::_readAttributeName ($attributes_type,$j);
1037
-                if (!$attribute_name)
1038
-                {
1039
-                    $attribute_name = $this->attribute_name;
1040
-                }
1041
-                else
1042
-                {
1043
-                    $this->attribute_name = $attribute_name;
1044
-                }
1045
-                $value = self::_readValue ($tag,$attributes_type,$j);
1046
-                $this->serveroutput->response[$attributes_type][$j]['value'] = 
1047
-                self::_interpretAttribute($attribute_name,$tag,$this->serveroutput->response[$attributes_type][$j]['value']);
1048
-                break;
1049
-        }
1050
-        return;
1051
-    }
1052
-
1053
-    protected function _readTag($tag)
1054
-    {
1055
-        switch ($tag)
1056
-        {
1057
-            case 0x10:
1058
-                $tag = "unsupported";
1059
-                break;
1060
-            case 0x11:
1061
-                $tag = "reserved for 'default'";
1062
-                break;
1063
-            case 0x12:
1064
-                $tag = "unknown";
1065
-                break;
1066
-            case 0x13:
1067
-                $tag = "no-value";
1068
-                break;
1069
-            case 0x15: // RFC 3380
1070
-                $tag = "not-settable";
1071
-                break;
1072
-            case 0x16: // RFC 3380
1073
-                $tag = "delete-attribute";
1074
-                break;
1075
-            case 0x17: // RFC 3380
1076
-                $tag = "admin-define";
1077
-                break;
1078
-            case 0x20:
1079
-                $tag = "IETF reserved (generic integer)";
1080
-                break;
1081
-            case 0x21:
1082
-                $tag = "integer";
1083
-                break;
1084
-            case 0x22:
1085
-                $tag = "boolean";
1086
-                break;
1087
-            case 0x23:
1088
-                $tag = "enum";
1089
-                break;
1090
-            case 0x30:
1091
-                $tag = "octetString";
1092
-                break;
1093
-            case 0x31:
1094
-                $tag = "datetime";
1095
-                break;
1096
-            case 0x32:
1097
-                $tag = "resolution";
1098
-                break;
1099
-            case 0x33:
1100
-                $tag = "rangeOfInteger";
1101
-                break;
1102
-            case 0x34: //RFC3382 (BLIND CODE)
1103
-                $tag = "begCollection";
1104
-                break;
1105
-            case 0x35:
1106
-                $tag = "textWithLanguage";
1107
-                break;
1108
-            case 0x36:
1109
-                $tag = "nameWithLanguage";
1110
-                break;
1111
-            case 0x37: //RFC3382 (BLIND CODE)
1112
-                $tag = "endCollection";
1113
-                break;
1114
-            case 0x40:
1115
-                $tag = "IETF reserved text string";
1116
-                break;
1117
-            case 0x41:
1118
-                $tag = "textWithoutLanguage";
1119
-                break;
1120
-            case 0x42:
1121
-                $tag = "nameWithoutLanguage";
1122
-                break;
1123
-            case 0x43:
1124
-                $tag = "IETF reserved for future";
1125
-                break;
1126
-            case 0x44:
1127
-                $tag = "keyword";
1128
-                break;
1129
-            case 0x45:
1130
-                $tag = "uri";
1131
-                break;
1132
-            case 0x46:
1133
-                $tag = "uriScheme";
1134
-                break;
1135
-            case 0x47:
1136
-                $tag = "charset";
1137
-                break;
1138
-            case 0x48:
1139
-                $tag = "naturalLanguage";
1140
-                break;
1141
-            case 0x49:
1142
-                $tag = "mimeMediaType";
1143
-                break;
1144
-            case 0x4A: // RFC3382 (BLIND CODE)
1145
-                $tag = "memberAttrName";
1146
-                break;
1147
-            case 0x7F:
1148
-                $tag = "extended type";
1149
-                break;
1150
-            default:
1151
-                if ($tag >= 0x14 && $tag < 0x15 && $tag > 0x17 && $tag <= 0x1f) 
1152
-                {
1153
-                    $tag = "out-of-band";
1154
-                }
1155
-                elseif (0x24 <= $tag && $tag <= 0x2f) 
1156
-                {
1157
-                    $tag = "new integer type";
1158
-                }
1159
-                elseif (0x38 <= $tag && $tag <= 0x3F) 
1160
-                {
1161
-                    $tag = "new octet-stream type";
1162
-                }
1163
-                elseif (0x4B <= $tag && $tag <= 0x5F) 
1164
-                {
1165
-                    $tag = "new character string type";
1166
-                }
1167
-                elseif ((0x60 <= $tag && $tag < 0x7f) || $tag >= 0x80 )
1168
-                {
1169
-                    $tag = "IETF reserved for future";
1170
-                }
1171
-                else
1172
-                {
1173
-                    $tag = sprintf("UNKNOWN: 0x%x (%u)",$tag,$tag);
1174
-                }
1175
-                break;                                                            
1176
-        }
1177
-
1178
-        return $tag; 
1179
-    }
1180
-
1181
-    protected function _readCollection($attributes_type,$j)
1182
-    {
1183
-        $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1184
-                     +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1185
-
1186
-        $this->_parsing->offset += 2;
1187
-
1188
-        self::_putDebug( "Collection name_length ". $name_length ."\n");
1189
-
1190
-        $name = '';
1191
-        for ($i = 0; $i < $name_length; $i++)
1192
-        {
1193
-            $name .= $this->serveroutput->body[$this->_parsing->offset];
1194
-            $this->_parsing->offset += 1;
1195
-            if ($this->_parsing->offset > strlen($this->serveroutput->body))
1196
-            {
1197
-                return;
1198
-            }
1199
-        }
1200
-
1201
-        $collection_name = $name;
1202
-
1203
-        $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1204
-                     +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1205
-        $this->_parsing->offset += 2;
1206
-
1207
-        self::_putDebug( "Attribute name_length ". $name_length ."\n");
1208
-
1209
-        $name = '';
1210
-        for ($i = 0; $i < $name_length; $i++)
1211
-        {
1212
-            $name .= $this->serveroutput->body[$this->_parsing->offset];
1213
-            $this->_parsing->offset += 1;
1214
-            if ($this->_parsing->offset > strlen($this->serveroutput->body))
1215
-            {
1216
-                return;
1217
-            }
1218
-        }
1219
-
1220
-        $attribute_name = $name;
1221
-        if ($attribute_name == "")
1222
-        {
1223
-            $attribute_name = $this->last_attribute_name;
1224
-            $this->collection_key[$this->collection_depth] ++;
1225
-        }
1226
-        else
1227
-        {
1228
-            $this->collection_key[$this->collection_depth] = 0;
1229
-        }
1230
-        $this->last_attribute_name = $attribute_name;
1231
-
1232
-        self::_putDebug( "Attribute name ".$name."\n");
1233
-
1234
-        $tag = self::_readTag(ord($this->serveroutput->body[$this->_parsing->offset]));
1235
-        $this->_parsing->offset ++;
1236
-
1237
-        $type = $tag;
1238
-
1239
-        $name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1240
-                     +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1241
-        $this->_parsing->offset += 2;
1242
-
1243
-        self::_putDebug( "Collection2 name_length ". $name_length ."\n");
1244
-
1245
-        $name = '';
1246
-        for ($i = 0; $i < $name_length; $i++)
1247
-        {
1248
-            $name .= $this->serveroutput->body[$this->_parsing->offset];
1249
-            $this->_parsing->offset += 1;
1250
-            if ($this->_parsing->offset > strlen($this->serveroutput->body))
1251
-            {
1252
-                return;
1253
-            }
1254
-        }
1255
-
1256
-        $collection_value = $name;
1257
-        $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1258
-                      +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1259
-
1260
-        self::_putDebug( "Collection value_length ".$this->serveroutput->body[ $this->_parsing->offset]
1261
-                                       . $this->serveroutput->body[$this->_parsing->offset + 1]
1262
-                                       .": "
1263
-                                       . $value_length
1264
-                                       . " ");
1265
-
1266
-        $this->_parsing->offset += 2;
1267
-
1268
-        $value = '';
1269
-        for ($i = 0; $i < $value_length; $i++)
1270
-        {
1271
-            if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1272
-            {
1273
-                return;
1274
-            }
1275
-            $value .= $this->serveroutput->body[$this->_parsing->offset];
1276
-            $this->_parsing->offset += 1;
1277
-        }
1278
-
1279
-        $object = &$this->collection;
1280
-        for ($i = 0 ; $i <= $this->collection_depth ; $i ++)
1281
-        {
1282
-            $indice = "_indice".$this->collection_nbr[$i];
1283
-            if (!isset($object->$indice))
1284
-            {
1285
-                $object->$indice = (object) 'indice';
1286
-            }
1287
-            $object = &$object->$indice;
1288
-        }
1289
-
1290
-        $value_key = "_value".$this->collection_key[$this->collection_depth];
1291
-        $col_name_key = "_collection_name".$this->collection_key[$this->collection_depth];
1292
-        $col_val_key = "_collection_value".$this->collection_key[$this->collection_depth];
1293
-
1294
-        $attribute_value = self::_interpretAttribute($attribute_name,$tag,$value);
1295
-        $attribute_name = str_replace('-','_',$attribute_name);
1296
-
1297
-        self::_putDebug( sprintf("Value: %s\n",$value));
1298
-        $object->$attribute_name->_type = $type;
1299
-        $object->$attribute_name->$value_key = $attribute_value;
1300
-        $object->$attribute_name->$col_name_key = $collection_name;
1301
-        $object->$attribute_name->$col_val_key = $collection_value;
1302
-
1303
-        $this->serveroutput->response[$attributes_type][$j]['value'] = $this->collection;
1304
-    }
1305
-
1306
-    protected function _readAttributeName ($attributes_type,$j,$write=1)
1307
-    {
1308
-        $name_length = ord($this->serveroutput->body[ $this->_parsing->offset]) *  256
1309
-                     +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1310
-        $this->_parsing->offset += 2;
1311
-
1312
-        self::_putDebug( "name_length ". $name_length ."\n");
1313
-
1314
-        $name = '';
1315
-        for ($i = 0; $i < $name_length; $i++)
1316
-        {
1317
-            if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1318
-            {
1319
-                return;
1320
-            }
1321
-            $name .= $this->serveroutput->body[$this->_parsing->offset];
1322
-            $this->_parsing->offset += 1;
1323
-        }
1324
-
1325
-        if($write)
1326
-        {
1327
-            $this->serveroutput->response[$attributes_type][$j]['name'] = $name;
1328
-        }
1329
-
1330
-        self::_putDebug( "name " . $name . "\n");
1331
-
1332
-        return $name;   
1333
-    }
1334
-
1335
-    protected function _readValue ($type,$attributes_type,$j,$write=1)
1336
-    {
1337
-        $value_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1338
-                      +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
851
+		self::_putDebug( "job-uri is: ".$job_uri."\n",2);
852
+	}
853
+
854
+	// RESPONSE PARSING
855
+	protected function _parsePrinterAttributes()
856
+	{
857
+		//if (!preg_match('#successful#',$this->serveroutput->status))
858
+		//   return false;
859
+
860
+		$k = -1;
861
+		$l = 0;
862
+		for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
863
+		{
864
+			for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
865
+			{
866
+				if (!empty($this->serveroutput->response[$i][$j]['name']))
867
+				{
868
+					$k++;
869
+					$l = 0;
870
+					$this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
871
+					$this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
872
+					$this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
873
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
874
+				}
875
+				else
876
+				{
877
+					$l ++;
878
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
879
+					}
880
+			}
881
+		}
882
+		$this->serveroutput->response = array();
883
+
884
+		$this->printer_attributes = new \stdClass();
885
+		for ($i = 0 ; $i < count($this->parsed) ; $i ++)
886
+		{
887
+					$name = $this->parsed[$i]['name'];
888
+					$php_name = str_replace('-','_',$name);
889
+					$type = $this->parsed[$i]['type'];
890
+					$range = $this->parsed[$i]['range'];
891
+					$this->printer_attributes->$php_name = new \stdClass();
892
+					$this->printer_attributes->$php_name->_type = $type;
893
+					$this->printer_attributes->$php_name->_range = $range;
894
+					for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
895
+					{
896
+						$value = $this->parsed[$i][$j];
897
+						$index = '_value'.$j;
898
+						$this->printer_attributes->$php_name->$index = $value;
899
+						}
900
+					}
901
+
902
+		$this->parsed = array();
903
+	}
904
+
905
+	protected function _parseJobsAttributes()
906
+	{
907
+		//if ($this->serveroutput->status != "successfull-ok")
908
+		//    return false;
909
+
910
+		$job = -1;
911
+		$l = 0;
912
+		for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
913
+		{
914
+			if ($this->serveroutput->response[$i]['attributes'] == "job-attributes")
915
+			{
916
+				$job ++;
917
+			}
918
+			$k = -1; 
919
+			for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
920
+			{
921
+				if (!empty($this->serveroutput->response[$i][$j]['name']))
922
+				{
923
+					$k++;
924
+					$l = 0;
925
+					$this->parsed[$job][$k]['range'] = $this->serveroutput->response[$i]['attributes'];
926
+					$this->parsed[$job][$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
927
+					$this->parsed[$job][$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
928
+					$this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
929
+				}
930
+				else
931
+				{
932
+					$l ++;
933
+					$this->parsed[$job][$k][$l] = $this->serveroutput->response[$i][$j]['value'];
934
+				}
935
+			}
936
+		}
937
+
938
+		$this->serveroutput->response = array();
939
+		$this->jobs_attributes = new \stdClass();
940
+		for ($job_nbr = 0 ; $job_nbr <= $job ; $job_nbr ++)
941
+		{
942
+			$job_index = "job_".$job_nbr;
943
+			$this->jobs_attributes->$job_index = new \stdClass();
944
+			for ($i = 0 ; $i < count($this->parsed[$job_nbr]) ; $i ++)
945
+			{
946
+				$name = $this->parsed[$job_nbr][$i]['name'];
947
+				$php_name = str_replace('-','_',$name);
948
+				$type = $this->parsed[$job_nbr][$i]['type'];
949
+				$range = $this->parsed[$job_nbr][$i]['range'];
950
+				$this->jobs_attributes->$job_index->$php_name = new \stdClass();
951
+				$this->jobs_attributes->$job_index->$php_name->_type = $type;
952
+				$this->jobs_attributes->$job_index->$php_name->_range = $range;
953
+				for ($j = 0 ; $j < (count($this->parsed[$job_nbr][$i]) - 3) ; $j ++)
954
+				{
955
+					# This causes incorrect parsing of integer job attributes.
956
+					# 2010-08-16
957
+					# bpkroth
958
+					#$value = self::_interpretAttribute($name,$type,$this->parsed[$job_nbr][$i][$j]);
959
+					$value = $this->parsed[$job_nbr][$i][$j];
960
+					$index = '_value'.$j;
961
+					$this->jobs_attributes->$job_index->$php_name->$index = $value;
962
+				}
963
+			}
964
+		}
965
+
966
+		$this->parsed = array();
967
+	}
968
+
969
+	protected function _readAttribute($attributes_type)
970
+	{
971
+		$tag = ord($this->serveroutput->body[$this->_parsing->offset]);
972
+
973
+		$this->_parsing->offset += 1;
974
+		$j = $this->index;
975
+
976
+		$tag = self::_readTag($tag);
977
+
978
+		switch ($tag)
979
+		{
980
+			case "begCollection": //RFC3382 (BLIND CODE)
981
+				if ($this->end_collection)
982
+				{
983
+					$this->index --;
984
+				}
985
+				$this->end_collection = false;
986
+				$this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
987
+				self::_putDebug( "tag is: begCollection\n");
988
+				self::_readAttributeName ($attributes_type,$j);
989
+				if (!$this->serveroutput->response[$attributes_type][$j]['name'])
990
+				{ // it is a multi-valued collection
991
+					$this->collection_depth ++;
992
+					$this->index --;
993
+					$this->collection_nbr[$this->collection_depth] ++;
994
+				}
995
+				else
996
+				{
997
+					$this->collection_depth ++;
998
+					if ($this->collection_depth == 0)
999
+					{
1000
+						$this->collection = (object) 'collection';
1001
+					}
1002
+					if (array_key_exists($this->collection_depth,$this->collection_nbr))
1003
+					{
1004
+						$this->collection_nbr[$this->collection_depth] ++;
1005
+					}
1006
+					else
1007
+					{
1008
+						$this->collection_nbr[$this->collection_depth] = 0;
1009
+					}
1010
+					unset($this->end_collection);
1011
+				}
1012
+				self::_readValue ("begCollection",$attributes_type,$j);
1013
+				break;
1014
+			case "endCollection": //RFC3382 (BLIND CODE)
1015
+				$this->serveroutput->response[$attributes_type][$j]['type'] = "collection";
1016
+				self::_putDebug( "tag is: endCollection\n");
1017
+				self::_readAttributeName ($attributes_type,$j,0);
1018
+				self::_readValue ('name',$attributes_type,$j,0);
1019
+				$this->collection_depth --;
1020
+				$this->collection_key[$this->collection_depth] = 0;
1021
+				$this->end_collection = true;
1022
+				break;
1023
+			case "memberAttrName": // RFC3382 (BLIND CODE)
1024
+				$this->serveroutput->response[$attributes_type][$j]['type'] = "memberAttrName";
1025
+				$this->index -- ;
1026
+				self::_putDebug( "tag is: memberAttrName\n");
1027
+				self::_readCollection ($attributes_type,$j);
1028
+				break;
1029
+
1030
+			default:
1031
+				$this->collection_depth = -1;
1032
+				$this->collection_key = array();
1033
+				$this->collection_nbr = array();
1034
+				$this->serveroutput->response[$attributes_type][$j]['type'] = $tag;
1035
+				self::_putDebug( "tag is: $tag\n");
1036
+				$attribute_name = self::_readAttributeName ($attributes_type,$j);
1037
+				if (!$attribute_name)
1038
+				{
1039
+					$attribute_name = $this->attribute_name;
1040
+				}
1041
+				else
1042
+				{
1043
+					$this->attribute_name = $attribute_name;
1044
+				}
1045
+				$value = self::_readValue ($tag,$attributes_type,$j);
1046
+				$this->serveroutput->response[$attributes_type][$j]['value'] = 
1047
+				self::_interpretAttribute($attribute_name,$tag,$this->serveroutput->response[$attributes_type][$j]['value']);
1048
+				break;
1049
+		}
1050
+		return;
1051
+	}
1052
+
1053
+	protected function _readTag($tag)
1054
+	{
1055
+		switch ($tag)
1056
+		{
1057
+			case 0x10:
1058
+				$tag = "unsupported";
1059
+				break;
1060
+			case 0x11:
1061
+				$tag = "reserved for 'default'";
1062
+				break;
1063
+			case 0x12:
1064
+				$tag = "unknown";
1065
+				break;
1066
+			case 0x13:
1067
+				$tag = "no-value";
1068
+				break;
1069
+			case 0x15: // RFC 3380
1070
+				$tag = "not-settable";
1071
+				break;
1072
+			case 0x16: // RFC 3380
1073
+				$tag = "delete-attribute";
1074
+				break;
1075
+			case 0x17: // RFC 3380
1076
+				$tag = "admin-define";
1077
+				break;
1078
+			case 0x20:
1079
+				$tag = "IETF reserved (generic integer)";
1080
+				break;
1081
+			case 0x21:
1082
+				$tag = "integer";
1083
+				break;
1084
+			case 0x22:
1085
+				$tag = "boolean";
1086
+				break;
1087
+			case 0x23:
1088
+				$tag = "enum";
1089
+				break;
1090
+			case 0x30:
1091
+				$tag = "octetString";
1092
+				break;
1093
+			case 0x31:
1094
+				$tag = "datetime";
1095
+				break;
1096
+			case 0x32:
1097
+				$tag = "resolution";
1098
+				break;
1099
+			case 0x33:
1100
+				$tag = "rangeOfInteger";
1101
+				break;
1102
+			case 0x34: //RFC3382 (BLIND CODE)
1103
+				$tag = "begCollection";
1104
+				break;
1105
+			case 0x35:
1106
+				$tag = "textWithLanguage";
1107
+				break;
1108
+			case 0x36:
1109
+				$tag = "nameWithLanguage";
1110
+				break;
1111
+			case 0x37: //RFC3382 (BLIND CODE)
1112
+				$tag = "endCollection";
1113
+				break;
1114
+			case 0x40:
1115
+				$tag = "IETF reserved text string";
1116
+				break;
1117
+			case 0x41:
1118
+				$tag = "textWithoutLanguage";
1119
+				break;
1120
+			case 0x42:
1121
+				$tag = "nameWithoutLanguage";
1122
+				break;
1123
+			case 0x43:
1124
+				$tag = "IETF reserved for future";
1125
+				break;
1126
+			case 0x44:
1127
+				$tag = "keyword";
1128
+				break;
1129
+			case 0x45:
1130
+				$tag = "uri";
1131
+				break;
1132
+			case 0x46:
1133
+				$tag = "uriScheme";
1134
+				break;
1135
+			case 0x47:
1136
+				$tag = "charset";
1137
+				break;
1138
+			case 0x48:
1139
+				$tag = "naturalLanguage";
1140
+				break;
1141
+			case 0x49:
1142
+				$tag = "mimeMediaType";
1143
+				break;
1144
+			case 0x4A: // RFC3382 (BLIND CODE)
1145
+				$tag = "memberAttrName";
1146
+				break;
1147
+			case 0x7F:
1148
+				$tag = "extended type";
1149
+				break;
1150
+			default:
1151
+				if ($tag >= 0x14 && $tag < 0x15 && $tag > 0x17 && $tag <= 0x1f) 
1152
+				{
1153
+					$tag = "out-of-band";
1154
+				}
1155
+				elseif (0x24 <= $tag && $tag <= 0x2f) 
1156
+				{
1157
+					$tag = "new integer type";
1158
+				}
1159
+				elseif (0x38 <= $tag && $tag <= 0x3F) 
1160
+				{
1161
+					$tag = "new octet-stream type";
1162
+				}
1163
+				elseif (0x4B <= $tag && $tag <= 0x5F) 
1164
+				{
1165
+					$tag = "new character string type";
1166
+				}
1167
+				elseif ((0x60 <= $tag && $tag < 0x7f) || $tag >= 0x80 )
1168
+				{
1169
+					$tag = "IETF reserved for future";
1170
+				}
1171
+				else
1172
+				{
1173
+					$tag = sprintf("UNKNOWN: 0x%x (%u)",$tag,$tag);
1174
+				}
1175
+				break;                                                            
1176
+		}
1177
+
1178
+		return $tag; 
1179
+	}
1180
+
1181
+	protected function _readCollection($attributes_type,$j)
1182
+	{
1183
+		$name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1184
+					 +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1185
+
1186
+		$this->_parsing->offset += 2;
1187
+
1188
+		self::_putDebug( "Collection name_length ". $name_length ."\n");
1189
+
1190
+		$name = '';
1191
+		for ($i = 0; $i < $name_length; $i++)
1192
+		{
1193
+			$name .= $this->serveroutput->body[$this->_parsing->offset];
1194
+			$this->_parsing->offset += 1;
1195
+			if ($this->_parsing->offset > strlen($this->serveroutput->body))
1196
+			{
1197
+				return;
1198
+			}
1199
+		}
1200
+
1201
+		$collection_name = $name;
1202
+
1203
+		$name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1204
+					 +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1205
+		$this->_parsing->offset += 2;
1206
+
1207
+		self::_putDebug( "Attribute name_length ". $name_length ."\n");
1208
+
1209
+		$name = '';
1210
+		for ($i = 0; $i < $name_length; $i++)
1211
+		{
1212
+			$name .= $this->serveroutput->body[$this->_parsing->offset];
1213
+			$this->_parsing->offset += 1;
1214
+			if ($this->_parsing->offset > strlen($this->serveroutput->body))
1215
+			{
1216
+				return;
1217
+			}
1218
+		}
1219
+
1220
+		$attribute_name = $name;
1221
+		if ($attribute_name == "")
1222
+		{
1223
+			$attribute_name = $this->last_attribute_name;
1224
+			$this->collection_key[$this->collection_depth] ++;
1225
+		}
1226
+		else
1227
+		{
1228
+			$this->collection_key[$this->collection_depth] = 0;
1229
+		}
1230
+		$this->last_attribute_name = $attribute_name;
1231
+
1232
+		self::_putDebug( "Attribute name ".$name."\n");
1233
+
1234
+		$tag = self::_readTag(ord($this->serveroutput->body[$this->_parsing->offset]));
1235
+		$this->_parsing->offset ++;
1236
+
1237
+		$type = $tag;
1238
+
1239
+		$name_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1240
+					 +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1241
+		$this->_parsing->offset += 2;
1242
+
1243
+		self::_putDebug( "Collection2 name_length ". $name_length ."\n");
1244
+
1245
+		$name = '';
1246
+		for ($i = 0; $i < $name_length; $i++)
1247
+		{
1248
+			$name .= $this->serveroutput->body[$this->_parsing->offset];
1249
+			$this->_parsing->offset += 1;
1250
+			if ($this->_parsing->offset > strlen($this->serveroutput->body))
1251
+			{
1252
+				return;
1253
+			}
1254
+		}
1255
+
1256
+		$collection_value = $name;
1257
+		$value_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1258
+					  +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1259
+
1260
+		self::_putDebug( "Collection value_length ".$this->serveroutput->body[ $this->_parsing->offset]
1261
+									   . $this->serveroutput->body[$this->_parsing->offset + 1]
1262
+									   .": "
1263
+									   . $value_length
1264
+									   . " ");
1265
+
1266
+		$this->_parsing->offset += 2;
1267
+
1268
+		$value = '';
1269
+		for ($i = 0; $i < $value_length; $i++)
1270
+		{
1271
+			if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1272
+			{
1273
+				return;
1274
+			}
1275
+			$value .= $this->serveroutput->body[$this->_parsing->offset];
1276
+			$this->_parsing->offset += 1;
1277
+		}
1278
+
1279
+		$object = &$this->collection;
1280
+		for ($i = 0 ; $i <= $this->collection_depth ; $i ++)
1281
+		{
1282
+			$indice = "_indice".$this->collection_nbr[$i];
1283
+			if (!isset($object->$indice))
1284
+			{
1285
+				$object->$indice = (object) 'indice';
1286
+			}
1287
+			$object = &$object->$indice;
1288
+		}
1289
+
1290
+		$value_key = "_value".$this->collection_key[$this->collection_depth];
1291
+		$col_name_key = "_collection_name".$this->collection_key[$this->collection_depth];
1292
+		$col_val_key = "_collection_value".$this->collection_key[$this->collection_depth];
1293
+
1294
+		$attribute_value = self::_interpretAttribute($attribute_name,$tag,$value);
1295
+		$attribute_name = str_replace('-','_',$attribute_name);
1296
+
1297
+		self::_putDebug( sprintf("Value: %s\n",$value));
1298
+		$object->$attribute_name->_type = $type;
1299
+		$object->$attribute_name->$value_key = $attribute_value;
1300
+		$object->$attribute_name->$col_name_key = $collection_name;
1301
+		$object->$attribute_name->$col_val_key = $collection_value;
1302
+
1303
+		$this->serveroutput->response[$attributes_type][$j]['value'] = $this->collection;
1304
+	}
1305
+
1306
+	protected function _readAttributeName ($attributes_type,$j,$write=1)
1307
+	{
1308
+		$name_length = ord($this->serveroutput->body[ $this->_parsing->offset]) *  256
1309
+					 +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1310
+		$this->_parsing->offset += 2;
1311
+
1312
+		self::_putDebug( "name_length ". $name_length ."\n");
1313
+
1314
+		$name = '';
1315
+		for ($i = 0; $i < $name_length; $i++)
1316
+		{
1317
+			if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1318
+			{
1319
+				return;
1320
+			}
1321
+			$name .= $this->serveroutput->body[$this->_parsing->offset];
1322
+			$this->_parsing->offset += 1;
1323
+		}
1324
+
1325
+		if($write)
1326
+		{
1327
+			$this->serveroutput->response[$attributes_type][$j]['name'] = $name;
1328
+		}
1329
+
1330
+		self::_putDebug( "name " . $name . "\n");
1331
+
1332
+		return $name;   
1333
+	}
1334
+
1335
+	protected function _readValue ($type,$attributes_type,$j,$write=1)
1336
+	{
1337
+		$value_length = ord($this->serveroutput->body[$this->_parsing->offset]) *  256
1338
+					  +  ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1339 1339
         
1340
-        self::_putDebug( "value_length ".$this->serveroutput->body[ $this->_parsing->offset]
1341
-                                       . $this->serveroutput->body[$this->_parsing->offset + 1]
1342
-                                       .": "
1343
-                                       . $value_length
1344
-                                       . " ");
1345
-
1346
-        $this->_parsing->offset += 2;
1347
-
1348
-        $value = '';
1349
-        for ($i = 0; $i < $value_length; $i++)
1350
-        {
1351
-            if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1352
-            {
1353
-                return;
1354
-            }
1355
-            $value .= $this->serveroutput->body[$this->_parsing->offset];
1356
-            $this->_parsing->offset += 1;
1357
-            }
1358
-
1359
-        self::_putDebug( sprintf("Value: %s\n",$value));
1360
-
1361
-        if ($write)
1362
-        {
1363
-            $this->serveroutput->response[$attributes_type][$j]['value'] = $value;
1364
-        }
1365
-
1366
-        return $value;
1367
-    }
1368
-
1369
-    protected function _parseAttributes()
1370
-    {
1371
-        $k = -1;
1372
-        $l = 0;
1373
-        for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
1374
-        {
1375
-            for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
1376
-            {
1377
-                if (!empty($this->serveroutput->response[$i][$j]['name']))
1378
-                {
1379
-                    $k++;
1380
-                    $l = 0;
1381
-                    $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
1382
-                    $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
1383
-                    $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
1384
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1385
-                }
1386
-                else
1387
-                {
1388
-                    $l ++;
1389
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1390
-                }
1391
-            }
1392
-        }
1393
-        $this->serveroutput->response = array();
1394
-        $this->attributes  = new \stdClass();
1395
-        for ($i = 0 ; $i < count($this->parsed) ; $i ++)
1396
-        {
1397
-                    $name = $this->parsed[$i]['name'];
1398
-                    $php_name = str_replace('-','_',$name);
1399
-                    $type = $this->parsed[$i]['type'];
1400
-                    $range = $this->parsed[$i]['range'];
1401
-                    $this->attributes->$php_name = new \stdClass();
1402
-                    $this->attributes->$php_name->_type = $type;
1403
-                    $this->attributes->$php_name->_range = $range;
1404
-                    for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
1405
-                    {
1406
-                        $value = $this->parsed[$i][$j];
1407
-                        $index = '_value'.$j;
1408
-                        $this->attributes->$php_name->$index = $value;
1409
-                        }
1410
-                    }
1411
-
1412
-        $this->parsed = array();
1413
-    }
1414
-
1415
-    protected function _parseJobAttributes()
1416
-    {
1417
-        //if (!preg_match('#successful#',$this->serveroutput->status))
1418
-        //    return false;
1419
-        $k = -1;
1420
-        $l = 0;
1421
-        for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
1422
-        {
1423
-            for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
1424
-            {
1425
-                if (!empty($this->serveroutput->response[$i][$j]['name']))
1426
-                {
1427
-                    $k++;
1428
-                    $l = 0;
1429
-                    $this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
1430
-                    $this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
1431
-                    $this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
1432
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1433
-                }
1434
-                else
1435
-                {
1436
-                    $l ++;
1437
-                    $this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1438
-                }
1439
-            }
1440
-        }
1441
-
1442
-        $this->serveroutput->response = array();
1443
-
1444
-        $this->job_attributes = new \stdClass();
1445
-        for ($i = 0 ; $i < count($this->parsed) ; $i ++)
1446
-        {
1447
-                    $name = $this->parsed[$i]['name'];
1448
-                    $php_name = str_replace('-','_',$name);
1449
-                    $type = $this->parsed[$i]['type'];
1450
-                    $range = $this->parsed[$i]['range'];
1451
-                    $this->job_attributes->$php_name = new \stdClass();
1452
-                    $this->job_attributes->$php_name->_type = $type;
1453
-                    $this->job_attributes->$php_name->_range = $range;
1454
-                    for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
1455
-                    {
1456
-                        $value = $this->parsed[$i][$j];
1457
-                        $index = '_value'.$j;
1458
-                        $this->job_attributes->$php_name->$index = $value;
1459
-                        }
1460
-                    }
1461
-
1462
-        $this->parsed = array();
1463
-    }
1464
-
1465
-    protected function _interpretAttribute($attribute_name,$type,$value)
1466
-    {
1467
-        switch ($type)
1468
-        {
1469
-            case "integer":
1470
-                $value = self::_interpretInteger($value);
1471
-                break;
1472
-            case "rangeOfInteger":
1473
-                $value = self::_interpretRangeOfInteger($value);
1474
-                break;
1475
-            case 'boolean':
1476
-                $value = ord($value);
1477
-                if ($value == 0x00)
1478
-                {
1479
-                    $value = 'false';
1480
-                }
1481
-                else
1482
-                {
1483
-                    $value = 'true';
1484
-                }
1485
-                break;
1486
-            case 'datetime':
1487
-                $value = self::_interpretDateTime($value);
1488
-                break;
1489
-            case 'enum':
1490
-                $value = $this->_interpretEnum($attribute_name,$value); // must be overwritten by children
1491
-                break;
1492
-            case 'resolution':
1493
-                $unit = $value[8];
1494
-                $value = self::_interpretRangeOfInteger(substr($value,0,8));
1495
-                switch($unit)
1496
-                {
1497
-                    case chr(0x03):
1498
-                        $unit = "dpi";
1499
-                        break;
1500
-                    case chr(0x04):
1501
-                        $unit = "dpc";
1502
-                        break;
1503
-                    }
1504
-                $value = $value." ".$unit;
1505
-                break;
1506
-            default:
1507
-                break;
1508
-        }
1509
-        return $value;
1510
-    }
1511
-
1512
-    protected function _interpretRangeOfInteger($value)
1513
-    {
1514
-        $value_parsed = 0;
1515
-        $integer1 = $integer2 = 0;
1516
-
1517
-        $halfsize = strlen($value) / 2;
1518
-
1519
-        $integer1 = self::_interpretInteger(substr($value,0,$halfsize));
1520
-        $integer2 = self::_interpretInteger(substr($value,$halfsize,$halfsize));
1521
-
1522
-        $value_parsed = sprintf('%s-%s',$integer1,$integer2);
1523
-
1524
-        return $value_parsed;
1525
-    }
1526
-
1527
-    protected function _interpretDateTime($date)
1528
-    {
1529
-        $year = self::_interpretInteger(substr($date,0,2));
1530
-        $month =  self::_interpretInteger(substr($date,2,1));
1531
-        $day =  self::_interpretInteger(substr($date,3,1));
1532
-        $hour =  self::_interpretInteger(substr($date,4,1));
1533
-        $minute =  self::_interpretInteger(substr($date,5,1));
1534
-        $second =  self::_interpretInteger(substr($date,6,1));
1535
-        $direction = substr($date,8,1);
1536
-        $hours_from_utc = self::_interpretInteger(substr($date,9,1));
1537
-        $minutes_from_utc = self::_interpretInteger(substr($date,10,1));
1538
-
1539
-        $date = sprintf('%s-%s-%s %s:%s:%s %s%s:%s',$year,$month,$day,$hour,$minute,$second,$direction,$hours_from_utc,$minutes_from_utc);
1540
-
1541
-        return $date;
1542
-    }
1543
-
1544
-    protected function _interpretEnum($attribute_name,$value)
1545
-    {
1546
-        $value_parsed = self::_interpretInteger($value);
1547
-
1548
-        switch ($attribute_name)
1549
-        {
1550
-            case 'job-state':
1551
-                switch ($value_parsed)
1552
-                {
1553
-                    case 0x03:
1554
-                        $value = 'pending';
1555
-                        break;
1556
-                    case 0x04:
1557
-                        $value = 'pending-held';
1558
-                        break;
1559
-                    case 0x05:
1560
-                        $value = 'processing';
1561
-                        break;
1562
-                    case 0x06:
1563
-                        $value = 'processing-stopped';
1564
-                        break;
1565
-                    case 0x07:
1566
-                        $value = 'canceled';
1567
-                        break;
1568
-                    case 0x08:
1569
-                        $value = 'aborted';
1570
-                        break;
1571
-                    case 0x09:
1572
-                        $value = 'completed';
1573
-                        break;
1574
-                }
1575
-                if ($value_parsed > 0x09)
1576
-                {
1577
-                    $value = sprintf('Unknown(IETF standards track "job-state" reserved): 0x%x',$value_parsed);
1578
-                }
1579
-                break;
1580
-            case 'print-quality':
1581
-            case 'print-quality-supported':
1582
-            case 'print-quality-default':
1583
-                switch ($value_parsed)
1584
-                {
1585
-                    case 0x03:
1586
-                        $value = 'draft';
1587
-                        break;
1588
-                    case 0x04:
1589
-                        $value = 'normal';
1590
-                        break;
1591
-                    case 0x05:
1592
-                        $value = 'high';
1593
-                        break;
1594
-                    }
1595
-                break;
1596
-            case 'printer-state':
1597
-                switch ($value_parsed)
1598
-                {
1599
-                    case 0x03:
1600
-                        $value = 'idle';
1601
-                        break;
1602
-                    case 0x04:
1603
-                        $value = 'processing';
1604
-                        break;
1605
-                    case 0x05:
1606
-                        $value = 'stopped';
1607
-                        break;
1608
-                }
1609
-                if ($value_parsed > 0x05)
1610
-                {
1611
-                    $value = sprintf('Unknown(IETF standards track "printer-state" reserved): 0x%x',$value_parsed);
1612
-                }
1613
-                break;
1614
-
1615
-            case 'operations-supported':
1616
-                switch($value_parsed)
1617
-                {
1618
-                    case 0x0000:
1619
-                    case 0x0001:
1620
-                        $value = sprintf('Unknown(reserved) : %s',ord($value));
1621
-                        break;
1622
-                    case 0x0002:
1623
-                        $value = 'Print-Job';
1624
-                        break;
1625
-                    case 0x0003:
1626
-                        $value = 'Print-URI';
1627
-                        break;
1628
-                    case 0x0004:
1629
-                        $value = 'Validate-Job';
1630
-                        break;
1631
-                    case 0x0005:
1632
-                        $value = 'Create-Job';
1633
-                        break;
1634
-                    case 0x0006:
1635
-                        $value = 'Send-Document';
1636
-                        break;
1637
-                    case 0x0007:
1638
-                        $value = 'Send-URI';
1639
-                        break;
1640
-                    case 0x0008:
1641
-                        $value = 'Cancel-Job';
1642
-                        break;
1643
-                    case 0x0009:
1644
-                        $value = 'Get-Job-Attributes';
1645
-                        break;
1646
-                    case 0x000A:
1647
-                        $value = 'Get-Jobs';
1648
-                        break;
1649
-                    case 0x000B:
1650
-                        $value = 'Get-Printer-Attributes';
1651
-                        break;
1652
-                    case 0x000C:
1653
-                        $value = 'Hold-Job';
1654
-                        break;
1655
-                    case 0x000D:
1656
-                        $value = 'Release-Job';
1657
-                        break;
1658
-                    case 0x000E:
1659
-                        $value = 'Restart-Job';
1660
-                        break;
1661
-                    case 0x000F:
1662
-                        $value = 'Unknown(reserved for a future operation)';
1663
-                        break;
1664
-                    case 0x0010:
1665
-                        $value = 'Pause-Printer';
1666
-                        break;
1667
-                    case 0x0011:
1668
-                        $value = 'Resume-Printer';
1669
-                        break;
1670
-                    case 0x0012:
1671
-                        $value = 'Purge-Jobs';
1672
-                        break;
1673
-                    case 0x0013:
1674
-                        $value = 'Set-Printer-Attributes'; // RFC3380
1675
-                        break;
1676
-                    case 0x0014:
1677
-                        $value = 'Set-Job-Attributes'; // RFC3380
1678
-                        break;
1679
-                    case 0x0015:
1680
-                        $value = 'Get-Printer-Supported-Values'; // RFC3380
1681
-                        break;
1682
-                    case 0x0016:
1683
-                        $value = 'Create-Printer-Subscriptions';
1684
-                        break;
1685
-                    case 0x0017:
1686
-                        $value = 'Create-Job-Subscriptions';
1687
-                        break;
1688
-                    case 0x0018:
1689
-                        $value = 'Get-Subscription-Attributes';
1690
-                        break;
1691
-                    case 0x0019:
1692
-                        $value = 'Get-Subscriptions';
1693
-                        break;
1694
-                    case 0x001A:
1695
-                        $value = 'Renew-Subscription';
1696
-                        break;
1697
-                    case 0x001B:
1698
-                        $value = 'Cancel-Subscription';
1699
-                        break;
1700
-                    case 0x001C:
1701
-                        $value = 'Get-Notifications';
1702
-                        break;
1703
-                    case 0x001D:
1704
-                        $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1705
-                        break;
1706
-                    case 0x001E:
1707
-                        $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1708
-                        break;
1709
-                    case 0x001F:
1710
-                        $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1711
-                        break;
1712
-                    case 0x0020:
1713
-                        $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1714
-                        break;
1715
-                    case 0x0021:
1716
-                        $value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1717
-                        break;
1718
-                    case 0x0022: 
1719
-                        $value = 'Enable-Printer';
1720
-                        break;
1721
-                    case 0x0023: 
1722
-                        $value = 'Disable-Printer';
1723
-                        break;
1724
-                    case 0x0024: 
1725
-                        $value = 'Pause-Printer-After-Current-Job';
1726
-                        break;
1727
-                    case 0x0025: 
1728
-                        $value = 'Hold-New-Jobs';
1729
-                        break;
1730
-                    case 0x0026: 
1731
-                        $value = 'Release-Held-New-Jobs';
1732
-                        break;
1733
-                    case 0x0027: 
1734
-                        $value = 'Deactivate-Printer';
1735
-                        break;
1736
-                    case 0x0028: 
1737
-                        $value = 'Activate-Printer';
1738
-                        break;
1739
-                    case 0x0029: 
1740
-                        $value = 'Restart-Printer';
1741
-                        break;
1742
-                    case 0x002A: 
1743
-                        $value = 'Shutdown-Printer';
1744
-                        break;
1745
-                    case 0x002B: 
1746
-                        $value = 'Startup-Printer';
1747
-                        break;
1748
-                }
1749
-                if ($value_parsed > 0x002B && $value_parsed <= 0x3FFF)
1750
-                {
1751
-                    $value = sprintf('Unknown(IETF standards track operations reserved): 0x%x',$value_parsed);
1752
-                }
1753
-                elseif ($value_parsed >= 0x4000 && $value_parsed <= 0x8FFF)
1754
-                {
1755
-                    if (method_exists($this,'_getEnumVendorExtensions'))
1756
-                    {
1757
-                        $value = $this->_getEnumVendorExtensions($value_parsed);
1758
-                    }
1759
-                    else
1760
-                    {
1761
-                        $value = sprintf('Unknown(Vendor extension for operations): 0x%x',$value_parsed);
1762
-                    }
1763
-                }
1764
-                elseif ($value_parsed > 0x8FFF)
1765
-                {
1766
-                    $value = sprintf('Unknown operation (should not exists): 0x%x',$value_parsed);
1767
-                }
1768
-
1769
-                break;
1770
-            case 'finishings':
1771
-            case 'finishings-default':
1772
-            case 'finishings-supported':
1773
-                switch ($value_parsed)
1774
-                {
1775
-                    case 3:
1776
-                        $value = 'none';
1777
-                        break;
1778
-                    case 4:
1779
-                        $value = 'staple';
1780
-                        break;
1781
-                    case 5:
1782
-                        $value = 'punch';
1783
-                        break;
1784
-                    case 6:
1785
-                        $value = 'cover';
1786
-                        break;
1787
-                    case 7:
1788
-                        $value = 'bind';
1789
-                        break;
1790
-                    case 8:
1791
-                        $value = 'saddle-stitch';
1792
-                        break;
1793
-                    case 9:
1794
-                        $value = 'edge-stitch';
1795
-                        break;
1796
-                    case 20:
1797
-                        $value = 'staple-top-left';
1798
-                        break;
1799
-                    case 21:
1800
-                        $value = 'staple-bottom-left';
1801
-                        break;
1802
-                    case 22:
1803
-                        $value = 'staple-top-right';
1804
-                        break;
1805
-                    case 23:
1806
-                        $value = 'staple-bottom-right';
1807
-                        break;
1808
-                    case 24:
1809
-                        $value = 'edge-stitch-left';
1810
-                        break;
1811
-                    case 25:
1812
-                        $value = 'edge-stitch-top';
1813
-                        break;
1814
-                    case 26:
1815
-                        $value = 'edge-stitch-right';
1816
-                        break;
1817
-                    case 27:
1818
-                        $value = 'edge-stitch-bottom';
1819
-                        break;
1820
-                    case 28:
1821
-                        $value = 'staple-dual-left';
1822
-                        break;
1823
-                    case 29:
1824
-                        $value = 'staple-dual-top';
1825
-                        break;
1826
-                    case 30:
1827
-                        $value = 'staple-dual-right';
1828
-                        break;
1829
-                    case 31:
1830
-                        $value = 'staple-dual-bottom';
1831
-                        break;
1832
-                }
1833
-                if ($value_parsed > 31)
1834
-                {
1835
-                    $value = sprintf('Unknown(IETF standards track "finishing" reserved): 0x%x',$value_parsed);
1836
-                }
1837
-                break;
1838
-
1839
-            case 'orientation-requested':
1840
-            case 'orientation-requested-supported':
1841
-            case 'orientation-requested-default':
1842
-                switch ($value_parsed)
1843
-                {
1844
-                    case 0x03:
1845
-                        $value = 'portrait';
1846
-                        break;
1847
-                    case 0x04:
1848
-                        $value = 'landscape';
1849
-                        break;
1850
-                    case 0x05:
1851
-                        $value = 'reverse-landscape';
1852
-                        break;
1853
-                    case 0x06:
1854
-                        $value = 'reverse-portrait';
1855
-                        break;
1856
-                }
1857
-                if ($value_parsed > 0x06)
1858
-                {
1859
-                    $value = sprintf('Unknown(IETF standards track "orientation" reserved): 0x%x',$value_parsed);
1860
-                }
1861
-                break;
1862
-
1863
-            default:
1864
-                break;
1865
-        }
1866
-        return $value;
1867
-    }
1868
-
1869
-    protected function _getJobId ()
1870
-    {
1871
-        if (!isset($this->serveroutput->response))
1872
-        {
1873
-            $this->jobs = array_merge($this->jobs,array('NO JOB'));
1874
-        }
1875
-
1876
-        $jobfinded = false;
1877
-        for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
1878
-        {
1879
-            if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
1880
-            {
1881
-                for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
1882
-                {
1883
-                    if ($this->serveroutput->response[$i][$j]['name'] == "job-id")
1884
-                    {
1885
-                        $this->last_job = $this->serveroutput->response[$i][$j]['value'];
1886
-                        $this->jobs = array_merge($this->jobs,array($this->serveroutput->response[$i][$j]['value']));
1887
-                        return;
1888
-                    }
1889
-                }
1890
-            }
1891
-        }
1892
-    }
1893
-
1894
-    protected function _getJobUri ()
1895
-    {
1896
-        if (!isset($this->jobs_uri))
1897
-        {
1898
-            $this->jobs_uri = array();
1899
-        }
1900
-
1901
-        $jobfinded = false;
1902
-        for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
1903
-        {
1904
-            if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
1905
-            {
1906
-                for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
1907
-                {
1908
-                    if ($this->serveroutput->response[$i][$j]['name'] == "job-uri")
1909
-                    {
1910
-                        $this->last_job = $this->serveroutput->response[$i][$j]['value'];
1911
-                        $this->jobs_uri = array_merge($this->jobs_uri,array($this->last_job));
1912
-                        return;
1913
-                    }
1914
-                }
1915
-            }
1916
-        }
1917
-        $this->last_job = '';
1918
-    }
1919
-
1920
-    protected function _parseResponse ()
1340
+		self::_putDebug( "value_length ".$this->serveroutput->body[ $this->_parsing->offset]
1341
+									   . $this->serveroutput->body[$this->_parsing->offset + 1]
1342
+									   .": "
1343
+									   . $value_length
1344
+									   . " ");
1345
+
1346
+		$this->_parsing->offset += 2;
1347
+
1348
+		$value = '';
1349
+		for ($i = 0; $i < $value_length; $i++)
1350
+		{
1351
+			if ($this->_parsing->offset >= strlen($this->serveroutput->body))
1352
+			{
1353
+				return;
1354
+			}
1355
+			$value .= $this->serveroutput->body[$this->_parsing->offset];
1356
+			$this->_parsing->offset += 1;
1357
+			}
1358
+
1359
+		self::_putDebug( sprintf("Value: %s\n",$value));
1360
+
1361
+		if ($write)
1362
+		{
1363
+			$this->serveroutput->response[$attributes_type][$j]['value'] = $value;
1364
+		}
1365
+
1366
+		return $value;
1367
+	}
1368
+
1369
+	protected function _parseAttributes()
1370
+	{
1371
+		$k = -1;
1372
+		$l = 0;
1373
+		for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
1374
+		{
1375
+			for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
1376
+			{
1377
+				if (!empty($this->serveroutput->response[$i][$j]['name']))
1378
+				{
1379
+					$k++;
1380
+					$l = 0;
1381
+					$this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
1382
+					$this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
1383
+					$this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
1384
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1385
+				}
1386
+				else
1387
+				{
1388
+					$l ++;
1389
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1390
+				}
1391
+			}
1392
+		}
1393
+		$this->serveroutput->response = array();
1394
+		$this->attributes  = new \stdClass();
1395
+		for ($i = 0 ; $i < count($this->parsed) ; $i ++)
1396
+		{
1397
+					$name = $this->parsed[$i]['name'];
1398
+					$php_name = str_replace('-','_',$name);
1399
+					$type = $this->parsed[$i]['type'];
1400
+					$range = $this->parsed[$i]['range'];
1401
+					$this->attributes->$php_name = new \stdClass();
1402
+					$this->attributes->$php_name->_type = $type;
1403
+					$this->attributes->$php_name->_range = $range;
1404
+					for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
1405
+					{
1406
+						$value = $this->parsed[$i][$j];
1407
+						$index = '_value'.$j;
1408
+						$this->attributes->$php_name->$index = $value;
1409
+						}
1410
+					}
1411
+
1412
+		$this->parsed = array();
1413
+	}
1414
+
1415
+	protected function _parseJobAttributes()
1416
+	{
1417
+		//if (!preg_match('#successful#',$this->serveroutput->status))
1418
+		//    return false;
1419
+		$k = -1;
1420
+		$l = 0;
1421
+		for ($i = 0 ; $i < count($this->serveroutput->response) ; $i++)
1422
+		{
1423
+			for ($j = 0 ; $j < (count($this->serveroutput->response[$i]) - 1) ; $j ++)
1424
+			{
1425
+				if (!empty($this->serveroutput->response[$i][$j]['name']))
1426
+				{
1427
+					$k++;
1428
+					$l = 0;
1429
+					$this->parsed[$k]['range'] = $this->serveroutput->response[$i]['attributes'];
1430
+					$this->parsed[$k]['name'] = $this->serveroutput->response[$i][$j]['name'];
1431
+					$this->parsed[$k]['type'] = $this->serveroutput->response[$i][$j]['type'];
1432
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1433
+				}
1434
+				else
1435
+				{
1436
+					$l ++;
1437
+					$this->parsed[$k][$l] = $this->serveroutput->response[$i][$j]['value'];
1438
+				}
1439
+			}
1440
+		}
1441
+
1442
+		$this->serveroutput->response = array();
1443
+
1444
+		$this->job_attributes = new \stdClass();
1445
+		for ($i = 0 ; $i < count($this->parsed) ; $i ++)
1446
+		{
1447
+					$name = $this->parsed[$i]['name'];
1448
+					$php_name = str_replace('-','_',$name);
1449
+					$type = $this->parsed[$i]['type'];
1450
+					$range = $this->parsed[$i]['range'];
1451
+					$this->job_attributes->$php_name = new \stdClass();
1452
+					$this->job_attributes->$php_name->_type = $type;
1453
+					$this->job_attributes->$php_name->_range = $range;
1454
+					for ($j = 0 ; $j < (count($this->parsed[$i]) - 3) ; $j ++)
1455
+					{
1456
+						$value = $this->parsed[$i][$j];
1457
+						$index = '_value'.$j;
1458
+						$this->job_attributes->$php_name->$index = $value;
1459
+						}
1460
+					}
1461
+
1462
+		$this->parsed = array();
1463
+	}
1464
+
1465
+	protected function _interpretAttribute($attribute_name,$type,$value)
1466
+	{
1467
+		switch ($type)
1468
+		{
1469
+			case "integer":
1470
+				$value = self::_interpretInteger($value);
1471
+				break;
1472
+			case "rangeOfInteger":
1473
+				$value = self::_interpretRangeOfInteger($value);
1474
+				break;
1475
+			case 'boolean':
1476
+				$value = ord($value);
1477
+				if ($value == 0x00)
1478
+				{
1479
+					$value = 'false';
1480
+				}
1481
+				else
1482
+				{
1483
+					$value = 'true';
1484
+				}
1485
+				break;
1486
+			case 'datetime':
1487
+				$value = self::_interpretDateTime($value);
1488
+				break;
1489
+			case 'enum':
1490
+				$value = $this->_interpretEnum($attribute_name,$value); // must be overwritten by children
1491
+				break;
1492
+			case 'resolution':
1493
+				$unit = $value[8];
1494
+				$value = self::_interpretRangeOfInteger(substr($value,0,8));
1495
+				switch($unit)
1496
+				{
1497
+					case chr(0x03):
1498
+						$unit = "dpi";
1499
+						break;
1500
+					case chr(0x04):
1501
+						$unit = "dpc";
1502
+						break;
1503
+					}
1504
+				$value = $value." ".$unit;
1505
+				break;
1506
+			default:
1507
+				break;
1508
+		}
1509
+		return $value;
1510
+	}
1511
+
1512
+	protected function _interpretRangeOfInteger($value)
1513
+	{
1514
+		$value_parsed = 0;
1515
+		$integer1 = $integer2 = 0;
1516
+
1517
+		$halfsize = strlen($value) / 2;
1518
+
1519
+		$integer1 = self::_interpretInteger(substr($value,0,$halfsize));
1520
+		$integer2 = self::_interpretInteger(substr($value,$halfsize,$halfsize));
1521
+
1522
+		$value_parsed = sprintf('%s-%s',$integer1,$integer2);
1523
+
1524
+		return $value_parsed;
1525
+	}
1526
+
1527
+	protected function _interpretDateTime($date)
1528
+	{
1529
+		$year = self::_interpretInteger(substr($date,0,2));
1530
+		$month =  self::_interpretInteger(substr($date,2,1));
1531
+		$day =  self::_interpretInteger(substr($date,3,1));
1532
+		$hour =  self::_interpretInteger(substr($date,4,1));
1533
+		$minute =  self::_interpretInteger(substr($date,5,1));
1534
+		$second =  self::_interpretInteger(substr($date,6,1));
1535
+		$direction = substr($date,8,1);
1536
+		$hours_from_utc = self::_interpretInteger(substr($date,9,1));
1537
+		$minutes_from_utc = self::_interpretInteger(substr($date,10,1));
1538
+
1539
+		$date = sprintf('%s-%s-%s %s:%s:%s %s%s:%s',$year,$month,$day,$hour,$minute,$second,$direction,$hours_from_utc,$minutes_from_utc);
1540
+
1541
+		return $date;
1542
+	}
1543
+
1544
+	protected function _interpretEnum($attribute_name,$value)
1545
+	{
1546
+		$value_parsed = self::_interpretInteger($value);
1547
+
1548
+		switch ($attribute_name)
1549
+		{
1550
+			case 'job-state':
1551
+				switch ($value_parsed)
1552
+				{
1553
+					case 0x03:
1554
+						$value = 'pending';
1555
+						break;
1556
+					case 0x04:
1557
+						$value = 'pending-held';
1558
+						break;
1559
+					case 0x05:
1560
+						$value = 'processing';
1561
+						break;
1562
+					case 0x06:
1563
+						$value = 'processing-stopped';
1564
+						break;
1565
+					case 0x07:
1566
+						$value = 'canceled';
1567
+						break;
1568
+					case 0x08:
1569
+						$value = 'aborted';
1570
+						break;
1571
+					case 0x09:
1572
+						$value = 'completed';
1573
+						break;
1574
+				}
1575
+				if ($value_parsed > 0x09)
1576
+				{
1577
+					$value = sprintf('Unknown(IETF standards track "job-state" reserved): 0x%x',$value_parsed);
1578
+				}
1579
+				break;
1580
+			case 'print-quality':
1581
+			case 'print-quality-supported':
1582
+			case 'print-quality-default':
1583
+				switch ($value_parsed)
1584
+				{
1585
+					case 0x03:
1586
+						$value = 'draft';
1587
+						break;
1588
+					case 0x04:
1589
+						$value = 'normal';
1590
+						break;
1591
+					case 0x05:
1592
+						$value = 'high';
1593
+						break;
1594
+					}
1595
+				break;
1596
+			case 'printer-state':
1597
+				switch ($value_parsed)
1598
+				{
1599
+					case 0x03:
1600
+						$value = 'idle';
1601
+						break;
1602
+					case 0x04:
1603
+						$value = 'processing';
1604
+						break;
1605
+					case 0x05:
1606
+						$value = 'stopped';
1607
+						break;
1608
+				}
1609
+				if ($value_parsed > 0x05)
1610
+				{
1611
+					$value = sprintf('Unknown(IETF standards track "printer-state" reserved): 0x%x',$value_parsed);
1612
+				}
1613
+				break;
1614
+
1615
+			case 'operations-supported':
1616
+				switch($value_parsed)
1617
+				{
1618
+					case 0x0000:
1619
+					case 0x0001:
1620
+						$value = sprintf('Unknown(reserved) : %s',ord($value));
1621
+						break;
1622
+					case 0x0002:
1623
+						$value = 'Print-Job';
1624
+						break;
1625
+					case 0x0003:
1626
+						$value = 'Print-URI';
1627
+						break;
1628
+					case 0x0004:
1629
+						$value = 'Validate-Job';
1630
+						break;
1631
+					case 0x0005:
1632
+						$value = 'Create-Job';
1633
+						break;
1634
+					case 0x0006:
1635
+						$value = 'Send-Document';
1636
+						break;
1637
+					case 0x0007:
1638
+						$value = 'Send-URI';
1639
+						break;
1640
+					case 0x0008:
1641
+						$value = 'Cancel-Job';
1642
+						break;
1643
+					case 0x0009:
1644
+						$value = 'Get-Job-Attributes';
1645
+						break;
1646
+					case 0x000A:
1647
+						$value = 'Get-Jobs';
1648
+						break;
1649
+					case 0x000B:
1650
+						$value = 'Get-Printer-Attributes';
1651
+						break;
1652
+					case 0x000C:
1653
+						$value = 'Hold-Job';
1654
+						break;
1655
+					case 0x000D:
1656
+						$value = 'Release-Job';
1657
+						break;
1658
+					case 0x000E:
1659
+						$value = 'Restart-Job';
1660
+						break;
1661
+					case 0x000F:
1662
+						$value = 'Unknown(reserved for a future operation)';
1663
+						break;
1664
+					case 0x0010:
1665
+						$value = 'Pause-Printer';
1666
+						break;
1667
+					case 0x0011:
1668
+						$value = 'Resume-Printer';
1669
+						break;
1670
+					case 0x0012:
1671
+						$value = 'Purge-Jobs';
1672
+						break;
1673
+					case 0x0013:
1674
+						$value = 'Set-Printer-Attributes'; // RFC3380
1675
+						break;
1676
+					case 0x0014:
1677
+						$value = 'Set-Job-Attributes'; // RFC3380
1678
+						break;
1679
+					case 0x0015:
1680
+						$value = 'Get-Printer-Supported-Values'; // RFC3380
1681
+						break;
1682
+					case 0x0016:
1683
+						$value = 'Create-Printer-Subscriptions';
1684
+						break;
1685
+					case 0x0017:
1686
+						$value = 'Create-Job-Subscriptions';
1687
+						break;
1688
+					case 0x0018:
1689
+						$value = 'Get-Subscription-Attributes';
1690
+						break;
1691
+					case 0x0019:
1692
+						$value = 'Get-Subscriptions';
1693
+						break;
1694
+					case 0x001A:
1695
+						$value = 'Renew-Subscription';
1696
+						break;
1697
+					case 0x001B:
1698
+						$value = 'Cancel-Subscription';
1699
+						break;
1700
+					case 0x001C:
1701
+						$value = 'Get-Notifications';
1702
+						break;
1703
+					case 0x001D:
1704
+						$value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1705
+						break;
1706
+					case 0x001E:
1707
+						$value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1708
+						break;
1709
+					case 0x001F:
1710
+						$value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1711
+						break;
1712
+					case 0x0020:
1713
+						$value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1714
+						break;
1715
+					case 0x0021:
1716
+						$value = sprintf('Unknown (reserved IETF "operations"): 0x%x',ord($value));
1717
+						break;
1718
+					case 0x0022: 
1719
+						$value = 'Enable-Printer';
1720
+						break;
1721
+					case 0x0023: 
1722
+						$value = 'Disable-Printer';
1723
+						break;
1724
+					case 0x0024: 
1725
+						$value = 'Pause-Printer-After-Current-Job';
1726
+						break;
1727
+					case 0x0025: 
1728
+						$value = 'Hold-New-Jobs';
1729
+						break;
1730
+					case 0x0026: 
1731
+						$value = 'Release-Held-New-Jobs';
1732
+						break;
1733
+					case 0x0027: 
1734
+						$value = 'Deactivate-Printer';
1735
+						break;
1736
+					case 0x0028: 
1737
+						$value = 'Activate-Printer';
1738
+						break;
1739
+					case 0x0029: 
1740
+						$value = 'Restart-Printer';
1741
+						break;
1742
+					case 0x002A: 
1743
+						$value = 'Shutdown-Printer';
1744
+						break;
1745
+					case 0x002B: 
1746
+						$value = 'Startup-Printer';
1747
+						break;
1748
+				}
1749
+				if ($value_parsed > 0x002B && $value_parsed <= 0x3FFF)
1750
+				{
1751
+					$value = sprintf('Unknown(IETF standards track operations reserved): 0x%x',$value_parsed);
1752
+				}
1753
+				elseif ($value_parsed >= 0x4000 && $value_parsed <= 0x8FFF)
1754
+				{
1755
+					if (method_exists($this,'_getEnumVendorExtensions'))
1756
+					{
1757
+						$value = $this->_getEnumVendorExtensions($value_parsed);
1758
+					}
1759
+					else
1760
+					{
1761
+						$value = sprintf('Unknown(Vendor extension for operations): 0x%x',$value_parsed);
1762
+					}
1763
+				}
1764
+				elseif ($value_parsed > 0x8FFF)
1765
+				{
1766
+					$value = sprintf('Unknown operation (should not exists): 0x%x',$value_parsed);
1767
+				}
1768
+
1769
+				break;
1770
+			case 'finishings':
1771
+			case 'finishings-default':
1772
+			case 'finishings-supported':
1773
+				switch ($value_parsed)
1774
+				{
1775
+					case 3:
1776
+						$value = 'none';
1777
+						break;
1778
+					case 4:
1779
+						$value = 'staple';
1780
+						break;
1781
+					case 5:
1782
+						$value = 'punch';
1783
+						break;
1784
+					case 6:
1785
+						$value = 'cover';
1786
+						break;
1787
+					case 7:
1788
+						$value = 'bind';
1789
+						break;
1790
+					case 8:
1791
+						$value = 'saddle-stitch';
1792
+						break;
1793
+					case 9:
1794
+						$value = 'edge-stitch';
1795
+						break;
1796
+					case 20:
1797
+						$value = 'staple-top-left';
1798
+						break;
1799
+					case 21:
1800
+						$value = 'staple-bottom-left';
1801
+						break;
1802
+					case 22:
1803
+						$value = 'staple-top-right';
1804
+						break;
1805
+					case 23:
1806
+						$value = 'staple-bottom-right';
1807
+						break;
1808
+					case 24:
1809
+						$value = 'edge-stitch-left';
1810
+						break;
1811
+					case 25:
1812
+						$value = 'edge-stitch-top';
1813
+						break;
1814
+					case 26:
1815
+						$value = 'edge-stitch-right';
1816
+						break;
1817
+					case 27:
1818
+						$value = 'edge-stitch-bottom';
1819
+						break;
1820
+					case 28:
1821
+						$value = 'staple-dual-left';
1822
+						break;
1823
+					case 29:
1824
+						$value = 'staple-dual-top';
1825
+						break;
1826
+					case 30:
1827
+						$value = 'staple-dual-right';
1828
+						break;
1829
+					case 31:
1830
+						$value = 'staple-dual-bottom';
1831
+						break;
1832
+				}
1833
+				if ($value_parsed > 31)
1834
+				{
1835
+					$value = sprintf('Unknown(IETF standards track "finishing" reserved): 0x%x',$value_parsed);
1836
+				}
1837
+				break;
1838
+
1839
+			case 'orientation-requested':
1840
+			case 'orientation-requested-supported':
1841
+			case 'orientation-requested-default':
1842
+				switch ($value_parsed)
1843
+				{
1844
+					case 0x03:
1845
+						$value = 'portrait';
1846
+						break;
1847
+					case 0x04:
1848
+						$value = 'landscape';
1849
+						break;
1850
+					case 0x05:
1851
+						$value = 'reverse-landscape';
1852
+						break;
1853
+					case 0x06:
1854
+						$value = 'reverse-portrait';
1855
+						break;
1856
+				}
1857
+				if ($value_parsed > 0x06)
1858
+				{
1859
+					$value = sprintf('Unknown(IETF standards track "orientation" reserved): 0x%x',$value_parsed);
1860
+				}
1861
+				break;
1862
+
1863
+			default:
1864
+				break;
1865
+		}
1866
+		return $value;
1867
+	}
1868
+
1869
+	protected function _getJobId ()
1870
+	{
1871
+		if (!isset($this->serveroutput->response))
1872
+		{
1873
+			$this->jobs = array_merge($this->jobs,array('NO JOB'));
1874
+		}
1875
+
1876
+		$jobfinded = false;
1877
+		for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
1878
+		{
1879
+			if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
1880
+			{
1881
+				for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
1882
+				{
1883
+					if ($this->serveroutput->response[$i][$j]['name'] == "job-id")
1884
+					{
1885
+						$this->last_job = $this->serveroutput->response[$i][$j]['value'];
1886
+						$this->jobs = array_merge($this->jobs,array($this->serveroutput->response[$i][$j]['value']));
1887
+						return;
1888
+					}
1889
+				}
1890
+			}
1891
+		}
1892
+	}
1893
+
1894
+	protected function _getJobUri ()
1895
+	{
1896
+		if (!isset($this->jobs_uri))
1897
+		{
1898
+			$this->jobs_uri = array();
1899
+		}
1900
+
1901
+		$jobfinded = false;
1902
+		for ($i = 0 ; (!$jobfinded && array_key_exists($i,$this->serveroutput->response)) ; $i ++)
1903
+		{
1904
+			if (($this->serveroutput->response[$i]['attributes']) == "job-attributes")
1905
+			{
1906
+				for ($j = 0 ; array_key_exists($j,$this->serveroutput->response[$i]) ; $j++)
1907
+				{
1908
+					if ($this->serveroutput->response[$i][$j]['name'] == "job-uri")
1909
+					{
1910
+						$this->last_job = $this->serveroutput->response[$i][$j]['value'];
1911
+						$this->jobs_uri = array_merge($this->jobs_uri,array($this->last_job));
1912
+						return;
1913
+					}
1914
+				}
1915
+			}
1916
+		}
1917
+		$this->last_job = '';
1918
+	}
1919
+
1920
+	protected function _parseResponse ()
1921 1921
    {
1922
-        $j = -1;
1923
-        $this->index = 0;
1924
-        for ($i = $this->_parsing->offset; $i < strlen($this->serveroutput->body) ; $i = $this->_parsing->offset)
1925
-        {
1926
-            $tag = ord($this->serveroutput->body[$this->_parsing->offset]);
1927
-
1928
-            if ($tag > 0x0F)
1929
-            {
1930
-                self::_readAttribute($j);
1931
-                $this->index ++;
1932
-                continue;
1933
-            }
1934
-
1935
-            switch ($tag)
1936
-            {
1937
-                case 0x01:
1938
-                    $j += 1;
1939
-                    $this->serveroutput->response[$j]['attributes'] = "operation-attributes";
1940
-                    $this->index = 0;
1941
-                    $this->_parsing->offset += 1;
1942
-                    break;
1943
-                case 0x02:
1944
-                    $j += 1;
1945
-                    $this->serveroutput->response[$j]['attributes'] = "job-attributes";
1946
-                    $this->index = 0;
1947
-                    $this->_parsing->offset += 1;
1948
-                    break;
1949
-                case 0x03:
1950
-                    $j +=1;
1951
-                    $this->serveroutput->response[$j]['attributes'] = "end-of-attributes";
1952
-                    self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n");
1953
-                    if ($this->alert_on_end_tag === 1)
1954
-                    {
1955
-                        echo "END tag OK<br />";
1956
-                    }
1957
-                    $this->response_completed[(count($this->response_completed) -1)] = "completed";
1958
-                    return;
1959
-                case 0x04:
1960
-                    $j += 1;
1961
-                    $this->serveroutput->response[$j]['attributes'] = "printer-attributes";
1962
-                    $this->index = 0;
1963
-                    $this->_parsing->offset += 1;
1964
-                    break;
1965
-                case 0x05:
1966
-                    $j += 1;
1967
-                    $this->serveroutput->response[$j]['attributes'] = "unsupported-attributes";
1968
-                    $this->index = 0;
1969
-                    $this->_parsing->offset += 1;
1970
-                    break;
1971
-                default:
1972
-                    $j += 1;
1973
-                    $this->serveroutput->response[$j]['attributes'] = sprintf(_("0x%x (%u) : attributes tag Unknown (reserved for future versions of IPP"),$tag,$tag);
1974
-                    $this->index = 0;
1975
-                    $this->_parsing->offset += 1;
1976
-                    break;
1977
-            }
1978
-
1979
-            self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n\n\n");
1980
-        }
1981
-        return;
1982
-    }
1983
-
1984
-    /*
1922
+		$j = -1;
1923
+		$this->index = 0;
1924
+		for ($i = $this->_parsing->offset; $i < strlen($this->serveroutput->body) ; $i = $this->_parsing->offset)
1925
+		{
1926
+			$tag = ord($this->serveroutput->body[$this->_parsing->offset]);
1927
+
1928
+			if ($tag > 0x0F)
1929
+			{
1930
+				self::_readAttribute($j);
1931
+				$this->index ++;
1932
+				continue;
1933
+			}
1934
+
1935
+			switch ($tag)
1936
+			{
1937
+				case 0x01:
1938
+					$j += 1;
1939
+					$this->serveroutput->response[$j]['attributes'] = "operation-attributes";
1940
+					$this->index = 0;
1941
+					$this->_parsing->offset += 1;
1942
+					break;
1943
+				case 0x02:
1944
+					$j += 1;
1945
+					$this->serveroutput->response[$j]['attributes'] = "job-attributes";
1946
+					$this->index = 0;
1947
+					$this->_parsing->offset += 1;
1948
+					break;
1949
+				case 0x03:
1950
+					$j +=1;
1951
+					$this->serveroutput->response[$j]['attributes'] = "end-of-attributes";
1952
+					self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n");
1953
+					if ($this->alert_on_end_tag === 1)
1954
+					{
1955
+						echo "END tag OK<br />";
1956
+					}
1957
+					$this->response_completed[(count($this->response_completed) -1)] = "completed";
1958
+					return;
1959
+				case 0x04:
1960
+					$j += 1;
1961
+					$this->serveroutput->response[$j]['attributes'] = "printer-attributes";
1962
+					$this->index = 0;
1963
+					$this->_parsing->offset += 1;
1964
+					break;
1965
+				case 0x05:
1966
+					$j += 1;
1967
+					$this->serveroutput->response[$j]['attributes'] = "unsupported-attributes";
1968
+					$this->index = 0;
1969
+					$this->_parsing->offset += 1;
1970
+					break;
1971
+				default:
1972
+					$j += 1;
1973
+					$this->serveroutput->response[$j]['attributes'] = sprintf(_("0x%x (%u) : attributes tag Unknown (reserved for future versions of IPP"),$tag,$tag);
1974
+					$this->index = 0;
1975
+					$this->_parsing->offset += 1;
1976
+					break;
1977
+			}
1978
+
1979
+			self::_putDebug( "tag is: ".$this->serveroutput->response[$j]['attributes']."\n\n\n");
1980
+		}
1981
+		return;
1982
+	}
1983
+
1984
+	/*
1985 1985
     // NOTICE : HAVE TO READ AGAIN RFC 2911 TO SEE IF IT IS PART OF SERVER'S RESPONSE (CUPS DO NOT)
1986 1986
 
1987 1987
     protected function _getPrinterUri () {
@@ -2002,53 +2002,53 @@  discard block
 block discarded – undo
2002 2002
 
2003 2003
     */
2004 2004
 
2005
-    // REQUEST BUILDING
2006
-    protected function _stringCancel ($job_uri)
2007
-    {
2005
+	// REQUEST BUILDING
2006
+	protected function _stringCancel ($job_uri)
2007
+	{
2008 2008
     
2009
-        if (!isset($this->setup->charset))
2010
-        {
2011
-            self::setCharset();
2012
-        }
2013
-        if (!isset($this->setup->datatype))
2014
-        {
2015
-            self::setBinary();
2016
-        }
2017
-        if (!isset($this->setup->language))
2018
-        {
2019
-            self::setLanguage('en_us');
2020
-        }
2021
-        if (!$this->requesting_user)   
2022
-        {
2023
-            self::setUserName();
2024
-        }
2025
-        if (!isset($this->meta->message))
2026
-        {
2027
-            $this->meta->message = '';
2028
-        }
2029
-
2030
-        self::_setOperationId();
2031
-
2032
-        self::_setJobUri($job_uri);
2033
-
2034
-        if (!isset($this->error_generation->request_body_malformed))
2035
-        {
2036
-            $this->error_generation->request_body_malformed = "";
2037
-        }
2038
-
2039
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
2040
-                         . chr(0x00) . chr (0x08) // cancel-Job | operation-id
2041
-                         . $this->meta->operation_id //           request-id
2042
-                         . $this->error_generation->request_body_malformed
2043
-                         . chr(0x01) // start operation-attributes | operation-attributes-tag
2044
-                         . $this->meta->charset
2045
-                         . $this->meta->language
2046
-                         . $this->meta->job_uri
2047
-                         . $this->meta->username
2048
-                         . $this->meta->message
2049
-                         . chr(0x03); // end-of-attributes | end-of-attributes-tag
2009
+		if (!isset($this->setup->charset))
2010
+		{
2011
+			self::setCharset();
2012
+		}
2013
+		if (!isset($this->setup->datatype))
2014
+		{
2015
+			self::setBinary();
2016
+		}
2017
+		if (!isset($this->setup->language))
2018
+		{
2019
+			self::setLanguage('en_us');
2020
+		}
2021
+		if (!$this->requesting_user)   
2022
+		{
2023
+			self::setUserName();
2024
+		}
2025
+		if (!isset($this->meta->message))
2026
+		{
2027
+			$this->meta->message = '';
2028
+		}
2029
+
2030
+		self::_setOperationId();
2031
+
2032
+		self::_setJobUri($job_uri);
2033
+
2034
+		if (!isset($this->error_generation->request_body_malformed))
2035
+		{
2036
+			$this->error_generation->request_body_malformed = "";
2037
+		}
2038
+
2039
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
2040
+						 . chr(0x00) . chr (0x08) // cancel-Job | operation-id
2041
+						 . $this->meta->operation_id //           request-id
2042
+						 . $this->error_generation->request_body_malformed
2043
+						 . chr(0x01) // start operation-attributes | operation-attributes-tag
2044
+						 . $this->meta->charset
2045
+						 . $this->meta->language
2046
+						 . $this->meta->job_uri
2047
+						 . $this->meta->username
2048
+						 . $this->meta->message
2049
+						 . chr(0x03); // end-of-attributes | end-of-attributes-tag
2050 2050
                          
2051
-        self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
2052
-        return TRUE;
2053
-    }
2051
+		self::_putDebug( sprintf(_("String sent to the server is:\n%s\n"), $this->stringjob));
2052
+		return TRUE;
2053
+	}
2054 2054
 }
Please login to merge, or discard this patch.
htdocs/includes/printipp/BasicIPP.php 1 patch
Indentation   +1922 added lines, -1922 removed lines patch added patch discarded remove patch
@@ -40,333 +40,333 @@  discard block
 block discarded – undo
40 40
 
41 41
 class ippException extends \Exception
42 42
 {
43
-    protected $errno;
44
-
45
-    public function __construct($msg, $errno = null)
46
-    {
47
-        parent::__construct($msg);
48
-        $this->errno = $errno;
49
-    }
50
-
51
-    public function getErrorFormatted()
52
-    {
53
-        $return = sprintf("[ipp]: %s -- " . _(" file %s, line %s"),
54
-            $this->getMessage() , $this->getFile() , $this->getLine());
55
-        return $return;
56
-    }
57
-
58
-    public function getErrno()
59
-    {
60
-        return $this->errno;
61
-    }
43
+	protected $errno;
44
+
45
+	public function __construct($msg, $errno = null)
46
+	{
47
+		parent::__construct($msg);
48
+		$this->errno = $errno;
49
+	}
50
+
51
+	public function getErrorFormatted()
52
+	{
53
+		$return = sprintf("[ipp]: %s -- " . _(" file %s, line %s"),
54
+			$this->getMessage() , $this->getFile() , $this->getLine());
55
+		return $return;
56
+	}
57
+
58
+	public function getErrno()
59
+	{
60
+		return $this->errno;
61
+	}
62 62
 }
63 63
 
64 64
 class BasicIPP
65 65
 {
66
-    public $paths = array(
67
-        "root" => "/",
68
-        "admin" => "/admin/",
69
-        "printers" => "/printers/",
70
-        "jobs" => "/jobs/"
71
-    );
72
-    public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30.
73
-    public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30.
74
-    public $ssl = false;
75
-    public $debug_level = 3; // max 3: almost silent
76
-    public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and  reads while end tag)
77
-    public $with_exceptions = 1; // compatibility mode for old scripts		// DOL_LDR_CHANGE set this to 1
78
-    public $handle_http_exceptions = 1;
79
-
80
-    // readables variables
81
-    public $jobs = array();
82
-    public $jobs_uri = array();
83
-    public $status = array();
84
-    public $response_completed = array();
85
-    public $last_job = "";
86
-    public $attributes; // object you can read: attributes after validateJob()
87
-    public $printer_attributes; // object you can read: printer's attributes after getPrinterAttributes()
88
-    public $job_attributes; // object you can read: last job attributes
89
-    public $jobs_attributes; // object you can read: jobs attributes after getJobs()
90
-    public $available_printers = array();
91
-    public $printer_map = array();
92
-    public $printers_uri = array();
93
-    public $debug = array();
94
-    public $response;
95
-    public $meta;
96
-
97
-    // protected variables;
98
-    protected $log_level = 2; // max 3: very verbose
99
-    protected $log_type = 3; // 3: file | 1: e-mail | 0: logger
100
-    protected $log_destination; // e-mail or file
101
-    protected $serveroutput;
102
-    protected $setup;
103
-    protected $stringjob;
104
-    protected $data;
105
-    protected $debug_count = 0;
106
-    protected $username;
107
-    protected $charset;
108
-    protected $password;
109
-    protected $requesring_user;
110
-    protected $client_hostname = "localhost";
111
-    protected $stream;
112
-    protected $host = "localhost";
113
-    protected $port = "631";
114
-    protected $requesting_user = '';
115
-    protected $printer_uri;
116
-    protected $timeout = "20"; //20 secs
117
-    protected $errNo;
118
-    protected $errStr;
119
-    protected $datatype;
120
-    protected $datahead;
121
-    protected $datatail;
122
-    protected $operation_id;
123
-    protected $delay;
124
-    protected $error_generation; //devel feature
125
-    protected $debug_http = 0;
126
-    protected $no_disconnect;
127
-    protected $job_tags;
128
-    protected $operation_tags;
129
-    protected $index;
130
-    protected $collection; //RFC3382
131
-    protected $collection_index; //RFC3382
132
-    protected $collection_key = array(); //RFC3382
133
-    protected $collection_depth = - 1; //RFC3382
134
-    protected $end_collection = false; //RFC3382
135
-    protected $collection_nbr = array(); //RFC3382
136
-    protected $unix = false; // true -> use unix sockets instead of http
137
-    protected $output;
138
-
139
-    public function __construct()
140
-    {
141
-        $tz = getenv("date.timezone");
142
-        if (!$tz)
143
-        {
144
-            $tz = @date_default_timezone_get();
145
-        }
146
-
147
-        date_default_timezone_set($tz);
148
-        $this->meta = new \stdClass();
149
-        $this->setup = new \stdClass();
150
-        $this->values = new \stdClass();
151
-        $this->serveroutput = new \stdClass();
152
-        $this->error_generation = new \stdClass();
153
-        $this->_parsing = new \stdClass();
154
-        self::_initTags();
155
-    }
156
-
157
-    public function setPort($port = '631')
158
-    {
159
-        $this->port = $port;
160
-        self::_putDebug("Port is " . $this->port, 2);
161
-    }
162
-
163
-    public function setUnix($socket = '/var/run/cups/cups.sock')
164
-    {
165
-        $this->host = $socket;
166
-        $this->unix = true;
167
-        self::_putDebug("Host is " . $this->host, 2);
168
-    }
169
-
170
-    public function setHost($host = 'localhost')
171
-    {
172
-        $this->host = $host;
173
-        $this->unix = false;
174
-        self::_putDebug("Host is " . $this->host, 2);
175
-    }
176
-
177
-    public function setTimeout($timeout)
178
-    {
179
-        $this->timeout = $timeout;
180
-    }
181
-
182
-    public function setPrinterURI($uri)
183
-    {
184
-        $length = strlen($uri);
185
-        $length = chr($length);
186
-        while (strlen($length) < 2) $length = chr(0x00) . $length;
187
-        $this->meta->printer_uri = chr(0x45) // uri type | value-tag
188
-            . chr(0x00) . chr(0x0B) // name-length
189
-            . "printer-uri" // printer-uri | name
190
-            . $length . $uri;
191
-        $this->printer_uri = $uri;
192
-        self::_putDebug(sprintf(_("Printer URI: %s") , $uri) , 2);
193
-        $this->setup->uri = 1;
194
-    }
195
-
196
-    public function setData($data)
197
-    {
198
-        $this->data = $data;
199
-        self::_putDebug("Data set", 2);
200
-    }
201
-
202
-    public function setRawText()
203
-    {
204
-        $this->setup->datatype = 'TEXT';
205
-        $this->meta->mime_media_type = "";
206
-        $this->setup->mime_media_type = 1;
207
-        $this->datahead = chr(0x16);
208
-        if (is_readable($this->data))
209
-        {
210
-            //It's a filename.  Open and stream.
211
-            $data = fopen($this->data, "rb");
212
-            while (!feof($data)) $output = fread($data, 8192);
213
-        }
214
-        else
215
-        {
216
-            $output = $this->data;
217
-        }
218
-        if (substr($output, -1, 1) != chr(0x0c)) {
219
-            if (!isset($this->setup->noFormFeed))
220
-            {
221
-                $this->datatail = chr(0x0c);
222
-            }
223
-        }
224
-        self::_putDebug(_("Forcing data to be interpreted as RAW TEXT") , 2);
225
-    }
226
-
227
-    public function unsetRawText()
228
-    {
229
-        $this->setup->datatype = 'BINARY';
230
-        $this->datahead = '';
231
-        $this->datatail = '';
232
-        self::_putDebug(_("Unset forcing data to be interpreted as RAW TEXT") , 2);
233
-    }
234
-
235
-    public function setBinary()
236
-    {
237
-        self::unsetRawText();
238
-    }
239
-
240
-    public function setFormFeed()
241
-    {
242
-        $this->datatail = "\r\n" . chr(0x0c);
243
-        unset($this->setup->noFormFeed);
244
-    }
245
-
246
-    public function unsetFormFeed()
247
-    {
248
-        $this->datatail = '';
249
-        $this->setup->noFormFeed = 1;
250
-    }
251
-
252
-    public function setCharset($charset = 'utf-8')
253
-    {
254
-        $charset = strtolower($charset);
255
-        $this->charset = $charset;
256
-        $this->meta->charset = chr(0x47) // charset type | value-tag
257
-            . chr(0x00) . chr(0x12) // name-length
258
-            . "attributes-charset" // attributes-charset | name
259
-            . self::_giveMeStringLength($charset) // value-length
260
-            . $charset; // value
261
-        self::_putDebug(sprintf(_("Charset: %s") , $charset) , 2);
262
-        $this->setup->charset = 1;
263
-    }
264
-
265
-    public function setLanguage($language = 'en_us')
266
-    {
267
-        $language = strtolower($language);
268
-        $this->meta->language = chr(0x48) // natural-language type | value-tag
269
-            . chr(0x00) . chr(0x1B) //  name-length
270
-            . "attributes-natural-language" //attributes-natural-language
271
-            . self::_giveMeStringLength($language) // value-length
272
-            . $language; // value
273
-        self::_putDebug(sprintf(_("Language: %s") , $language) , 2);
274
-        $this->setup->language = 1;
275
-    }
276
-
277
-    public function setDocumentFormat($mime_media_type = 'application/octet-stream')
278
-    {
279
-        self::setBinary();
280
-        $length = chr(strlen($mime_media_type));
281
-        while (strlen($length) < 2) $length = chr(0x00) . $length;
282
-        self::_putDebug(sprintf(_("mime type: %s") , $mime_media_type) , 2);
283
-        $this->meta->mime_media_type = chr(0x49) // document-format tag
284
-            . self::_giveMeStringLength('document-format') . 'document-format' //
285
-            . self::_giveMeStringLength($mime_media_type) . $mime_media_type; // value
286
-        $this->setup->mime_media_type = 1;
287
-    }
288
-
289
-    // setDocumentFormat alias for backward compatibility
290
-    public function setMimeMediaType($mime_media_type = "application/octet-stream")
291
-    {
292
-        self::setDocumentFormat($mime_media_type);
293
-    }
294
-
295
-    public function setCopies($nbrcopies = 1)
296
-    {
297
-        $this->meta->copies = "";
298
-
299
-        if ($nbrcopies == 1 || !$nbrcopies)
300
-        {
301
-            return true;
302
-        }
303
-
304
-        $copies = self::_integerBuild($nbrcopies);
305
-        $this->meta->copies = chr(0x21) // integer type | value-tag
306
-            . chr(0x00) . chr(0x06) //             name-length
307
-            . "copies" // copies    |             name
308
-            . self::_giveMeStringLength($copies) // value-length
309
-            . $copies;
310
-        self::_putDebug(sprintf(_("Copies: %s") , $nbrcopies) , 2);
311
-        $this->setup->copies = 1;
312
-    }
313
-
314
-    public function setDocumentName($document_name = "")
315
-    {
316
-        $this->meta->document_name = "";
317
-        if (!$document_name) {
318
-            return true;
319
-        }
320
-        $document_name = substr($document_name, 0, 1023);
321
-        $length = strlen($document_name);
322
-        $length = chr($length);
323
-        while (strlen($length) < 2) $length = chr(0x00) . $length;
324
-        self::_putDebug(sprintf(_("document name: %s") , $document_name) , 2);
325
-        $this->meta->document_name = chr(0x41) // textWithoutLanguage tag
326
-            . chr(0x00) . chr(0x0d) // name-length
327
-            . "document-name" // mimeMediaType
328
-            . self::_giveMeStringLength($document_name) . $document_name; // value
329
-
330
-    }
331
-
332
-    public function setJobName($jobname = '', $absolute = false)
333
-    {
334
-        $this->meta->jobname = '';
335
-        if ($jobname == '')
336
-        {
337
-            $this->meta->jobname = '';
338
-            return true;
339
-        }
340
-        $postpend = date('-H:i:s-') . $this->_setJobId();
341
-        if ($absolute) {
342
-            $postpend = '';
343
-        }
344
-        if (isset($this->values->jobname) && $jobname == '(PHP)')
345
-        {
346
-            $jobname = $this->values->jobname;
347
-        }
348
-        $this->values->jobname = $jobname;
349
-        $jobname.= $postpend;
350
-        $this->meta->jobname = chr(0x42) // nameWithoutLanguage type || value-tag
351
-            . chr(0x00) . chr(0x08) //  name-length
352
-            . "job-name" //  job-name || name
353
-            . self::_giveMeStringLength($jobname) // value-length
354
-            . $jobname; // value
355
-        self::_putDebug(sprintf(_("Job name: %s") , $jobname) , 2);
356
-        $this->setup->jobname = 1;
357
-    }
358
-
359
-    public function setUserName($username = 'PHP-SERVER')
360
-    {
361
-        $this->requesting_user = $username;
362
-        $this->meta->username = '';
363
-        if (!$username) {
364
-            return true;
365
-        }
366
-        if ($username == 'PHP-SERVER' && isset($this->meta->username)) {
367
-            return TRUE;
368
-        }
369
-        /*
66
+	public $paths = array(
67
+		"root" => "/",
68
+		"admin" => "/admin/",
69
+		"printers" => "/printers/",
70
+		"jobs" => "/jobs/"
71
+	);
72
+	public $http_timeout = 30; // timeout at http connection (seconds) 0 => default => 30.
73
+	public $http_data_timeout = 30; // data reading timeout (milliseconds) 0 => default => 30.
74
+	public $ssl = false;
75
+	public $debug_level = 3; // max 3: almost silent
76
+	public $alert_on_end_tag; // debugging purpose: echo "END tag OK" if (1 and  reads while end tag)
77
+	public $with_exceptions = 1; // compatibility mode for old scripts		// DOL_LDR_CHANGE set this to 1
78
+	public $handle_http_exceptions = 1;
79
+
80
+	// readables variables
81
+	public $jobs = array();
82
+	public $jobs_uri = array();
83
+	public $status = array();
84
+	public $response_completed = array();
85
+	public $last_job = "";
86
+	public $attributes; // object you can read: attributes after validateJob()
87
+	public $printer_attributes; // object you can read: printer's attributes after getPrinterAttributes()
88
+	public $job_attributes; // object you can read: last job attributes
89
+	public $jobs_attributes; // object you can read: jobs attributes after getJobs()
90
+	public $available_printers = array();
91
+	public $printer_map = array();
92
+	public $printers_uri = array();
93
+	public $debug = array();
94
+	public $response;
95
+	public $meta;
96
+
97
+	// protected variables;
98
+	protected $log_level = 2; // max 3: very verbose
99
+	protected $log_type = 3; // 3: file | 1: e-mail | 0: logger
100
+	protected $log_destination; // e-mail or file
101
+	protected $serveroutput;
102
+	protected $setup;
103
+	protected $stringjob;
104
+	protected $data;
105
+	protected $debug_count = 0;
106
+	protected $username;
107
+	protected $charset;
108
+	protected $password;
109
+	protected $requesring_user;
110
+	protected $client_hostname = "localhost";
111
+	protected $stream;
112
+	protected $host = "localhost";
113
+	protected $port = "631";
114
+	protected $requesting_user = '';
115
+	protected $printer_uri;
116
+	protected $timeout = "20"; //20 secs
117
+	protected $errNo;
118
+	protected $errStr;
119
+	protected $datatype;
120
+	protected $datahead;
121
+	protected $datatail;
122
+	protected $operation_id;
123
+	protected $delay;
124
+	protected $error_generation; //devel feature
125
+	protected $debug_http = 0;
126
+	protected $no_disconnect;
127
+	protected $job_tags;
128
+	protected $operation_tags;
129
+	protected $index;
130
+	protected $collection; //RFC3382
131
+	protected $collection_index; //RFC3382
132
+	protected $collection_key = array(); //RFC3382
133
+	protected $collection_depth = - 1; //RFC3382
134
+	protected $end_collection = false; //RFC3382
135
+	protected $collection_nbr = array(); //RFC3382
136
+	protected $unix = false; // true -> use unix sockets instead of http
137
+	protected $output;
138
+
139
+	public function __construct()
140
+	{
141
+		$tz = getenv("date.timezone");
142
+		if (!$tz)
143
+		{
144
+			$tz = @date_default_timezone_get();
145
+		}
146
+
147
+		date_default_timezone_set($tz);
148
+		$this->meta = new \stdClass();
149
+		$this->setup = new \stdClass();
150
+		$this->values = new \stdClass();
151
+		$this->serveroutput = new \stdClass();
152
+		$this->error_generation = new \stdClass();
153
+		$this->_parsing = new \stdClass();
154
+		self::_initTags();
155
+	}
156
+
157
+	public function setPort($port = '631')
158
+	{
159
+		$this->port = $port;
160
+		self::_putDebug("Port is " . $this->port, 2);
161
+	}
162
+
163
+	public function setUnix($socket = '/var/run/cups/cups.sock')
164
+	{
165
+		$this->host = $socket;
166
+		$this->unix = true;
167
+		self::_putDebug("Host is " . $this->host, 2);
168
+	}
169
+
170
+	public function setHost($host = 'localhost')
171
+	{
172
+		$this->host = $host;
173
+		$this->unix = false;
174
+		self::_putDebug("Host is " . $this->host, 2);
175
+	}
176
+
177
+	public function setTimeout($timeout)
178
+	{
179
+		$this->timeout = $timeout;
180
+	}
181
+
182
+	public function setPrinterURI($uri)
183
+	{
184
+		$length = strlen($uri);
185
+		$length = chr($length);
186
+		while (strlen($length) < 2) $length = chr(0x00) . $length;
187
+		$this->meta->printer_uri = chr(0x45) // uri type | value-tag
188
+			. chr(0x00) . chr(0x0B) // name-length
189
+			. "printer-uri" // printer-uri | name
190
+			. $length . $uri;
191
+		$this->printer_uri = $uri;
192
+		self::_putDebug(sprintf(_("Printer URI: %s") , $uri) , 2);
193
+		$this->setup->uri = 1;
194
+	}
195
+
196
+	public function setData($data)
197
+	{
198
+		$this->data = $data;
199
+		self::_putDebug("Data set", 2);
200
+	}
201
+
202
+	public function setRawText()
203
+	{
204
+		$this->setup->datatype = 'TEXT';
205
+		$this->meta->mime_media_type = "";
206
+		$this->setup->mime_media_type = 1;
207
+		$this->datahead = chr(0x16);
208
+		if (is_readable($this->data))
209
+		{
210
+			//It's a filename.  Open and stream.
211
+			$data = fopen($this->data, "rb");
212
+			while (!feof($data)) $output = fread($data, 8192);
213
+		}
214
+		else
215
+		{
216
+			$output = $this->data;
217
+		}
218
+		if (substr($output, -1, 1) != chr(0x0c)) {
219
+			if (!isset($this->setup->noFormFeed))
220
+			{
221
+				$this->datatail = chr(0x0c);
222
+			}
223
+		}
224
+		self::_putDebug(_("Forcing data to be interpreted as RAW TEXT") , 2);
225
+	}
226
+
227
+	public function unsetRawText()
228
+	{
229
+		$this->setup->datatype = 'BINARY';
230
+		$this->datahead = '';
231
+		$this->datatail = '';
232
+		self::_putDebug(_("Unset forcing data to be interpreted as RAW TEXT") , 2);
233
+	}
234
+
235
+	public function setBinary()
236
+	{
237
+		self::unsetRawText();
238
+	}
239
+
240
+	public function setFormFeed()
241
+	{
242
+		$this->datatail = "\r\n" . chr(0x0c);
243
+		unset($this->setup->noFormFeed);
244
+	}
245
+
246
+	public function unsetFormFeed()
247
+	{
248
+		$this->datatail = '';
249
+		$this->setup->noFormFeed = 1;
250
+	}
251
+
252
+	public function setCharset($charset = 'utf-8')
253
+	{
254
+		$charset = strtolower($charset);
255
+		$this->charset = $charset;
256
+		$this->meta->charset = chr(0x47) // charset type | value-tag
257
+			. chr(0x00) . chr(0x12) // name-length
258
+			. "attributes-charset" // attributes-charset | name
259
+			. self::_giveMeStringLength($charset) // value-length
260
+			. $charset; // value
261
+		self::_putDebug(sprintf(_("Charset: %s") , $charset) , 2);
262
+		$this->setup->charset = 1;
263
+	}
264
+
265
+	public function setLanguage($language = 'en_us')
266
+	{
267
+		$language = strtolower($language);
268
+		$this->meta->language = chr(0x48) // natural-language type | value-tag
269
+			. chr(0x00) . chr(0x1B) //  name-length
270
+			. "attributes-natural-language" //attributes-natural-language
271
+			. self::_giveMeStringLength($language) // value-length
272
+			. $language; // value
273
+		self::_putDebug(sprintf(_("Language: %s") , $language) , 2);
274
+		$this->setup->language = 1;
275
+	}
276
+
277
+	public function setDocumentFormat($mime_media_type = 'application/octet-stream')
278
+	{
279
+		self::setBinary();
280
+		$length = chr(strlen($mime_media_type));
281
+		while (strlen($length) < 2) $length = chr(0x00) . $length;
282
+		self::_putDebug(sprintf(_("mime type: %s") , $mime_media_type) , 2);
283
+		$this->meta->mime_media_type = chr(0x49) // document-format tag
284
+			. self::_giveMeStringLength('document-format') . 'document-format' //
285
+			. self::_giveMeStringLength($mime_media_type) . $mime_media_type; // value
286
+		$this->setup->mime_media_type = 1;
287
+	}
288
+
289
+	// setDocumentFormat alias for backward compatibility
290
+	public function setMimeMediaType($mime_media_type = "application/octet-stream")
291
+	{
292
+		self::setDocumentFormat($mime_media_type);
293
+	}
294
+
295
+	public function setCopies($nbrcopies = 1)
296
+	{
297
+		$this->meta->copies = "";
298
+
299
+		if ($nbrcopies == 1 || !$nbrcopies)
300
+		{
301
+			return true;
302
+		}
303
+
304
+		$copies = self::_integerBuild($nbrcopies);
305
+		$this->meta->copies = chr(0x21) // integer type | value-tag
306
+			. chr(0x00) . chr(0x06) //             name-length
307
+			. "copies" // copies    |             name
308
+			. self::_giveMeStringLength($copies) // value-length
309
+			. $copies;
310
+		self::_putDebug(sprintf(_("Copies: %s") , $nbrcopies) , 2);
311
+		$this->setup->copies = 1;
312
+	}
313
+
314
+	public function setDocumentName($document_name = "")
315
+	{
316
+		$this->meta->document_name = "";
317
+		if (!$document_name) {
318
+			return true;
319
+		}
320
+		$document_name = substr($document_name, 0, 1023);
321
+		$length = strlen($document_name);
322
+		$length = chr($length);
323
+		while (strlen($length) < 2) $length = chr(0x00) . $length;
324
+		self::_putDebug(sprintf(_("document name: %s") , $document_name) , 2);
325
+		$this->meta->document_name = chr(0x41) // textWithoutLanguage tag
326
+			. chr(0x00) . chr(0x0d) // name-length
327
+			. "document-name" // mimeMediaType
328
+			. self::_giveMeStringLength($document_name) . $document_name; // value
329
+
330
+	}
331
+
332
+	public function setJobName($jobname = '', $absolute = false)
333
+	{
334
+		$this->meta->jobname = '';
335
+		if ($jobname == '')
336
+		{
337
+			$this->meta->jobname = '';
338
+			return true;
339
+		}
340
+		$postpend = date('-H:i:s-') . $this->_setJobId();
341
+		if ($absolute) {
342
+			$postpend = '';
343
+		}
344
+		if (isset($this->values->jobname) && $jobname == '(PHP)')
345
+		{
346
+			$jobname = $this->values->jobname;
347
+		}
348
+		$this->values->jobname = $jobname;
349
+		$jobname.= $postpend;
350
+		$this->meta->jobname = chr(0x42) // nameWithoutLanguage type || value-tag
351
+			. chr(0x00) . chr(0x08) //  name-length
352
+			. "job-name" //  job-name || name
353
+			. self::_giveMeStringLength($jobname) // value-length
354
+			. $jobname; // value
355
+		self::_putDebug(sprintf(_("Job name: %s") , $jobname) , 2);
356
+		$this->setup->jobname = 1;
357
+	}
358
+
359
+	public function setUserName($username = 'PHP-SERVER')
360
+	{
361
+		$this->requesting_user = $username;
362
+		$this->meta->username = '';
363
+		if (!$username) {
364
+			return true;
365
+		}
366
+		if ($username == 'PHP-SERVER' && isset($this->meta->username)) {
367
+			return TRUE;
368
+		}
369
+		/*
370 370
         $value_length = 0x00;
371 371
         for ($i = 0; $i < strlen($username); $i++)
372 372
         {
@@ -375,1610 +375,1610 @@  discard block
 block discarded – undo
375 375
         $value_length = chr($value_length);
376 376
         while (strlen($value_length) < 2) $value_length = chr(0x00) . $value_length;
377 377
         */
378
-        $this->meta->username = chr(0x42) // keyword type || value-tag
379
-            . chr(0x00) . chr(0x14) // name-length
380
-            . "requesting-user-name"
381
-            . self::_giveMeStringLength($username) // value-length
382
-            . $username;
383
-        self::_putDebug(sprintf(_("Username: %s") , $username) , 2);
384
-        $this->setup->username = 1;
385
-    }
386
-
387
-    public function setAuthentification($username, $password)
388
-    {
389
-        self::setAuthentication($username, $password);
390
-    }
391
-
392
-    public function setAuthentication($username, $password)
393
-    {
394
-        $this->password = $password;
395
-        $this->username = $username;
396
-        self::_putDebug(_("Setting password") , 2);
397
-        $this->setup->password = 1;
398
-    }
399
-
400
-    public function setSides($sides = 2)
401
-    {
402
-        $this->meta->sides = '';
403
-        if (!$sides)
404
-        {
405
-            return true;
406
-        }
407
-
408
-        switch ($sides)
409
-        {
410
-            case 1:
411
-                $sides = "one-sided";
412
-                break;
413
-
414
-            case 2:
415
-                $sides = "two-sided-long-edge";
416
-                break;
417
-
418
-            case "2CE":
419
-                $sides = "two-sided-short-edge";
420
-                break;
421
-        }
422
-
423
-        $this->meta->sides = chr(0x44) // keyword type | value-tag
424
-            . chr(0x00) . chr(0x05) //        name-length
425
-            . "sides" // sides |             name
426
-            . self::_giveMeStringLength($sides) //               value-length
427
-            . $sides; // one-sided |          value
428
-        self::_putDebug(sprintf(_("Sides value set to %s") , $sides) , 2);
429
-    }
430
-
431
-    public function setFidelity()
432
-    {
433
-        // whether the server can't replace any attributes
434
-        // (eg, 2 sided print is not possible,
435
-        // so print one sided) and DO NOT THE JOB.
436
-        $this->meta->fidelity = chr(0x22) // boolean type  |  value-tag
437
-            . chr(0x00) . chr(0x16) //                  name-length
438
-            . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name
439
-            . chr(0x00) . chr(0x01) //  value-length
440
-            . chr(0x01); //  true | value
441
-        self::_putDebug(_("Fidelity attribute is set (paranoid mode)") , 3);
442
-    }
443
-
444
-    public function unsetFidelity()
445
-    {
446
-        // whether the server can replace any attributes
447
-        // (eg, 2 sided print is not possible,
448
-        // so print one sided) and DO THE JOB.
449
-        $this->meta->fidelity = chr(0x22) //  boolean type | value-tag
450
-            . chr(0x00) . chr(0x16) //        name-length
451
-            . "ipp-attribute-fidelity" // ipp-attribute-fidelity | name
452
-            . chr(0x00) . chr(0x01) //               value-length
453
-            . chr(0x00); // false |                   value
454
-        self::_putDebug(_("Fidelity attribute is unset") , 2);
455
-    }
456
-
457
-    public function setMessage($message = '')
458
-    {
459
-        $this->meta->message = '';
460
-        if (!$message) {
461
-            return true;
462
-        }
463
-        $this->meta->message =
464
-            chr(0x41) // attribute type = textWithoutLanguage
465
-                . chr(0x00)
466
-                . chr(0x07)
467
-                . "message"
468
-                . self::_giveMeStringLength(substr($message, 0, 127))
469
-                . substr($message, 0, 127);
470
-        self::_putDebug(sprintf(_('Setting message to "%s"') , $message) , 2);
471
-    }
472
-
473
-    public function setPageRanges($page_ranges)
474
-    {
475
-        // $pages_ranges = string:  "1:5 10:25 40:52 ..."
476
-        // to unset, specify an empty string.
477
-        $this->meta->page_range = '';
478
-        if (!$page_ranges) {
479
-            return true;
480
-        }
481
-        $page_ranges = trim(str_replace("-", ":", $page_ranges));
482
-        $first = true;
483
-        #$page_ranges = split(' ', $page_ranges);
484
-        $page_ranges = preg_split('# #', $page_ranges);
485
-        foreach($page_ranges as $page_range)
486
-        {
487
-            $value = self::_rangeOfIntegerBuild($page_range);
488
-            if ($first)
489
-            {
490
-                $this->meta->page_ranges .=
491
-                $this->tags_types['rangeOfInteger']['tag']
492
-                    . self::_giveMeStringLength('page-ranges')
493
-                    . 'page-ranges'
494
-                    . self::_giveMeStringLength($value)
495
-                    . $value;
496
-            }
497
-            else
498
-            {
499
-                $this->meta->page_ranges .=
500
-                $this->tags_types['rangeOfInteger']['tag']
501
-                    . self::_giveMeStringLength('')
502
-                    . self::_giveMeStringLength($value)
503
-                    . $value;
504
-                $first = false;
505
-            }
506
-        }
507
-    }
508
-
509
-    public function setAttribute($attribute, $values)
510
-    {
511
-        $operation_attributes_tags = array_keys($this->operation_tags);
512
-        $job_attributes_tags = array_keys($this->job_tags);
513
-        $printer_attributes_tags = array_keys($this->printer_tags);
514
-        self::unsetAttribute($attribute);
515
-        if (in_array($attribute, $operation_attributes_tags))
516
-        {
517
-            if (!is_array($values))
518
-            {
519
-                self::_setOperationAttribute($attribute, $values);
520
-            }
521
-            else
522
-            {
523
-                foreach($values as $value)
524
-                {
525
-                    self::_setOperationAttribute($attribute, $value);
526
-                }
527
-            }
528
-        }
529
-        elseif (in_array($attribute, $job_attributes_tags))
530
-        {
531
-            if (!is_array($values))
532
-            {
533
-                self::_setJobAttribute($attribute, $values);
534
-            }
535
-            else
536
-            {
537
-                foreach($values as $value)
538
-                {
539
-                    self::_setJobAttribute($attribute, $value);
540
-                }
541
-            }
542
-        }
543
-        elseif (in_array($attribute, $printer_attributes_tags))
544
-        {
545
-            if (!is_array($values))
546
-            {
547
-                self::_setPrinterAttribute($attribute, $values);
548
-            }
549
-            else
550
-            {
551
-                foreach($values as $value)
552
-                {
553
-                    self::_setPrinterAttribute($attribute, $value);
554
-                }
555
-            }
556
-        }
557
-        else
558
-        {
559
-            trigger_error(
560
-                sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
561
-                    $attribute) , E_USER_NOTICE);
562
-            self::_putDebug(
563
-                sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
564
-                    $attribute) , 3);
565
-            self::_errorLog(
566
-                sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
567
-                    $attribute) , 2);
568
-            return FALSE;
569
-        }
570
-    }
571
-
572
-    public function unsetAttribute($attribute)
573
-    {
574
-        $operation_attributes_tags = array_keys($this->operation_tags);
575
-        $job_attributes_tags = array_keys($this->job_tags);
576
-        $printer_attributes_tags = array_keys($this->printer_tags);
577
-        if (in_array($attribute, $operation_attributes_tags))
578
-        {
579
-            unset(
580
-                $this->operation_tags[$attribute]['value'],
581
-                $this->operation_tags[$attribute]['systag']
582
-            );
583
-        }
584
-        elseif (in_array($attribute, $job_attributes_tags))
585
-        {
586
-            unset(
587
-                $this->job_tags[$attribute]['value'],
588
-                $this->job_tags[$attribute]['systag']
589
-            );
590
-        }
591
-        elseif (in_array($attribute, $printer_attributes_tags))
592
-        {
593
-            unset(
594
-                $this->printer_tags[$attribute]['value'],
595
-                $this->printer_tags[$attribute]['systag']
596
-            );
597
-        }
598
-        else
599
-        {
600
-            trigger_error(
601
-                sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
602
-                    $attribute) , E_USER_NOTICE);
603
-            self::_putDebug(
604
-                sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
605
-                    $attribute) , 3);
606
-            self::_errorLog(
607
-                sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
608
-                    $attribute) , 2);
609
-            return FALSE;
610
-        }
611
-        return true;
612
-    }
613
-
614
-    //
615
-    // LOGGING / DEBUGGING
616
-    //
617
-    /**
618
-     * Sets log file destination. Creates the file if has permission.
619
-     *
620
-     * @param string $log_destination
621
-     * @param string $destination_type
622
-     * @param int $level
623
-     *
624
-     * @throws ippException
625
-     */
626
-    public function setLog($log_destination, $destination_type = 'file', $level = 2)
627
-    {
628
-        if (!file_exists($log_destination) && is_writable(dirname($log_destination)))
629
-        {
630
-            touch($log_destination);
631
-            chmod($log_destination, 0777);
632
-        }
633
-
634
-        switch ($destination_type)
635
-        {
636
-            case 'file':
637
-            case 3:
638
-                $this->log_destination = $log_destination;
639
-                $this->log_type = 3;
640
-                break;
641
-
642
-            case 'logger':
643
-            case 0:
644
-                $this->log_destination = '';
645
-                $this->log_type = 0;
646
-                break;
647
-
648
-            case 'e-mail':
649
-            case 1:
650
-                $this->log_destination = $log_destination;
651
-                $this->log_type = 1;
652
-                break;
653
-        }
654
-        $this->log_level = $level;
655
-    }
656
-
657
-    public function printDebug()
658
-    {
659
-        for ($i = 0; $i < $this->debug_count; $i++)
660
-        {
661
-            echo $this->debug[$i], "\n";
662
-        }
663
-        $this->debug = array();
664
-        $this->debug_count = 0;
665
-    }
666
-
667
-    public function getDebug()
668
-    {
669
-        $debug = '';
670
-        for ($i = 0; $i < $this->debug_count; $i++)
671
-        {
672
-            $debug.= $this->debug[$i];
673
-        }
674
-        $this->debug = array();
675
-        $this->debug_count = 0;
676
-        return $debug;
677
-    }
678
-
679
-    //
680
-    // OPERATIONS
681
-    //
682
-    public function printJob()
683
-    {
684
-        // this BASIC version of printJob do not parse server
685
-        // output for job's attributes
686
-        self::_putDebug(
687
-            sprintf(
688
-                "************** Date: %s ***********",
689
-                date('Y-m-d H:i:s')
690
-            )
691
-        );
692
-        if (!$this->_stringJob()) {
693
-            return FALSE;
694
-        }
695
-        if (is_readable($this->data))
696
-        {
697
-            self::_putDebug(_("Printing a FILE"));
698
-            $this->output = $this->stringjob;
699
-            if ($this->setup->datatype == "TEXT")
700
-            {
701
-                $this->output.= chr(0x16);
702
-            }
703
-            $post_values = array(
704
-                "Content-Type" => "application/ipp",
705
-                "Data" => $this->output,
706
-                "File" => $this->data
707
-            );
708
-            if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
709
-            {
710
-                $post_values = array_merge(
711
-                    $post_values,
712
-                    array(
713
-                        "Filetype" => "TEXT"
714
-                    )
715
-                );
716
-            }
717
-        }
718
-        else
719
-        {
720
-            self::_putDebug(_("Printing DATA"));
721
-            $this->output =
722
-                $this->stringjob
723
-                    . $this->datahead
724
-                    . $this->data
725
-                    . $this->datatail;
726
-            $post_values = array(
727
-                "Content-Type" => "application/ipp",
728
-                "Data" => $this->output
729
-            );
730
-        }
731
-        if (self::_sendHttp($post_values, $this->paths["printers"]))
732
-        {
733
-            self::_parseServerOutput();
734
-        }
735
-        if (isset($this->serveroutput) && isset($this->serveroutput->status))
736
-        {
737
-            $this->status = array_merge($this->status, array(
738
-                $this->serveroutput->status
739
-            ));
740
-            if ($this->serveroutput->status == "successfull-ok")
741
-            {
742
-                self::_errorLog(
743
-                    sprintf("printing job %s: ", $this->last_job)
744
-                        . $this->serveroutput->status,
745
-                    3);
746
-            }
747
-            else
748
-            {
749
-                self::_errorLog(
750
-                    sprintf("printing job: ", $this->last_job)
751
-                        . $this->serveroutput->status,
752
-                    1);
753
-            }
754
-                return $this->serveroutput->status;
755
-        }
756
-
757
-    $this->status =
758
-        array_merge($this->status, array("OPERATION FAILED"));
759
-        $this->jobs =
760
-            array_merge($this->jobs, array(""));
761
-        $this->jobs_uri =
762
-            array_merge($this->jobs_uri, array(""));
763
-
764
-        self::_errorLog("printing job : OPERATION FAILED", 1);
765
-        return false;
766
-    }
767
-
768
-    //
769
-    // HTTP OUTPUT
770
-    //
771
-    protected function _sendHttp($post_values, $uri)
772
-    {
773
-        /*
378
+		$this->meta->username = chr(0x42) // keyword type || value-tag
379
+			. chr(0x00) . chr(0x14) // name-length
380
+			. "requesting-user-name"
381
+			. self::_giveMeStringLength($username) // value-length
382
+			. $username;
383
+		self::_putDebug(sprintf(_("Username: %s") , $username) , 2);
384
+		$this->setup->username = 1;
385
+	}
386
+
387
+	public function setAuthentification($username, $password)
388
+	{
389
+		self::setAuthentication($username, $password);
390
+	}
391
+
392
+	public function setAuthentication($username, $password)
393
+	{
394
+		$this->password = $password;
395
+		$this->username = $username;
396
+		self::_putDebug(_("Setting password") , 2);
397
+		$this->setup->password = 1;
398
+	}
399
+
400
+	public function setSides($sides = 2)
401
+	{
402
+		$this->meta->sides = '';
403
+		if (!$sides)
404
+		{
405
+			return true;
406
+		}
407
+
408
+		switch ($sides)
409
+		{
410
+			case 1:
411
+				$sides = "one-sided";
412
+				break;
413
+
414
+			case 2:
415
+				$sides = "two-sided-long-edge";
416
+				break;
417
+
418
+			case "2CE":
419
+				$sides = "two-sided-short-edge";
420
+				break;
421
+		}
422
+
423
+		$this->meta->sides = chr(0x44) // keyword type | value-tag
424
+			. chr(0x00) . chr(0x05) //        name-length
425
+			. "sides" // sides |             name
426
+			. self::_giveMeStringLength($sides) //               value-length
427
+			. $sides; // one-sided |          value
428
+		self::_putDebug(sprintf(_("Sides value set to %s") , $sides) , 2);
429
+	}
430
+
431
+	public function setFidelity()
432
+	{
433
+		// whether the server can't replace any attributes
434
+		// (eg, 2 sided print is not possible,
435
+		// so print one sided) and DO NOT THE JOB.
436
+		$this->meta->fidelity = chr(0x22) // boolean type  |  value-tag
437
+			. chr(0x00) . chr(0x16) //                  name-length
438
+			. "ipp-attribute-fidelity" // ipp-attribute-fidelity | name
439
+			. chr(0x00) . chr(0x01) //  value-length
440
+			. chr(0x01); //  true | value
441
+		self::_putDebug(_("Fidelity attribute is set (paranoid mode)") , 3);
442
+	}
443
+
444
+	public function unsetFidelity()
445
+	{
446
+		// whether the server can replace any attributes
447
+		// (eg, 2 sided print is not possible,
448
+		// so print one sided) and DO THE JOB.
449
+		$this->meta->fidelity = chr(0x22) //  boolean type | value-tag
450
+			. chr(0x00) . chr(0x16) //        name-length
451
+			. "ipp-attribute-fidelity" // ipp-attribute-fidelity | name
452
+			. chr(0x00) . chr(0x01) //               value-length
453
+			. chr(0x00); // false |                   value
454
+		self::_putDebug(_("Fidelity attribute is unset") , 2);
455
+	}
456
+
457
+	public function setMessage($message = '')
458
+	{
459
+		$this->meta->message = '';
460
+		if (!$message) {
461
+			return true;
462
+		}
463
+		$this->meta->message =
464
+			chr(0x41) // attribute type = textWithoutLanguage
465
+				. chr(0x00)
466
+				. chr(0x07)
467
+				. "message"
468
+				. self::_giveMeStringLength(substr($message, 0, 127))
469
+				. substr($message, 0, 127);
470
+		self::_putDebug(sprintf(_('Setting message to "%s"') , $message) , 2);
471
+	}
472
+
473
+	public function setPageRanges($page_ranges)
474
+	{
475
+		// $pages_ranges = string:  "1:5 10:25 40:52 ..."
476
+		// to unset, specify an empty string.
477
+		$this->meta->page_range = '';
478
+		if (!$page_ranges) {
479
+			return true;
480
+		}
481
+		$page_ranges = trim(str_replace("-", ":", $page_ranges));
482
+		$first = true;
483
+		#$page_ranges = split(' ', $page_ranges);
484
+		$page_ranges = preg_split('# #', $page_ranges);
485
+		foreach($page_ranges as $page_range)
486
+		{
487
+			$value = self::_rangeOfIntegerBuild($page_range);
488
+			if ($first)
489
+			{
490
+				$this->meta->page_ranges .=
491
+				$this->tags_types['rangeOfInteger']['tag']
492
+					. self::_giveMeStringLength('page-ranges')
493
+					. 'page-ranges'
494
+					. self::_giveMeStringLength($value)
495
+					. $value;
496
+			}
497
+			else
498
+			{
499
+				$this->meta->page_ranges .=
500
+				$this->tags_types['rangeOfInteger']['tag']
501
+					. self::_giveMeStringLength('')
502
+					. self::_giveMeStringLength($value)
503
+					. $value;
504
+				$first = false;
505
+			}
506
+		}
507
+	}
508
+
509
+	public function setAttribute($attribute, $values)
510
+	{
511
+		$operation_attributes_tags = array_keys($this->operation_tags);
512
+		$job_attributes_tags = array_keys($this->job_tags);
513
+		$printer_attributes_tags = array_keys($this->printer_tags);
514
+		self::unsetAttribute($attribute);
515
+		if (in_array($attribute, $operation_attributes_tags))
516
+		{
517
+			if (!is_array($values))
518
+			{
519
+				self::_setOperationAttribute($attribute, $values);
520
+			}
521
+			else
522
+			{
523
+				foreach($values as $value)
524
+				{
525
+					self::_setOperationAttribute($attribute, $value);
526
+				}
527
+			}
528
+		}
529
+		elseif (in_array($attribute, $job_attributes_tags))
530
+		{
531
+			if (!is_array($values))
532
+			{
533
+				self::_setJobAttribute($attribute, $values);
534
+			}
535
+			else
536
+			{
537
+				foreach($values as $value)
538
+				{
539
+					self::_setJobAttribute($attribute, $value);
540
+				}
541
+			}
542
+		}
543
+		elseif (in_array($attribute, $printer_attributes_tags))
544
+		{
545
+			if (!is_array($values))
546
+			{
547
+				self::_setPrinterAttribute($attribute, $values);
548
+			}
549
+			else
550
+			{
551
+				foreach($values as $value)
552
+				{
553
+					self::_setPrinterAttribute($attribute, $value);
554
+				}
555
+			}
556
+		}
557
+		else
558
+		{
559
+			trigger_error(
560
+				sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
561
+					$attribute) , E_USER_NOTICE);
562
+			self::_putDebug(
563
+				sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
564
+					$attribute) , 3);
565
+			self::_errorLog(
566
+				sprintf(_('SetAttribute: Tag "%s" is not a printer or a job attribute'),
567
+					$attribute) , 2);
568
+			return FALSE;
569
+		}
570
+	}
571
+
572
+	public function unsetAttribute($attribute)
573
+	{
574
+		$operation_attributes_tags = array_keys($this->operation_tags);
575
+		$job_attributes_tags = array_keys($this->job_tags);
576
+		$printer_attributes_tags = array_keys($this->printer_tags);
577
+		if (in_array($attribute, $operation_attributes_tags))
578
+		{
579
+			unset(
580
+				$this->operation_tags[$attribute]['value'],
581
+				$this->operation_tags[$attribute]['systag']
582
+			);
583
+		}
584
+		elseif (in_array($attribute, $job_attributes_tags))
585
+		{
586
+			unset(
587
+				$this->job_tags[$attribute]['value'],
588
+				$this->job_tags[$attribute]['systag']
589
+			);
590
+		}
591
+		elseif (in_array($attribute, $printer_attributes_tags))
592
+		{
593
+			unset(
594
+				$this->printer_tags[$attribute]['value'],
595
+				$this->printer_tags[$attribute]['systag']
596
+			);
597
+		}
598
+		else
599
+		{
600
+			trigger_error(
601
+				sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
602
+					$attribute) , E_USER_NOTICE);
603
+			self::_putDebug(
604
+				sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
605
+					$attribute) , 3);
606
+			self::_errorLog(
607
+				sprintf(_('unsetAttribute: Tag "%s" is not a printer or a job attribute'),
608
+					$attribute) , 2);
609
+			return FALSE;
610
+		}
611
+		return true;
612
+	}
613
+
614
+	//
615
+	// LOGGING / DEBUGGING
616
+	//
617
+	/**
618
+	 * Sets log file destination. Creates the file if has permission.
619
+	 *
620
+	 * @param string $log_destination
621
+	 * @param string $destination_type
622
+	 * @param int $level
623
+	 *
624
+	 * @throws ippException
625
+	 */
626
+	public function setLog($log_destination, $destination_type = 'file', $level = 2)
627
+	{
628
+		if (!file_exists($log_destination) && is_writable(dirname($log_destination)))
629
+		{
630
+			touch($log_destination);
631
+			chmod($log_destination, 0777);
632
+		}
633
+
634
+		switch ($destination_type)
635
+		{
636
+			case 'file':
637
+			case 3:
638
+				$this->log_destination = $log_destination;
639
+				$this->log_type = 3;
640
+				break;
641
+
642
+			case 'logger':
643
+			case 0:
644
+				$this->log_destination = '';
645
+				$this->log_type = 0;
646
+				break;
647
+
648
+			case 'e-mail':
649
+			case 1:
650
+				$this->log_destination = $log_destination;
651
+				$this->log_type = 1;
652
+				break;
653
+		}
654
+		$this->log_level = $level;
655
+	}
656
+
657
+	public function printDebug()
658
+	{
659
+		for ($i = 0; $i < $this->debug_count; $i++)
660
+		{
661
+			echo $this->debug[$i], "\n";
662
+		}
663
+		$this->debug = array();
664
+		$this->debug_count = 0;
665
+	}
666
+
667
+	public function getDebug()
668
+	{
669
+		$debug = '';
670
+		for ($i = 0; $i < $this->debug_count; $i++)
671
+		{
672
+			$debug.= $this->debug[$i];
673
+		}
674
+		$this->debug = array();
675
+		$this->debug_count = 0;
676
+		return $debug;
677
+	}
678
+
679
+	//
680
+	// OPERATIONS
681
+	//
682
+	public function printJob()
683
+	{
684
+		// this BASIC version of printJob do not parse server
685
+		// output for job's attributes
686
+		self::_putDebug(
687
+			sprintf(
688
+				"************** Date: %s ***********",
689
+				date('Y-m-d H:i:s')
690
+			)
691
+		);
692
+		if (!$this->_stringJob()) {
693
+			return FALSE;
694
+		}
695
+		if (is_readable($this->data))
696
+		{
697
+			self::_putDebug(_("Printing a FILE"));
698
+			$this->output = $this->stringjob;
699
+			if ($this->setup->datatype == "TEXT")
700
+			{
701
+				$this->output.= chr(0x16);
702
+			}
703
+			$post_values = array(
704
+				"Content-Type" => "application/ipp",
705
+				"Data" => $this->output,
706
+				"File" => $this->data
707
+			);
708
+			if ($this->setup->datatype == "TEXT" && !isset($this->setup->noFormFeed))
709
+			{
710
+				$post_values = array_merge(
711
+					$post_values,
712
+					array(
713
+						"Filetype" => "TEXT"
714
+					)
715
+				);
716
+			}
717
+		}
718
+		else
719
+		{
720
+			self::_putDebug(_("Printing DATA"));
721
+			$this->output =
722
+				$this->stringjob
723
+					. $this->datahead
724
+					. $this->data
725
+					. $this->datatail;
726
+			$post_values = array(
727
+				"Content-Type" => "application/ipp",
728
+				"Data" => $this->output
729
+			);
730
+		}
731
+		if (self::_sendHttp($post_values, $this->paths["printers"]))
732
+		{
733
+			self::_parseServerOutput();
734
+		}
735
+		if (isset($this->serveroutput) && isset($this->serveroutput->status))
736
+		{
737
+			$this->status = array_merge($this->status, array(
738
+				$this->serveroutput->status
739
+			));
740
+			if ($this->serveroutput->status == "successfull-ok")
741
+			{
742
+				self::_errorLog(
743
+					sprintf("printing job %s: ", $this->last_job)
744
+						. $this->serveroutput->status,
745
+					3);
746
+			}
747
+			else
748
+			{
749
+				self::_errorLog(
750
+					sprintf("printing job: ", $this->last_job)
751
+						. $this->serveroutput->status,
752
+					1);
753
+			}
754
+				return $this->serveroutput->status;
755
+		}
756
+
757
+	$this->status =
758
+		array_merge($this->status, array("OPERATION FAILED"));
759
+		$this->jobs =
760
+			array_merge($this->jobs, array(""));
761
+		$this->jobs_uri =
762
+			array_merge($this->jobs_uri, array(""));
763
+
764
+		self::_errorLog("printing job : OPERATION FAILED", 1);
765
+		return false;
766
+	}
767
+
768
+	//
769
+	// HTTP OUTPUT
770
+	//
771
+	protected function _sendHttp($post_values, $uri)
772
+	{
773
+		/*
774 774
             This function Copyright (C) 2005-2006 Thomas Harding, Manuel Lemos
775 775
         */
776
-        $this->response_completed[] = "no";
777
-        unset($this->serverouptut);
778
-        self::_putDebug(_("Processing HTTP request") , 2);
779
-        $this->serveroutput->headers = array();
780
-        $this->serveroutput->body = "";
781
-        $http = new http_class;
782
-        if (!$this->unix) {
783
-        	// DOL_LDR_CHANGE
784
-        	if (empty($this->host)) $this->host='127.0.0.1';
785
-            $http->host = $this->host;
786
-        }
787
-        else {
788
-            $http->host = "localhost";
789
-        }
790
-        $http->with_exceptions = $this->with_exceptions;
791
-        if ($this->debug_http)
792
-        {
793
-            $http->debug = 1;
794
-            $http->html_debug = 0;
795
-        }
796
-        else
797
-        {
798
-            $http->debug = 0;
799
-            $http->html_debug = 0;
800
-        }
801
-        $url = "http://" . $this->host;
802
-        if ($this->ssl) {
803
-            $url = "https://" . $this->host;
804
-        }
805
-        if ($this->unix) {
806
-            $url = "unix://" . $this->host;
807
-        }
808
-        $http->port = $this->port;
809
-        $http->timeout = $this->http_timeout;
810
-        $http->data_timeout = $this->http_data_timeout;
811
-        $http->force_multipart_form_post = false;
812
-        $http->user = $this->username;
813
-        $http->password = $this->password;
814
-        $error = $http->GetRequestArguments($url, $arguments);
815
-        $arguments["RequestMethod"] = "POST";
816
-        $arguments["Headers"] = array(
817
-            "Content-Type" => "application/ipp"
818
-        );
819
-        $arguments["BodyStream"] = array(
820
-            array(
821
-                "Data" => $post_values["Data"]
822
-            )
823
-        );
824
-        if (isset($post_values["File"])) {
825
-            $arguments["BodyStream"][] = array(
826
-                "File" => $post_values["File"]
827
-            );
828
-        }
829
-        if (isset($post_values["FileType"])
830
-            && !strcmp($post_values["FileType"], "TEXT")
831
-        )
832
-        {
833
-            $arguments["BodyStream"][] = array("Data" => Chr(12));
834
-        }
835
-        $arguments["RequestURI"] = $uri;
836
-        if ($this->with_exceptions && $this->handle_http_exceptions)
837
-        {
838
-            try
839
-            {
840
-                $success = $http->Open($arguments);
841
-            }
842
-            catch(httpException $e)
843
-            {
844
-                throw new ippException(
845
-                    sprintf("http error: %s", $e->getMessage()),
846
-                        $e->getErrno());
847
-            }
848
-        }
849
-        else
850
-        {
851
-        	$success = $http->Open($arguments);
852
-        }
853
-        if ($success[0] == true)
854
-        {
855
-            $success = $http->SendRequest($arguments);
856
-            if ($success[0] == true)
857
-            {
858
-                self::_putDebug("H T T P    R E Q U E S T :");
859
-                self::_putDebug("Request headers:");
860
-                for (Reset($http->request_headers) , $header = 0; $header < count($http->request_headers); Next($http->request_headers) , $header++)
861
-                {
862
-                    $header_name = Key($http->request_headers);
863
-                    if (GetType($http->request_headers[$header_name]) == "array")
864
-                    {
865
-                        for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++)
866
-                        {
867
-                            self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]);
868
-                        }
869
-                    }
870
-                    else
871
-                    {
872
-                        self::_putDebug($header_name . ": " . $http->request_headers[$header_name]);
873
-                    }
874
-                }
875
-                self::_putDebug("Request body:");
876
-                self::_putDebug(
877
-                    htmlspecialchars($http->request_body)
878
-                        . "*********** END REQUEST BODY *********"
879
-                );
880
-                $i = 0;
881
-                $headers = array();
882
-                unset($this->serveroutput->headers);
883
-                $http->ReadReplyHeaders($headers);
884
-                self::_putDebug("H T T P    R E S P O N S E :");
885
-                self::_putDebug("Response headers:");
886
-                for (Reset($headers) , $header = 0; $header < count($headers); Next($headers) , $header++)
887
-                {
888
-                    $header_name = Key($headers);
889
-                    if (GetType($headers[$header_name]) == "array")
890
-                    {
891
-                        for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++)
892
-                        {
893
-                            self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]);
894
-                            $this->serveroutput->headers[$i] =
895
-                                $header_name . ": "
896
-                                    . $headers[$header_name][$header_value];
897
-                            $i++;
898
-                        }
899
-                    }
900
-                    else
901
-                    {
902
-                        self::_putDebug($header_name . ": " . $headers[$header_name]);
903
-                        $this->serveroutput->headers[$i] =
904
-                            $header_name
905
-                                . ": "
906
-                                . $headers[$header_name];
907
-                        $i++;
908
-                    }
909
-                }
910
-                self::_putDebug("\n\nResponse body:\n");
911
-                $this->serveroutput->body = "";
912
-                for (;;)
913
-                {
914
-                    $http->ReadReplyBody($body, 1024);
915
-                    if (strlen($body) == 0) {
916
-                        break;
917
-                    }
918
-
919
-                    self::_putDebug(htmlentities($body));
920
-                    $this->serveroutput->body.= $body;
921
-                }
922
-                self::_putDebug("********* END RESPONSE BODY ********");
923
-            }
924
-        }
925
-        $http->Close();
926
-        return true;
927
-    }
928
-
929
-    //
930
-    // INIT
931
-    //
932
-    protected function _initTags()
933
-    {
934
-        $this->tags_types = array(
935
-            "unsupported" => array(
936
-                "tag" => chr(0x10) ,
937
-                "build" => ""
938
-            ) ,
939
-            "reserved" => array(
940
-                "tag" => chr(0x11) ,
941
-                "build" => ""
942
-            ) ,
943
-            "unknown" => array(
944
-                "tag" => chr(0x12) ,
945
-                "build" => ""
946
-            ) ,
947
-            "no-value" => array(
948
-                "tag" => chr(0x13) ,
949
-                "build" => "no_value"
950
-            ) ,
951
-            "integer" => array(
952
-                "tag" => chr(0x21) ,
953
-                "build" => "integer"
954
-            ) ,
955
-            "boolean" => array(
956
-                "tag" => chr(0x22) ,
957
-                "build" => "boolean"
958
-            ) ,
959
-            "enum" => array(
960
-                "tag" => chr(0x23) ,
961
-                "build" => "enum"
962
-            ) ,
963
-            "octetString" => array(
964
-                "tag" => chr(0x30) ,
965
-                "build" => "octet_string"
966
-            ) ,
967
-            "datetime" => array(
968
-                "tag" => chr(0x31) ,
969
-                "build" => "datetime"
970
-            ) ,
971
-            "resolution" => array(
972
-                "tag" => chr(0x32) ,
973
-                "build" => "resolution"
974
-            ) ,
975
-            "rangeOfInteger" => array(
976
-                "tag" => chr(0x33) ,
977
-                "build" => "range_of_integers"
978
-            ) ,
979
-            "textWithLanguage" => array(
980
-                "tag" => chr(0x35) ,
981
-                "build" => "string"
982
-            ) ,
983
-            "nameWithLanguage" => array(
984
-                "tag" => chr(0x36) ,
985
-                "build" => "string"
986
-            ) ,
987
-            /*
776
+		$this->response_completed[] = "no";
777
+		unset($this->serverouptut);
778
+		self::_putDebug(_("Processing HTTP request") , 2);
779
+		$this->serveroutput->headers = array();
780
+		$this->serveroutput->body = "";
781
+		$http = new http_class;
782
+		if (!$this->unix) {
783
+			// DOL_LDR_CHANGE
784
+			if (empty($this->host)) $this->host='127.0.0.1';
785
+			$http->host = $this->host;
786
+		}
787
+		else {
788
+			$http->host = "localhost";
789
+		}
790
+		$http->with_exceptions = $this->with_exceptions;
791
+		if ($this->debug_http)
792
+		{
793
+			$http->debug = 1;
794
+			$http->html_debug = 0;
795
+		}
796
+		else
797
+		{
798
+			$http->debug = 0;
799
+			$http->html_debug = 0;
800
+		}
801
+		$url = "http://" . $this->host;
802
+		if ($this->ssl) {
803
+			$url = "https://" . $this->host;
804
+		}
805
+		if ($this->unix) {
806
+			$url = "unix://" . $this->host;
807
+		}
808
+		$http->port = $this->port;
809
+		$http->timeout = $this->http_timeout;
810
+		$http->data_timeout = $this->http_data_timeout;
811
+		$http->force_multipart_form_post = false;
812
+		$http->user = $this->username;
813
+		$http->password = $this->password;
814
+		$error = $http->GetRequestArguments($url, $arguments);
815
+		$arguments["RequestMethod"] = "POST";
816
+		$arguments["Headers"] = array(
817
+			"Content-Type" => "application/ipp"
818
+		);
819
+		$arguments["BodyStream"] = array(
820
+			array(
821
+				"Data" => $post_values["Data"]
822
+			)
823
+		);
824
+		if (isset($post_values["File"])) {
825
+			$arguments["BodyStream"][] = array(
826
+				"File" => $post_values["File"]
827
+			);
828
+		}
829
+		if (isset($post_values["FileType"])
830
+			&& !strcmp($post_values["FileType"], "TEXT")
831
+		)
832
+		{
833
+			$arguments["BodyStream"][] = array("Data" => Chr(12));
834
+		}
835
+		$arguments["RequestURI"] = $uri;
836
+		if ($this->with_exceptions && $this->handle_http_exceptions)
837
+		{
838
+			try
839
+			{
840
+				$success = $http->Open($arguments);
841
+			}
842
+			catch(httpException $e)
843
+			{
844
+				throw new ippException(
845
+					sprintf("http error: %s", $e->getMessage()),
846
+						$e->getErrno());
847
+			}
848
+		}
849
+		else
850
+		{
851
+			$success = $http->Open($arguments);
852
+		}
853
+		if ($success[0] == true)
854
+		{
855
+			$success = $http->SendRequest($arguments);
856
+			if ($success[0] == true)
857
+			{
858
+				self::_putDebug("H T T P    R E Q U E S T :");
859
+				self::_putDebug("Request headers:");
860
+				for (Reset($http->request_headers) , $header = 0; $header < count($http->request_headers); Next($http->request_headers) , $header++)
861
+				{
862
+					$header_name = Key($http->request_headers);
863
+					if (GetType($http->request_headers[$header_name]) == "array")
864
+					{
865
+						for ($header_value = 0; $header_value < count($http->request_headers[$header_name]); $header_value++)
866
+						{
867
+							self::_putDebug($header_name . ": " . $http->request_headers[$header_name][$header_value]);
868
+						}
869
+					}
870
+					else
871
+					{
872
+						self::_putDebug($header_name . ": " . $http->request_headers[$header_name]);
873
+					}
874
+				}
875
+				self::_putDebug("Request body:");
876
+				self::_putDebug(
877
+					htmlspecialchars($http->request_body)
878
+						. "*********** END REQUEST BODY *********"
879
+				);
880
+				$i = 0;
881
+				$headers = array();
882
+				unset($this->serveroutput->headers);
883
+				$http->ReadReplyHeaders($headers);
884
+				self::_putDebug("H T T P    R E S P O N S E :");
885
+				self::_putDebug("Response headers:");
886
+				for (Reset($headers) , $header = 0; $header < count($headers); Next($headers) , $header++)
887
+				{
888
+					$header_name = Key($headers);
889
+					if (GetType($headers[$header_name]) == "array")
890
+					{
891
+						for ($header_value = 0; $header_value < count($headers[$header_name]); $header_value++)
892
+						{
893
+							self::_putDebug($header_name . ": " . $headers[$header_name][$header_value]);
894
+							$this->serveroutput->headers[$i] =
895
+								$header_name . ": "
896
+									. $headers[$header_name][$header_value];
897
+							$i++;
898
+						}
899
+					}
900
+					else
901
+					{
902
+						self::_putDebug($header_name . ": " . $headers[$header_name]);
903
+						$this->serveroutput->headers[$i] =
904
+							$header_name
905
+								. ": "
906
+								. $headers[$header_name];
907
+						$i++;
908
+					}
909
+				}
910
+				self::_putDebug("\n\nResponse body:\n");
911
+				$this->serveroutput->body = "";
912
+				for (;;)
913
+				{
914
+					$http->ReadReplyBody($body, 1024);
915
+					if (strlen($body) == 0) {
916
+						break;
917
+					}
918
+
919
+					self::_putDebug(htmlentities($body));
920
+					$this->serveroutput->body.= $body;
921
+				}
922
+				self::_putDebug("********* END RESPONSE BODY ********");
923
+			}
924
+		}
925
+		$http->Close();
926
+		return true;
927
+	}
928
+
929
+	//
930
+	// INIT
931
+	//
932
+	protected function _initTags()
933
+	{
934
+		$this->tags_types = array(
935
+			"unsupported" => array(
936
+				"tag" => chr(0x10) ,
937
+				"build" => ""
938
+			) ,
939
+			"reserved" => array(
940
+				"tag" => chr(0x11) ,
941
+				"build" => ""
942
+			) ,
943
+			"unknown" => array(
944
+				"tag" => chr(0x12) ,
945
+				"build" => ""
946
+			) ,
947
+			"no-value" => array(
948
+				"tag" => chr(0x13) ,
949
+				"build" => "no_value"
950
+			) ,
951
+			"integer" => array(
952
+				"tag" => chr(0x21) ,
953
+				"build" => "integer"
954
+			) ,
955
+			"boolean" => array(
956
+				"tag" => chr(0x22) ,
957
+				"build" => "boolean"
958
+			) ,
959
+			"enum" => array(
960
+				"tag" => chr(0x23) ,
961
+				"build" => "enum"
962
+			) ,
963
+			"octetString" => array(
964
+				"tag" => chr(0x30) ,
965
+				"build" => "octet_string"
966
+			) ,
967
+			"datetime" => array(
968
+				"tag" => chr(0x31) ,
969
+				"build" => "datetime"
970
+			) ,
971
+			"resolution" => array(
972
+				"tag" => chr(0x32) ,
973
+				"build" => "resolution"
974
+			) ,
975
+			"rangeOfInteger" => array(
976
+				"tag" => chr(0x33) ,
977
+				"build" => "range_of_integers"
978
+			) ,
979
+			"textWithLanguage" => array(
980
+				"tag" => chr(0x35) ,
981
+				"build" => "string"
982
+			) ,
983
+			"nameWithLanguage" => array(
984
+				"tag" => chr(0x36) ,
985
+				"build" => "string"
986
+			) ,
987
+			/*
988 988
             "text" => array ("tag" => chr(0x40),
989 989
             "build" => "string"),
990 990
             "text string" => array ("tag" => chr(0x40),
991 991
             "build" => "string"),
992 992
             */
993
-            "textWithoutLanguage" => array(
994
-                "tag" => chr(0x41) ,
995
-                "build" => "string"
996
-            ) ,
997
-            "nameWithoutLanguage" => array(
998
-                "tag" => chr(0x42) ,
999
-                "buid" => "string"
1000
-            ) ,
1001
-            "keyword" => array(
1002
-                "tag" => chr(0x44) ,
1003
-                "build" => "string"
1004
-            ) ,
1005
-            "uri" => array(
1006
-                "tag" => chr(0x45) ,
1007
-                "build" => "string"
1008
-            ) ,
1009
-            "uriScheme" => array(
1010
-                "tag" => chr(0x46) ,
1011
-                "build" => "string"
1012
-            ) ,
1013
-            "charset" => array(
1014
-                "tag" => chr(0x47) ,
1015
-                "build" => "string"
1016
-            ) ,
1017
-            "naturalLanguage" => array(
1018
-                "tag" => chr(0x48) ,
1019
-                "build" => "string"
1020
-            ) ,
1021
-            "mimeMediaType" => array(
1022
-                "tag" => chr(0x49) ,
1023
-                "build" => "string"
1024
-            ) ,
1025
-            "extendedAttributes" => array(
1026
-                "tag" => chr(0x7F) ,
1027
-                "build" => "extended"
1028
-            ) ,
1029
-        );
1030
-        $this->operation_tags = array(
1031
-            "compression" => array(
1032
-                "tag" => "keyword"
1033
-            ) ,
1034
-            "document-natural-language" => array(
1035
-                "tag" => "naturalLanguage"
1036
-            ) ,
1037
-            "job-k-octets" => array(
1038
-                "tag" => "integer"
1039
-            ) ,
1040
-            "job-impressions" => array(
1041
-                "tag" => "integer"
1042
-            ) ,
1043
-            "job-media-sheets" => array(
1044
-                "tag" => "integer"
1045
-            ) ,
1046
-        );
1047
-        $this->job_tags = array(
1048
-            "job-priority" => array(
1049
-                "tag" => "integer"
1050
-            ) ,
1051
-            "job-hold-until" => array(
1052
-                "tag" => "keyword"
1053
-            ) ,
1054
-            "job-sheets" => array(
1055
-                "tag" => "keyword"
1056
-            ) , //banner page
1057
-            "multiple-document-handling" => array(
1058
-                "tag" => "keyword"
1059
-            ) ,
1060
-            //"copies" => array("tag" => "integer"),
1061
-            "finishings" => array(
1062
-                "tag" => "enum"
1063
-            ) ,
1064
-            //"page-ranges" => array("tag" => "rangeOfInteger"), // has its own function
1065
-            //"sides" => array("tag" => "keyword"), // has its own function
1066
-            "number-up" => array(
1067
-                "tag" => "integer"
1068
-            ) ,
1069
-            "orientation-requested" => array(
1070
-                "tag" => "enum"
1071
-            ) ,
1072
-            "media" => array(
1073
-                "tag" => "keyword"
1074
-            ) ,
1075
-            "printer-resolution" => array(
1076
-                "tag" => "resolution"
1077
-            ) ,
1078
-            "print-quality" => array(
1079
-                "tag" => "enum"
1080
-            ) ,
1081
-            "job-message-from-operator" => array(
1082
-                "tag" => "textWithoutLanguage"
1083
-            ) ,
1084
-        );
1085
-        $this->printer_tags = array(
1086
-            "requested-attributes" => array(
1087
-                "tag" => "keyword"
1088
-            )
1089
-        );
1090
-    }
1091
-
1092
-    //
1093
-    // SETUP
1094
-    //
1095
-    protected function _setOperationId()
1096
-    {
1097
-        $prepend = '';
1098
-        $this->operation_id+= 1;
1099
-        $this->meta->operation_id = self::_integerBuild($this->operation_id);
1100
-        self::_putDebug("operation id is: " . $this->operation_id, 2);
1101
-    }
1102
-
1103
-    protected function _setJobId()
1104
-    {
1105
-        $this->meta->jobid+= 1;
1106
-        $prepend = '';
1107
-        $prepend_length = 4 - strlen($this->meta->jobid);
1108
-        for ($i = 0; $i < $prepend_length; $i++) {
1109
-            $prepend.= '0';
1110
-        }
1111
-        return $prepend . $this->meta->jobid;
1112
-    }
1113
-
1114
-    protected function _setJobUri($job_uri)
1115
-    {
1116
-        $this->meta->job_uri = chr(0x45) // type uri
1117
-            . chr(0x00) . chr(0x07) // name-length
1118
-            . "job-uri"
1119
-            //. chr(0x00).chr(strlen($job_uri))
1120
-            . self::_giveMeStringLength($job_uri) . $job_uri;
1121
-        self::_putDebug("job-uri is: " . $job_uri, 2);
1122
-    }
1123
-
1124
-    //
1125
-    // RESPONSE PARSING
1126
-    //
1127
-    protected function _parseServerOutput()
1128
-    {
1129
-        $this->serveroutput->response = array();
1130
-        if (!self::_parseHttpHeaders()) {
1131
-            return FALSE;
1132
-        }
1133
-        $this->_parsing->offset = 0;
1134
-        self::_parseIppVersion();
1135
-        self::_parseStatusCode();
1136
-        self::_parseRequestID();
1137
-        $this->_parseResponse();
1138
-        //devel
1139
-        self::_putDebug(
1140
-            sprintf("***** IPP STATUS: %s ******", $this->serveroutput->status),
1141
-            4);
1142
-        self::_putDebug("****** END OF OPERATION ****");
1143
-        return true;
1144
-    }
1145
-
1146
-    protected function _parseHttpHeaders()
1147
-    {
1148
-        $response = "";
1149
-        switch ($this->serveroutput->headers[0])
1150
-        {
1151
-            case "http/1.1 200 ok: ":
1152
-                $this->serveroutput->httpstatus = "HTTP/1.1 200 OK";
1153
-                $response = "OK";
1154
-                break;
1155
-
1156
-            // primitive http/1.0 for Lexmark printers (from Rick Baril)
1157
-            case "http/1.0 200 ok: ":
1158
-                $this->serveroutput->httpstatus = "HTTP/1.0 200 OK";
1159
-                $response = "OK";
1160
-                break;
1161
-
1162
-            case "http/1.1 100 continue: ":
1163
-                $this->serveroutput->httpstatus = "HTTP/1.1 100 CONTINUE";
1164
-                $response = "OK";
1165
-                break;
1166
-
1167
-            case "":
1168
-                $this->serveroutput->httpstatus = "HTTP/1.1 000 No Response From Server";
1169
-                $this->serveroutput->status = "HTTP-ERROR-000_NO_RESPONSE_FROM_SERVER";
1170
-                trigger_error("No Response From Server", E_USER_WARNING);
1171
-                self::_errorLog("No Response From Server", 1);
1172
-                $this->disconnected = 1;
1173
-                return FALSE;
1174
-                break;
1175
-
1176
-            default:
1177
-                $server_response = preg_replace("/: $/", '', $this->serveroutput->headers[0]);
1178
-                #$strings = split(' ', $server_response, 3);
1179
-                $strings = preg_split('# #', $server_response, 3);
1180
-                $errno = $strings[1];
1181
-                $string = strtoupper(str_replace(' ', '_', $strings[2]));
1182
-                trigger_error(
1183
-                    sprintf(_("server responds %s") , $server_response),
1184
-                    E_USER_WARNING);
1185
-                self::_errorLog("server responds " . $server_response, 1);
1186
-                $this->serveroutput->httpstatus =
1187
-                    strtoupper($strings[0])
1188
-                        . " "
1189
-                        . $errno
1190
-                        . " "
1191
-                        . ucfirst($strings[2]);
1192
-
1193
-                $this->serveroutput->status =
1194
-                    "HTTP-ERROR-"
1195
-                        . $errno
1196
-                        . "-"
1197
-                        . $string;
1198
-                $this->disconnected = 1;
1199
-                return FALSE;
1200
-                break;
1201
-        }
1202
-        unset($this->serveroutput->headers);
1203
-        return TRUE;
1204
-    }
1205
-
1206
-    protected function _parseIppVersion()
1207
-    {
1208
-        $ippversion =
1209
-            (ord($this->serveroutput->body[$this->_parsing->offset]) * 256)
1210
-                + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1211
-        switch ($ippversion)
1212
-        {
1213
-            case 0x0101:
1214
-                $this->serveroutput->ipp_version = "1.1";
1215
-                break;
1216
-
1217
-            default:
1218
-                $this->serveroutput->ipp_version =
1219
-                    sprintf("%u.%u (Unknown)",
1220
-                        ord($this->serveroutput->body[$this->_parsing->offset]) * 256,
1221
-                        ord($this->serveroutput->body[$this->_parsing->offset + 1]));
1222
-                break;
1223
-        }
1224
-        self::_putDebug("I P P    R E S P O N S E :\n\n");
1225
-        self::_putDebug(
1226
-            sprintf("IPP version %s%s: %s",
1227
-                ord($this->serveroutput->body[$this->_parsing->offset]),
1228
-                ord($this->serveroutput->body[$this->_parsing->offset + 1]),
1229
-                $this->serveroutput->ipp_version));
1230
-        $this->_parsing->offset+= 2;
1231
-        return;
1232
-    }
1233
-
1234
-    protected function _parseStatusCode()
1235
-    {
1236
-        $status_code =
1237
-            (ord($this->serveroutput->body[$this->_parsing->offset]) * 256)
1238
-            + ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1239
-        $this->serveroutput->status = "NOT PARSED";
1240
-        $this->_parsing->offset+= 2;
1241
-        if (strlen($this->serveroutput->body) < $this->_parsing->offset)
1242
-        {
1243
-            return false;
1244
-        }
1245
-        if ($status_code < 0x00FF)
1246
-        {
1247
-            $this->serveroutput->status = "successfull";
1248
-        }
1249
-        elseif ($status_code < 0x01FF)
1250
-        {
1251
-            $this->serveroutput->status = "informational";
1252
-        }
1253
-        elseif ($status_code < 0x02FF)
1254
-        {
1255
-            $this->serveroutput->status = "redirection";
1256
-        }
1257
-        elseif ($status_code < 0x04FF)
1258
-        {
1259
-            $this->serveroutput->status = "client-error";
1260
-        }
1261
-        elseif ($status_code < 0x05FF)
1262
-        {
1263
-            $this->serveroutput->status = "server-error";
1264
-        }
1265
-        switch ($status_code)
1266
-        {
1267
-            case 0x0000:
1268
-                $this->serveroutput->status = "successfull-ok";
1269
-                break;
1270
-
1271
-            case 0x0001:
1272
-                $this->serveroutput->status = "successful-ok-ignored-or-substituted-attributes";
1273
-                break;
1274
-
1275
-            case 0x002:
1276
-                $this->serveroutput->status = "successful-ok-conflicting-attributes";
1277
-                break;
1278
-
1279
-            case 0x0400:
1280
-                $this->serveroutput->status = "client-error-bad-request";
1281
-                break;
1282
-
1283
-            case 0x0401:
1284
-                $this->serveroutput->status = "client-error-forbidden";
1285
-                break;
1286
-
1287
-            case 0x0402:
1288
-                $this->serveroutput->status = "client-error-not-authenticated";
1289
-                break;
1290
-
1291
-            case 0x0403:
1292
-                $this->serveroutput->status = "client-error-not-authorized";
1293
-                break;
1294
-
1295
-            case 0x0404:
1296
-                $this->serveroutput->status = "client-error-not-possible";
1297
-                break;
1298
-
1299
-            case 0x0405:
1300
-                $this->serveroutput->status = "client-error-timeout";
1301
-                break;
1302
-
1303
-            case 0x0406:
1304
-                $this->serveroutput->status = "client-error-not-found";
1305
-                break;
1306
-
1307
-            case 0x0407:
1308
-                $this->serveroutput->status = "client-error-gone";
1309
-                break;
1310
-
1311
-            case 0x0408:
1312
-                $this->serveroutput->status = "client-error-request-entity-too-large";
1313
-                break;
1314
-
1315
-            case 0x0409:
1316
-                $this->serveroutput->status = "client-error-request-value-too-long";
1317
-                break;
1318
-
1319
-            case 0x040A:
1320
-                $this->serveroutput->status = "client-error-document-format-not-supported";
1321
-                break;
1322
-
1323
-            case 0x040B:
1324
-                $this->serveroutput->status = "client-error-attributes-or-values-not-supported";
1325
-                break;
1326
-
1327
-            case 0x040C:
1328
-                $this->serveroutput->status = "client-error-uri-scheme-not-supported";
1329
-                break;
1330
-
1331
-            case 0x040D:
1332
-                $this->serveroutput->status = "client-error-charset-not-supported";
1333
-                break;
1334
-
1335
-            case 0x040E:
1336
-                $this->serveroutput->status = "client-error-conflicting-attributes";
1337
-                break;
1338
-
1339
-            case 0x040F:
1340
-                $this->serveroutput->status = "client-error-compression-not-supported";
1341
-                break;
1342
-
1343
-            case 0x0410:
1344
-                $this->serveroutput->status = "client-error-compression-error";
1345
-                break;
1346
-
1347
-            case 0x0411:
1348
-                $this->serveroutput->status = "client-error-document-format-error";
1349
-                break;
1350
-
1351
-            case 0x0412:
1352
-                $this->serveroutput->status = "client-error-document-access-error";
1353
-                break;
1354
-
1355
-            case 0x0413: // RFC3380
1356
-                $this->serveroutput->status = "client-error-attributes-not-settable";
1357
-                break;
1358
-
1359
-            case 0x0500:
1360
-                $this->serveroutput->status = "server-error-internal-error";
1361
-                break;
1362
-
1363
-            case 0x0501:
1364
-                $this->serveroutput->status = "server-error-operation-not-supported";
1365
-                break;
1366
-
1367
-            case 0x0502:
1368
-                $this->serveroutput->status = "server-error-service-unavailable";
1369
-                break;
1370
-
1371
-            case 0x0503:
1372
-                $this->serveroutput->status = "server-error-version-not-supported";
1373
-                break;
1374
-
1375
-            case 0x0504:
1376
-                $this->serveroutput->status = "server-error-device-error";
1377
-                break;
1378
-
1379
-            case 0x0505:
1380
-                $this->serveroutput->status = "server-error-temporary-error";
1381
-                break;
1382
-
1383
-            case 0x0506:
1384
-                $this->serveroutput->status = "server-error-not-accepting-jobs";
1385
-                break;
1386
-
1387
-            case 0x0507:
1388
-                $this->serveroutput->status = "server-error-busy";
1389
-                break;
1390
-
1391
-            case 0x0508:
1392
-                $this->serveroutput->status = "server-error-job-canceled";
1393
-                break;
1394
-
1395
-            case 0x0509:
1396
-                $this->serveroutput->status = "server-error-multiple-document-jobs-not-supported";
1397
-                break;
1398
-
1399
-            default:
1400
-                break;
1401
-        }
1402
-        self::_putDebug(
1403
-            sprintf(
1404
-                "status-code: %s%s: %s ",
1405
-                $this->serveroutput->body[$this->_parsing->offset],
1406
-                $this->serveroutput->body[$this->_parsing->offset + 1],
1407
-                $this->serveroutput->status),
1408
-            4);
1409
-        return;
1410
-    }
1411
-
1412
-    protected function _parseRequestID()
1413
-    {
1414
-        $this->serveroutput->request_id =
1415
-            self::_interpretInteger(
1416
-                substr($this->serveroutput->body, $this->_parsing->offset, 4)
1417
-            );
1418
-        self::_putDebug("request-id " . $this->serveroutput->request_id, 2);
1419
-        $this->_parsing->offset+= 4;
1420
-        return;
1421
-    }
1422
-
1423
-    protected function _interpretInteger($value)
1424
-    {
1425
-        // they are _signed_ integers
1426
-        $value_parsed = 0;
1427
-        for ($i = strlen($value); $i > 0; $i --)
1428
-        {
1429
-            $value_parsed +=
1430
-                (
1431
-                    (1 << (($i - 1) * 8))
1432
-                        *
1433
-                        ord($value[strlen($value) - $i])
1434
-                );
1435
-        }
1436
-        if ($value_parsed >= 2147483648)
1437
-        {
1438
-            $value_parsed -= 4294967296;
1439
-        }
1440
-        return $value_parsed;
1441
-    }
1442
-
1443
-    protected function _parseResponse()
1444
-    {
1445
-    }
1446
-
1447
-    //
1448
-    // REQUEST BUILDING
1449
-    //
1450
-    protected function _stringJob()
1451
-    {
1452
-        if (!isset($this->setup->charset)) {
1453
-            self::setCharset();
1454
-        }
1455
-        if (!isset($this->setup->datatype)) {
1456
-            self::setBinary();
1457
-        }
1458
-        if (!isset($this->setup->uri))
1459
-        {
1460
-            $this->getPrinters();
1461
-            unset($this->jobs[count($this->jobs) - 1]);
1462
-            unset($this->jobs_uri[count($this->jobs_uri) - 1]);
1463
-            unset($this->status[count($this->status) - 1]);
1464
-            if (array_key_exists(0, $this->available_printers))
1465
-            {
1466
-                self::setPrinterURI($this->available_printers[0]);
1467
-            }
1468
-            else
1469
-            {
1470
-                trigger_error(
1471
-                    _("_stringJob: Printer URI is not set: die"),
1472
-                    E_USER_WARNING);
1473
-                self::_putDebug(_("_stringJob: Printer URI is not set: die") , 4);
1474
-                self::_errorLog(" Printer URI is not set, die", 2);
1475
-                return FALSE;
1476
-            }
1477
-        }
1478
-        if (!isset($this->setup->copies)) {
1479
-            self::setCopies(1);
1480
-        }
1481
-        if (!isset($this->setup->language)) {
1482
-            self::setLanguage('en_us');
1483
-        }
1484
-        if (!isset($this->setup->mime_media_type)) {
1485
-            self::setMimeMediaType();
1486
-        }
1487
-        if (!isset($this->setup->jobname)) {
1488
-            self::setJobName();
1489
-        }
1490
-        unset($this->setup->jobname);
1491
-        if (!isset($this->meta->username)) {
1492
-            self::setUserName();
1493
-        }
1494
-        if (!isset($this->meta->fidelity)) {
1495
-            $this->meta->fidelity = '';
1496
-        }
1497
-        if (!isset($this->meta->document_name)) {
1498
-            $this->meta->document_name = '';
1499
-        }
1500
-        if (!isset($this->meta->sides)) {
1501
-            $this->meta->sides = '';
1502
-        }
1503
-        if (!isset($this->meta->page_ranges)) {
1504
-            $this->meta->page_ranges = '';
1505
-        }
1506
-        $jobattributes = '';
1507
-        $operationattributes = '';
1508
-        $printerattributes = '';
1509
-        $this->_buildValues($operationattributes, $jobattributes, $printerattributes);
1510
-        self::_setOperationId();
1511
-        if (!isset($this->error_generation->request_body_malformed))
1512
-        {
1513
-            $this->error_generation->request_body_malformed = "";
1514
-        }
1515
-        $this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
1516
-            . chr(0x00) . chr(0x02) // Print-Job | operation-id
1517
-            . $this->meta->operation_id //           request-id
1518
-            . chr(0x01) // start operation-attributes | operation-attributes-tag
1519
-            . $this->meta->charset
1520
-            . $this->meta->language
1521
-            . $this->meta->printer_uri
1522
-            . $this->meta->username
1523
-            . $this->meta->jobname
1524
-            . $this->meta->fidelity
1525
-            . $this->meta->document_name
1526
-            . $this->meta->mime_media_type
1527
-            . $operationattributes;
1528
-        if ($this->meta->copies || $this->meta->sides || $this->meta->page_ranges || !empty($jobattributes))
1529
-        {
1530
-            $this->stringjob .=
1531
-                chr(0x02) // start job-attributes | job-attributes-tag
1532
-                    . $this->meta->copies
1533
-                    . $this->meta->sides
1534
-                    . $this->meta->page_ranges
1535
-                    . $jobattributes;
1536
-        }
1537
-        $this->stringjob.= chr(0x03); // end-of-attributes | end-of-attributes-tag
1538
-        self::_putDebug(
1539
-            sprintf(_("String sent to the server is: %s"),
1540
-                $this->stringjob)
1541
-            );
1542
-        return TRUE;
1543
-    }
1544
-
1545
-    protected function _buildValues(&$operationattributes, &$jobattributes, &$printerattributes)
1546
-    {
1547
-        $operationattributes = '';
1548
-        foreach($this->operation_tags as $key => $values)
1549
-        {
1550
-            $item = 0;
1551
-            if (array_key_exists('value', $values))
1552
-            {
1553
-                foreach($values['value'] as $item_value)
1554
-                {
1555
-                    if ($item == 0)
1556
-                    {
1557
-                        $operationattributes .=
1558
-                            $values['systag']
1559
-                                . self::_giveMeStringLength($key)
1560
-                                . $key
1561
-                                . self::_giveMeStringLength($item_value)
1562
-                                . $item_value;
1563
-                    }
1564
-                    else
1565
-                    {
1566
-                        $operationattributes .=
1567
-                            $values['systag']
1568
-                                . self::_giveMeStringLength('')
1569
-                                . self::_giveMeStringLength($item_value)
1570
-                                . $item_value;
1571
-                    }
1572
-                    $item++;
1573
-                }
1574
-            }
1575
-        }
1576
-        $jobattributes = '';
1577
-        foreach($this->job_tags as $key => $values)
1578
-        {
1579
-            $item = 0;
1580
-            if (array_key_exists('value', $values))
1581
-            {
1582
-                foreach($values['value'] as $item_value)
1583
-                {
1584
-                    if ($item == 0)
1585
-                    {
1586
-                        $jobattributes .=
1587
-                            $values['systag']
1588
-                                . self::_giveMeStringLength($key)
1589
-                                . $key
1590
-                                . self::_giveMeStringLength($item_value)
1591
-                                . $item_value;
1592
-                    }
1593
-                    else
1594
-                    {
1595
-                        $jobattributes .=
1596
-                            $values['systag']
1597
-                                . self::_giveMeStringLength('')
1598
-                                . self::_giveMeStringLength($item_value)
1599
-                                . $item_value;
1600
-                    }
1601
-                    $item++;
1602
-                }
1603
-            }
1604
-        }
1605
-        $printerattributes = '';
1606
-        foreach($this->printer_tags as $key => $values)
1607
-        {
1608
-            $item = 0;
1609
-            if (array_key_exists('value', $values))
1610
-            {
1611
-                foreach($values['value'] as $item_value)
1612
-                {
1613
-                    if ($item == 0)
1614
-                    {
1615
-                        $printerattributes .=
1616
-                            $values['systag']
1617
-                                . self::_giveMeStringLength($key)
1618
-                                . $key
1619
-                                . self::_giveMeStringLength($item_value)
1620
-                                . $item_value;
1621
-                    }
1622
-                    else
1623
-                    {
1624
-                        $printerattributes .=
1625
-                            $values['systag']
1626
-                                . self::_giveMeStringLength('')
1627
-                                . self::_giveMeStringLength($item_value)
1628
-                                . $item_value;
1629
-                    }
1630
-                    $item++;
1631
-                }
1632
-            }
1633
-        }
1634
-        reset($this->job_tags);
1635
-        reset($this->operation_tags);
1636
-        reset($this->printer_tags);
1637
-        return true;
1638
-    }
1639
-
1640
-    protected function _giveMeStringLength($string)
1641
-    {
1642
-        $length = strlen($string);
1643
-        if ($length > ((0xFF << 8) + 0xFF)  )
1644
-        {
1645
-            $errmsg = sprintf (
1646
-                _('max string length for an ipp meta-information = %d, while here %d'),
1647
-                ((0xFF << 8) + 0xFF), $length);
1648
-
1649
-            if ($this->with_exceptions)
1650
-            {
1651
-                throw new ippException($errmsg);
1652
-            }
1653
-            else
1654
-            {
1655
-                trigger_error ($errmsg, E_USER_ERROR);
1656
-            }
1657
-        }
1658
-        $int1 = $length & 0xFF;
1659
-        $length -= $int1;
1660
-        $length = $length >> 8;
1661
-        $int2 = $length & 0xFF;
1662
-        return chr($int2) . chr($int1);
1663
-    }
1664
-
1665
-    protected function _enumBuild($tag, $value)
1666
-    {
1667
-        switch ($tag)
1668
-        {
1669
-            case "orientation-requested":
1670
-                switch ($value)
1671
-                {
1672
-                    case 'portrait':
1673
-                        $value = chr(3);
1674
-                        break;
1675
-
1676
-                    case 'landscape':
1677
-                        $value = chr(4);
1678
-                        break;
1679
-
1680
-                    case 'reverse-landscape':
1681
-                        $value = chr(5);
1682
-                        break;
1683
-
1684
-                    case 'reverse-portrait':
1685
-                        $value = chr(6);
1686
-                        break;
1687
-                }
1688
-                break;
1689
-
1690
-            case "print-quality":
1691
-                switch ($value)
1692
-                {
1693
-                    case 'draft':
1694
-                        $value = chr(3);
1695
-                        break;
1696
-
1697
-                    case 'normal':
1698
-                        $value = chr(4);
1699
-                        break;
1700
-
1701
-                    case 'high':
1702
-                        $value = chr(5);
1703
-                        break;
1704
-                }
1705
-                break;
1706
-
1707
-            case "finishing":
1708
-                switch ($value)
1709
-                {
1710
-                    case 'none':
1711
-                        $value = chr(3);
1712
-                        break;
1713
-
1714
-                    case 'staple':
1715
-                        $value = chr(4);
1716
-                        break;
1717
-
1718
-                    case 'punch':
1719
-                        $value = chr(5);
1720
-                        break;
1721
-
1722
-                    case 'cover':
1723
-                        $value = chr(6);
1724
-                        break;
1725
-
1726
-                    case 'bind':
1727
-                        $value = chr(7);
1728
-                        break;
1729
-
1730
-                    case 'saddle-stitch':
1731
-                        $value = chr(8);
1732
-                        break;
1733
-
1734
-                    case 'edge-stitch':
1735
-                        $value = chr(9);
1736
-                        break;
1737
-
1738
-                    case 'staple-top-left':
1739
-                        $value = chr(20);
1740
-                        break;
1741
-
1742
-                    case 'staple-bottom-left':
1743
-                        $value = chr(21);
1744
-                        break;
1745
-
1746
-                    case 'staple-top-right':
1747
-                        $value = chr(22);
1748
-                        break;
1749
-
1750
-                    case 'staple-bottom-right':
1751
-                        $value = chr(23);
1752
-                        break;
1753
-
1754
-                    case 'edge-stitch-left':
1755
-                        $value = chr(24);
1756
-                        break;
1757
-
1758
-                    case 'edge-stitch-top':
1759
-                        $value = chr(25);
1760
-                        break;
1761
-
1762
-                    case 'edge-stitch-right':
1763
-                        $value = chr(26);
1764
-                        break;
1765
-
1766
-                    case 'edge-stitch-bottom':
1767
-                        $value = chr(27);
1768
-                        break;
1769
-
1770
-                    case 'staple-dual-left':
1771
-                        $value = chr(28);
1772
-                        break;
1773
-
1774
-                    case 'staple-dual-top':
1775
-                        $value = chr(29);
1776
-                        break;
1777
-
1778
-                    case 'staple-dual-right':
1779
-                        $value = chr(30);
1780
-                        break;
1781
-
1782
-                    case 'staple-dual-bottom':
1783
-                        $value = chr(31);
1784
-                        break;
1785
-                }
1786
-                break;
1787
-        }
1788
-        $prepend = '';
1789
-        while ((strlen($value) + strlen($prepend)) < 4)
1790
-        {
1791
-            $prepend .= chr(0);
1792
-        }
1793
-        return $prepend . $value;
1794
-    }
1795
-
1796
-    protected function _integerBuild($value)
1797
-    {
1798
-        if ($value >= 2147483647 || $value < - 2147483648)
1799
-        {
1800
-            trigger_error(
1801
-                _("Values must be between -2147483648 and 2147483647: assuming '0'") , E_USER_WARNING);
1802
-            return chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00);
1803
-        }
1804
-        $initial_value = $value;
1805
-        $int1 = $value & 0xFF;
1806
-        $value -= $int1;
1807
-        $value = $value >> 8;
1808
-        $int2 = $value & 0xFF;
1809
-        $value-= $int2;
1810
-        $value = $value >> 8;
1811
-        $int3 = $value & 0xFF;
1812
-        $value-= $int3;
1813
-        $value = $value >> 8;
1814
-        $int4 = $value & 0xFF; //64bits
1815
-        if ($initial_value < 0) {
1816
-            $int4 = chr($int4) | chr(0x80);
1817
-        }
1818
-        else {
1819
-            $int4 = chr($int4);
1820
-        }
1821
-        $value = $int4 . chr($int3) . chr($int2) . chr($int1);
1822
-        return $value;
1823
-    }
1824
-
1825
-    protected function _rangeOfIntegerBuild($integers)
1826
-    {
1827
-        #$integers = split(":", $integers);
1828
-        $integers = preg_split("#:#", $integers);
1829
-        for ($i = 0; $i < 2; $i++) {
1830
-            $outvalue[$i] = self::_integerBuild($integers[$i]);
1831
-        }
1832
-        return $outvalue[0] . $outvalue[1];
1833
-    }
1834
-
1835
-    protected function _setJobAttribute($attribute, $value)
1836
-    {
1837
-        //used by setAttribute
1838
-        $tag_type = $this->job_tags[$attribute]['tag'];
1839
-        switch ($tag_type)
1840
-        {
1841
-            case 'integer':
1842
-                $this->job_tags[$attribute]['value'][] = self::_integerBuild($value);
1843
-                break;
1844
-
1845
-            case 'boolean':
1846
-            case 'nameWithoutLanguage':
1847
-            case 'nameWithLanguage':
1848
-            case 'textWithoutLanguage':
1849
-            case 'textWithLanguage':
1850
-            case 'keyword':
1851
-            case 'naturalLanguage':
1852
-                $this->job_tags[$attribute]['value'][] = $value;
1853
-                break;
1854
-
1855
-            case 'enum':
1856
-                $value = $this->_enumBuild($attribute, $value); // may be overwritten by children
1857
-                $this->job_tags[$attribute]['value'][] = $value;
1858
-                break;
1859
-
1860
-            case 'rangeOfInteger':
1861
-                // $value have to be: INT1:INT2 , eg 100:1000
1862
-                $this->job_tags[$attribute]['value'][] = self::_rangeOfIntegerBuild($value);
1863
-                break;
1864
-
1865
-            case 'resolution':
1866
-                if (preg_match("#dpi#", $value)) {
1867
-                    $unit = chr(0x3);
1868
-                }
1869
-                if (preg_match("#dpc#", $value)) {
1870
-                    $unit = chr(0x4);
1871
-                }
1872
-                $search = array(
1873
-                    "#(dpi|dpc)#",
1874
-                    '#(x|-)#'
1875
-                );
1876
-                $replace = array(
1877
-                    "",
1878
-                    ":"
1879
-                );
1880
-                $value = self::_rangeOfIntegerBuild(preg_replace($search, $replace, $value)) . $unit;
1881
-                $this->job_tags[$attribute]['value'][] = $value;
1882
-                break;
1883
-
1884
-            default:
1885
-                trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1886
-                self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1887
-                self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1888
-                return FALSE;
1889
-                break;
1890
-        }
1891
-        $this->job_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1892
-    }
1893
-
1894
-    protected function _setOperationAttribute($attribute, $value)
1895
-    {
1896
-        //used by setAttribute
1897
-        $tag_type = $this->operation_tags[$attribute]['tag'];
1898
-        switch ($tag_type)
1899
-        {
1900
-            case 'integer':
1901
-                $this->operation_tags[$attribute]['value'][] = self::_integerBuild($value);
1902
-                break;
1903
-
1904
-            case 'keyword':
1905
-            case 'naturalLanguage':
1906
-                $this->operation_tags[$attribute]['value'][] = $value;
1907
-                break;
1908
-
1909
-            default:
1910
-                trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1911
-                self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1912
-                self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1913
-                return FALSE;
1914
-                break;
1915
-        }
1916
-        $this->operation_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1917
-    }
1918
-
1919
-    protected function _setPrinterAttribute($attribute, $value)
1920
-    {
1921
-        //used by setAttribute
1922
-        $tag_type = $this->printer_tags[$attribute]['tag'];
1923
-        switch ($tag_type)
1924
-        {
1925
-            case 'integer':
1926
-                $this->printer_tags[$attribute]['value'][] = self::_integerBuild($value);
1927
-                break;
1928
-
1929
-            case 'keyword':
1930
-            case 'naturalLanguage':
1931
-                $this->printer_tags[$attribute]['value'][] = $value;
1932
-                break;
1933
-
1934
-            default:
1935
-                trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1936
-                self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1937
-                self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1938
-                return FALSE;
1939
-                break;
1940
-        }
1941
-        $this->printer_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1942
-    }
1943
-
1944
-    //
1945
-    // DEBUGGING
1946
-    //
1947
-    protected function _putDebug($string, $level = 1)
1948
-    {
1949
-        if ($level === false) {
1950
-            return;
1951
-        }
1952
-
1953
-        if ($level < $this->debug_level) {
1954
-            return;
1955
-        }
1956
-
1957
-        $this->debug[$this->debug_count] = substr($string, 0, 1024);
1958
-        $this->debug_count++;
1959
-        //$this->debug .= substr($string,0,1024);
1960
-
1961
-    }
1962
-
1963
-    //
1964
-    // LOGGING
1965
-    //
1966
-    protected function _errorLog($string_to_log, $level)
1967
-    {
1968
-        if ($level > $this->log_level) {
1969
-            return;
1970
-        }
1971
-
1972
-        $string = sprintf('%s : %s:%s user %s : %s', basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log);
1973
-
1974
-        if ($this->log_type == 0)
1975
-        {
1976
-            error_log($string);
1977
-            return;
1978
-        }
1979
-
1980
-        $string = sprintf("%s %s Host %s:%s user %s : %s\n", date('M d H:i:s') , basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log);
1981
-        error_log($string, $this->log_type, $this->log_destination);
1982
-        return;
1983
-    }
993
+			"textWithoutLanguage" => array(
994
+				"tag" => chr(0x41) ,
995
+				"build" => "string"
996
+			) ,
997
+			"nameWithoutLanguage" => array(
998
+				"tag" => chr(0x42) ,
999
+				"buid" => "string"
1000
+			) ,
1001
+			"keyword" => array(
1002
+				"tag" => chr(0x44) ,
1003
+				"build" => "string"
1004
+			) ,
1005
+			"uri" => array(
1006
+				"tag" => chr(0x45) ,
1007
+				"build" => "string"
1008
+			) ,
1009
+			"uriScheme" => array(
1010
+				"tag" => chr(0x46) ,
1011
+				"build" => "string"
1012
+			) ,
1013
+			"charset" => array(
1014
+				"tag" => chr(0x47) ,
1015
+				"build" => "string"
1016
+			) ,
1017
+			"naturalLanguage" => array(
1018
+				"tag" => chr(0x48) ,
1019
+				"build" => "string"
1020
+			) ,
1021
+			"mimeMediaType" => array(
1022
+				"tag" => chr(0x49) ,
1023
+				"build" => "string"
1024
+			) ,
1025
+			"extendedAttributes" => array(
1026
+				"tag" => chr(0x7F) ,
1027
+				"build" => "extended"
1028
+			) ,
1029
+		);
1030
+		$this->operation_tags = array(
1031
+			"compression" => array(
1032
+				"tag" => "keyword"
1033
+			) ,
1034
+			"document-natural-language" => array(
1035
+				"tag" => "naturalLanguage"
1036
+			) ,
1037
+			"job-k-octets" => array(
1038
+				"tag" => "integer"
1039
+			) ,
1040
+			"job-impressions" => array(
1041
+				"tag" => "integer"
1042
+			) ,
1043
+			"job-media-sheets" => array(
1044
+				"tag" => "integer"
1045
+			) ,
1046
+		);
1047
+		$this->job_tags = array(
1048
+			"job-priority" => array(
1049
+				"tag" => "integer"
1050
+			) ,
1051
+			"job-hold-until" => array(
1052
+				"tag" => "keyword"
1053
+			) ,
1054
+			"job-sheets" => array(
1055
+				"tag" => "keyword"
1056
+			) , //banner page
1057
+			"multiple-document-handling" => array(
1058
+				"tag" => "keyword"
1059
+			) ,
1060
+			//"copies" => array("tag" => "integer"),
1061
+			"finishings" => array(
1062
+				"tag" => "enum"
1063
+			) ,
1064
+			//"page-ranges" => array("tag" => "rangeOfInteger"), // has its own function
1065
+			//"sides" => array("tag" => "keyword"), // has its own function
1066
+			"number-up" => array(
1067
+				"tag" => "integer"
1068
+			) ,
1069
+			"orientation-requested" => array(
1070
+				"tag" => "enum"
1071
+			) ,
1072
+			"media" => array(
1073
+				"tag" => "keyword"
1074
+			) ,
1075
+			"printer-resolution" => array(
1076
+				"tag" => "resolution"
1077
+			) ,
1078
+			"print-quality" => array(
1079
+				"tag" => "enum"
1080
+			) ,
1081
+			"job-message-from-operator" => array(
1082
+				"tag" => "textWithoutLanguage"
1083
+			) ,
1084
+		);
1085
+		$this->printer_tags = array(
1086
+			"requested-attributes" => array(
1087
+				"tag" => "keyword"
1088
+			)
1089
+		);
1090
+	}
1091
+
1092
+	//
1093
+	// SETUP
1094
+	//
1095
+	protected function _setOperationId()
1096
+	{
1097
+		$prepend = '';
1098
+		$this->operation_id+= 1;
1099
+		$this->meta->operation_id = self::_integerBuild($this->operation_id);
1100
+		self::_putDebug("operation id is: " . $this->operation_id, 2);
1101
+	}
1102
+
1103
+	protected function _setJobId()
1104
+	{
1105
+		$this->meta->jobid+= 1;
1106
+		$prepend = '';
1107
+		$prepend_length = 4 - strlen($this->meta->jobid);
1108
+		for ($i = 0; $i < $prepend_length; $i++) {
1109
+			$prepend.= '0';
1110
+		}
1111
+		return $prepend . $this->meta->jobid;
1112
+	}
1113
+
1114
+	protected function _setJobUri($job_uri)
1115
+	{
1116
+		$this->meta->job_uri = chr(0x45) // type uri
1117
+			. chr(0x00) . chr(0x07) // name-length
1118
+			. "job-uri"
1119
+			//. chr(0x00).chr(strlen($job_uri))
1120
+			. self::_giveMeStringLength($job_uri) . $job_uri;
1121
+		self::_putDebug("job-uri is: " . $job_uri, 2);
1122
+	}
1123
+
1124
+	//
1125
+	// RESPONSE PARSING
1126
+	//
1127
+	protected function _parseServerOutput()
1128
+	{
1129
+		$this->serveroutput->response = array();
1130
+		if (!self::_parseHttpHeaders()) {
1131
+			return FALSE;
1132
+		}
1133
+		$this->_parsing->offset = 0;
1134
+		self::_parseIppVersion();
1135
+		self::_parseStatusCode();
1136
+		self::_parseRequestID();
1137
+		$this->_parseResponse();
1138
+		//devel
1139
+		self::_putDebug(
1140
+			sprintf("***** IPP STATUS: %s ******", $this->serveroutput->status),
1141
+			4);
1142
+		self::_putDebug("****** END OF OPERATION ****");
1143
+		return true;
1144
+	}
1145
+
1146
+	protected function _parseHttpHeaders()
1147
+	{
1148
+		$response = "";
1149
+		switch ($this->serveroutput->headers[0])
1150
+		{
1151
+			case "http/1.1 200 ok: ":
1152
+				$this->serveroutput->httpstatus = "HTTP/1.1 200 OK";
1153
+				$response = "OK";
1154
+				break;
1155
+
1156
+			// primitive http/1.0 for Lexmark printers (from Rick Baril)
1157
+			case "http/1.0 200 ok: ":
1158
+				$this->serveroutput->httpstatus = "HTTP/1.0 200 OK";
1159
+				$response = "OK";
1160
+				break;
1161
+
1162
+			case "http/1.1 100 continue: ":
1163
+				$this->serveroutput->httpstatus = "HTTP/1.1 100 CONTINUE";
1164
+				$response = "OK";
1165
+				break;
1166
+
1167
+			case "":
1168
+				$this->serveroutput->httpstatus = "HTTP/1.1 000 No Response From Server";
1169
+				$this->serveroutput->status = "HTTP-ERROR-000_NO_RESPONSE_FROM_SERVER";
1170
+				trigger_error("No Response From Server", E_USER_WARNING);
1171
+				self::_errorLog("No Response From Server", 1);
1172
+				$this->disconnected = 1;
1173
+				return FALSE;
1174
+				break;
1175
+
1176
+			default:
1177
+				$server_response = preg_replace("/: $/", '', $this->serveroutput->headers[0]);
1178
+				#$strings = split(' ', $server_response, 3);
1179
+				$strings = preg_split('# #', $server_response, 3);
1180
+				$errno = $strings[1];
1181
+				$string = strtoupper(str_replace(' ', '_', $strings[2]));
1182
+				trigger_error(
1183
+					sprintf(_("server responds %s") , $server_response),
1184
+					E_USER_WARNING);
1185
+				self::_errorLog("server responds " . $server_response, 1);
1186
+				$this->serveroutput->httpstatus =
1187
+					strtoupper($strings[0])
1188
+						. " "
1189
+						. $errno
1190
+						. " "
1191
+						. ucfirst($strings[2]);
1192
+
1193
+				$this->serveroutput->status =
1194
+					"HTTP-ERROR-"
1195
+						. $errno
1196
+						. "-"
1197
+						. $string;
1198
+				$this->disconnected = 1;
1199
+				return FALSE;
1200
+				break;
1201
+		}
1202
+		unset($this->serveroutput->headers);
1203
+		return TRUE;
1204
+	}
1205
+
1206
+	protected function _parseIppVersion()
1207
+	{
1208
+		$ippversion =
1209
+			(ord($this->serveroutput->body[$this->_parsing->offset]) * 256)
1210
+				+ ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1211
+		switch ($ippversion)
1212
+		{
1213
+			case 0x0101:
1214
+				$this->serveroutput->ipp_version = "1.1";
1215
+				break;
1216
+
1217
+			default:
1218
+				$this->serveroutput->ipp_version =
1219
+					sprintf("%u.%u (Unknown)",
1220
+						ord($this->serveroutput->body[$this->_parsing->offset]) * 256,
1221
+						ord($this->serveroutput->body[$this->_parsing->offset + 1]));
1222
+				break;
1223
+		}
1224
+		self::_putDebug("I P P    R E S P O N S E :\n\n");
1225
+		self::_putDebug(
1226
+			sprintf("IPP version %s%s: %s",
1227
+				ord($this->serveroutput->body[$this->_parsing->offset]),
1228
+				ord($this->serveroutput->body[$this->_parsing->offset + 1]),
1229
+				$this->serveroutput->ipp_version));
1230
+		$this->_parsing->offset+= 2;
1231
+		return;
1232
+	}
1233
+
1234
+	protected function _parseStatusCode()
1235
+	{
1236
+		$status_code =
1237
+			(ord($this->serveroutput->body[$this->_parsing->offset]) * 256)
1238
+			+ ord($this->serveroutput->body[$this->_parsing->offset + 1]);
1239
+		$this->serveroutput->status = "NOT PARSED";
1240
+		$this->_parsing->offset+= 2;
1241
+		if (strlen($this->serveroutput->body) < $this->_parsing->offset)
1242
+		{
1243
+			return false;
1244
+		}
1245
+		if ($status_code < 0x00FF)
1246
+		{
1247
+			$this->serveroutput->status = "successfull";
1248
+		}
1249
+		elseif ($status_code < 0x01FF)
1250
+		{
1251
+			$this->serveroutput->status = "informational";
1252
+		}
1253
+		elseif ($status_code < 0x02FF)
1254
+		{
1255
+			$this->serveroutput->status = "redirection";
1256
+		}
1257
+		elseif ($status_code < 0x04FF)
1258
+		{
1259
+			$this->serveroutput->status = "client-error";
1260
+		}
1261
+		elseif ($status_code < 0x05FF)
1262
+		{
1263
+			$this->serveroutput->status = "server-error";
1264
+		}
1265
+		switch ($status_code)
1266
+		{
1267
+			case 0x0000:
1268
+				$this->serveroutput->status = "successfull-ok";
1269
+				break;
1270
+
1271
+			case 0x0001:
1272
+				$this->serveroutput->status = "successful-ok-ignored-or-substituted-attributes";
1273
+				break;
1274
+
1275
+			case 0x002:
1276
+				$this->serveroutput->status = "successful-ok-conflicting-attributes";
1277
+				break;
1278
+
1279
+			case 0x0400:
1280
+				$this->serveroutput->status = "client-error-bad-request";
1281
+				break;
1282
+
1283
+			case 0x0401:
1284
+				$this->serveroutput->status = "client-error-forbidden";
1285
+				break;
1286
+
1287
+			case 0x0402:
1288
+				$this->serveroutput->status = "client-error-not-authenticated";
1289
+				break;
1290
+
1291
+			case 0x0403:
1292
+				$this->serveroutput->status = "client-error-not-authorized";
1293
+				break;
1294
+
1295
+			case 0x0404:
1296
+				$this->serveroutput->status = "client-error-not-possible";
1297
+				break;
1298
+
1299
+			case 0x0405:
1300
+				$this->serveroutput->status = "client-error-timeout";
1301
+				break;
1302
+
1303
+			case 0x0406:
1304
+				$this->serveroutput->status = "client-error-not-found";
1305
+				break;
1306
+
1307
+			case 0x0407:
1308
+				$this->serveroutput->status = "client-error-gone";
1309
+				break;
1310
+
1311
+			case 0x0408:
1312
+				$this->serveroutput->status = "client-error-request-entity-too-large";
1313
+				break;
1314
+
1315
+			case 0x0409:
1316
+				$this->serveroutput->status = "client-error-request-value-too-long";
1317
+				break;
1318
+
1319
+			case 0x040A:
1320
+				$this->serveroutput->status = "client-error-document-format-not-supported";
1321
+				break;
1322
+
1323
+			case 0x040B:
1324
+				$this->serveroutput->status = "client-error-attributes-or-values-not-supported";
1325
+				break;
1326
+
1327
+			case 0x040C:
1328
+				$this->serveroutput->status = "client-error-uri-scheme-not-supported";
1329
+				break;
1330
+
1331
+			case 0x040D:
1332
+				$this->serveroutput->status = "client-error-charset-not-supported";
1333
+				break;
1334
+
1335
+			case 0x040E:
1336
+				$this->serveroutput->status = "client-error-conflicting-attributes";
1337
+				break;
1338
+
1339
+			case 0x040F:
1340
+				$this->serveroutput->status = "client-error-compression-not-supported";
1341
+				break;
1342
+
1343
+			case 0x0410:
1344
+				$this->serveroutput->status = "client-error-compression-error";
1345
+				break;
1346
+
1347
+			case 0x0411:
1348
+				$this->serveroutput->status = "client-error-document-format-error";
1349
+				break;
1350
+
1351
+			case 0x0412:
1352
+				$this->serveroutput->status = "client-error-document-access-error";
1353
+				break;
1354
+
1355
+			case 0x0413: // RFC3380
1356
+				$this->serveroutput->status = "client-error-attributes-not-settable";
1357
+				break;
1358
+
1359
+			case 0x0500:
1360
+				$this->serveroutput->status = "server-error-internal-error";
1361
+				break;
1362
+
1363
+			case 0x0501:
1364
+				$this->serveroutput->status = "server-error-operation-not-supported";
1365
+				break;
1366
+
1367
+			case 0x0502:
1368
+				$this->serveroutput->status = "server-error-service-unavailable";
1369
+				break;
1370
+
1371
+			case 0x0503:
1372
+				$this->serveroutput->status = "server-error-version-not-supported";
1373
+				break;
1374
+
1375
+			case 0x0504:
1376
+				$this->serveroutput->status = "server-error-device-error";
1377
+				break;
1378
+
1379
+			case 0x0505:
1380
+				$this->serveroutput->status = "server-error-temporary-error";
1381
+				break;
1382
+
1383
+			case 0x0506:
1384
+				$this->serveroutput->status = "server-error-not-accepting-jobs";
1385
+				break;
1386
+
1387
+			case 0x0507:
1388
+				$this->serveroutput->status = "server-error-busy";
1389
+				break;
1390
+
1391
+			case 0x0508:
1392
+				$this->serveroutput->status = "server-error-job-canceled";
1393
+				break;
1394
+
1395
+			case 0x0509:
1396
+				$this->serveroutput->status = "server-error-multiple-document-jobs-not-supported";
1397
+				break;
1398
+
1399
+			default:
1400
+				break;
1401
+		}
1402
+		self::_putDebug(
1403
+			sprintf(
1404
+				"status-code: %s%s: %s ",
1405
+				$this->serveroutput->body[$this->_parsing->offset],
1406
+				$this->serveroutput->body[$this->_parsing->offset + 1],
1407
+				$this->serveroutput->status),
1408
+			4);
1409
+		return;
1410
+	}
1411
+
1412
+	protected function _parseRequestID()
1413
+	{
1414
+		$this->serveroutput->request_id =
1415
+			self::_interpretInteger(
1416
+				substr($this->serveroutput->body, $this->_parsing->offset, 4)
1417
+			);
1418
+		self::_putDebug("request-id " . $this->serveroutput->request_id, 2);
1419
+		$this->_parsing->offset+= 4;
1420
+		return;
1421
+	}
1422
+
1423
+	protected function _interpretInteger($value)
1424
+	{
1425
+		// they are _signed_ integers
1426
+		$value_parsed = 0;
1427
+		for ($i = strlen($value); $i > 0; $i --)
1428
+		{
1429
+			$value_parsed +=
1430
+				(
1431
+					(1 << (($i - 1) * 8))
1432
+						*
1433
+						ord($value[strlen($value) - $i])
1434
+				);
1435
+		}
1436
+		if ($value_parsed >= 2147483648)
1437
+		{
1438
+			$value_parsed -= 4294967296;
1439
+		}
1440
+		return $value_parsed;
1441
+	}
1442
+
1443
+	protected function _parseResponse()
1444
+	{
1445
+	}
1446
+
1447
+	//
1448
+	// REQUEST BUILDING
1449
+	//
1450
+	protected function _stringJob()
1451
+	{
1452
+		if (!isset($this->setup->charset)) {
1453
+			self::setCharset();
1454
+		}
1455
+		if (!isset($this->setup->datatype)) {
1456
+			self::setBinary();
1457
+		}
1458
+		if (!isset($this->setup->uri))
1459
+		{
1460
+			$this->getPrinters();
1461
+			unset($this->jobs[count($this->jobs) - 1]);
1462
+			unset($this->jobs_uri[count($this->jobs_uri) - 1]);
1463
+			unset($this->status[count($this->status) - 1]);
1464
+			if (array_key_exists(0, $this->available_printers))
1465
+			{
1466
+				self::setPrinterURI($this->available_printers[0]);
1467
+			}
1468
+			else
1469
+			{
1470
+				trigger_error(
1471
+					_("_stringJob: Printer URI is not set: die"),
1472
+					E_USER_WARNING);
1473
+				self::_putDebug(_("_stringJob: Printer URI is not set: die") , 4);
1474
+				self::_errorLog(" Printer URI is not set, die", 2);
1475
+				return FALSE;
1476
+			}
1477
+		}
1478
+		if (!isset($this->setup->copies)) {
1479
+			self::setCopies(1);
1480
+		}
1481
+		if (!isset($this->setup->language)) {
1482
+			self::setLanguage('en_us');
1483
+		}
1484
+		if (!isset($this->setup->mime_media_type)) {
1485
+			self::setMimeMediaType();
1486
+		}
1487
+		if (!isset($this->setup->jobname)) {
1488
+			self::setJobName();
1489
+		}
1490
+		unset($this->setup->jobname);
1491
+		if (!isset($this->meta->username)) {
1492
+			self::setUserName();
1493
+		}
1494
+		if (!isset($this->meta->fidelity)) {
1495
+			$this->meta->fidelity = '';
1496
+		}
1497
+		if (!isset($this->meta->document_name)) {
1498
+			$this->meta->document_name = '';
1499
+		}
1500
+		if (!isset($this->meta->sides)) {
1501
+			$this->meta->sides = '';
1502
+		}
1503
+		if (!isset($this->meta->page_ranges)) {
1504
+			$this->meta->page_ranges = '';
1505
+		}
1506
+		$jobattributes = '';
1507
+		$operationattributes = '';
1508
+		$printerattributes = '';
1509
+		$this->_buildValues($operationattributes, $jobattributes, $printerattributes);
1510
+		self::_setOperationId();
1511
+		if (!isset($this->error_generation->request_body_malformed))
1512
+		{
1513
+			$this->error_generation->request_body_malformed = "";
1514
+		}
1515
+		$this->stringjob = chr(0x01) . chr(0x01) // 1.1  | version-number
1516
+			. chr(0x00) . chr(0x02) // Print-Job | operation-id
1517
+			. $this->meta->operation_id //           request-id
1518
+			. chr(0x01) // start operation-attributes | operation-attributes-tag
1519
+			. $this->meta->charset
1520
+			. $this->meta->language
1521
+			. $this->meta->printer_uri
1522
+			. $this->meta->username
1523
+			. $this->meta->jobname
1524
+			. $this->meta->fidelity
1525
+			. $this->meta->document_name
1526
+			. $this->meta->mime_media_type
1527
+			. $operationattributes;
1528
+		if ($this->meta->copies || $this->meta->sides || $this->meta->page_ranges || !empty($jobattributes))
1529
+		{
1530
+			$this->stringjob .=
1531
+				chr(0x02) // start job-attributes | job-attributes-tag
1532
+					. $this->meta->copies
1533
+					. $this->meta->sides
1534
+					. $this->meta->page_ranges
1535
+					. $jobattributes;
1536
+		}
1537
+		$this->stringjob.= chr(0x03); // end-of-attributes | end-of-attributes-tag
1538
+		self::_putDebug(
1539
+			sprintf(_("String sent to the server is: %s"),
1540
+				$this->stringjob)
1541
+			);
1542
+		return TRUE;
1543
+	}
1544
+
1545
+	protected function _buildValues(&$operationattributes, &$jobattributes, &$printerattributes)
1546
+	{
1547
+		$operationattributes = '';
1548
+		foreach($this->operation_tags as $key => $values)
1549
+		{
1550
+			$item = 0;
1551
+			if (array_key_exists('value', $values))
1552
+			{
1553
+				foreach($values['value'] as $item_value)
1554
+				{
1555
+					if ($item == 0)
1556
+					{
1557
+						$operationattributes .=
1558
+							$values['systag']
1559
+								. self::_giveMeStringLength($key)
1560
+								. $key
1561
+								. self::_giveMeStringLength($item_value)
1562
+								. $item_value;
1563
+					}
1564
+					else
1565
+					{
1566
+						$operationattributes .=
1567
+							$values['systag']
1568
+								. self::_giveMeStringLength('')
1569
+								. self::_giveMeStringLength($item_value)
1570
+								. $item_value;
1571
+					}
1572
+					$item++;
1573
+				}
1574
+			}
1575
+		}
1576
+		$jobattributes = '';
1577
+		foreach($this->job_tags as $key => $values)
1578
+		{
1579
+			$item = 0;
1580
+			if (array_key_exists('value', $values))
1581
+			{
1582
+				foreach($values['value'] as $item_value)
1583
+				{
1584
+					if ($item == 0)
1585
+					{
1586
+						$jobattributes .=
1587
+							$values['systag']
1588
+								. self::_giveMeStringLength($key)
1589
+								. $key
1590
+								. self::_giveMeStringLength($item_value)
1591
+								. $item_value;
1592
+					}
1593
+					else
1594
+					{
1595
+						$jobattributes .=
1596
+							$values['systag']
1597
+								. self::_giveMeStringLength('')
1598
+								. self::_giveMeStringLength($item_value)
1599
+								. $item_value;
1600
+					}
1601
+					$item++;
1602
+				}
1603
+			}
1604
+		}
1605
+		$printerattributes = '';
1606
+		foreach($this->printer_tags as $key => $values)
1607
+		{
1608
+			$item = 0;
1609
+			if (array_key_exists('value', $values))
1610
+			{
1611
+				foreach($values['value'] as $item_value)
1612
+				{
1613
+					if ($item == 0)
1614
+					{
1615
+						$printerattributes .=
1616
+							$values['systag']
1617
+								. self::_giveMeStringLength($key)
1618
+								. $key
1619
+								. self::_giveMeStringLength($item_value)
1620
+								. $item_value;
1621
+					}
1622
+					else
1623
+					{
1624
+						$printerattributes .=
1625
+							$values['systag']
1626
+								. self::_giveMeStringLength('')
1627
+								. self::_giveMeStringLength($item_value)
1628
+								. $item_value;
1629
+					}
1630
+					$item++;
1631
+				}
1632
+			}
1633
+		}
1634
+		reset($this->job_tags);
1635
+		reset($this->operation_tags);
1636
+		reset($this->printer_tags);
1637
+		return true;
1638
+	}
1639
+
1640
+	protected function _giveMeStringLength($string)
1641
+	{
1642
+		$length = strlen($string);
1643
+		if ($length > ((0xFF << 8) + 0xFF)  )
1644
+		{
1645
+			$errmsg = sprintf (
1646
+				_('max string length for an ipp meta-information = %d, while here %d'),
1647
+				((0xFF << 8) + 0xFF), $length);
1648
+
1649
+			if ($this->with_exceptions)
1650
+			{
1651
+				throw new ippException($errmsg);
1652
+			}
1653
+			else
1654
+			{
1655
+				trigger_error ($errmsg, E_USER_ERROR);
1656
+			}
1657
+		}
1658
+		$int1 = $length & 0xFF;
1659
+		$length -= $int1;
1660
+		$length = $length >> 8;
1661
+		$int2 = $length & 0xFF;
1662
+		return chr($int2) . chr($int1);
1663
+	}
1664
+
1665
+	protected function _enumBuild($tag, $value)
1666
+	{
1667
+		switch ($tag)
1668
+		{
1669
+			case "orientation-requested":
1670
+				switch ($value)
1671
+				{
1672
+					case 'portrait':
1673
+						$value = chr(3);
1674
+						break;
1675
+
1676
+					case 'landscape':
1677
+						$value = chr(4);
1678
+						break;
1679
+
1680
+					case 'reverse-landscape':
1681
+						$value = chr(5);
1682
+						break;
1683
+
1684
+					case 'reverse-portrait':
1685
+						$value = chr(6);
1686
+						break;
1687
+				}
1688
+				break;
1689
+
1690
+			case "print-quality":
1691
+				switch ($value)
1692
+				{
1693
+					case 'draft':
1694
+						$value = chr(3);
1695
+						break;
1696
+
1697
+					case 'normal':
1698
+						$value = chr(4);
1699
+						break;
1700
+
1701
+					case 'high':
1702
+						$value = chr(5);
1703
+						break;
1704
+				}
1705
+				break;
1706
+
1707
+			case "finishing":
1708
+				switch ($value)
1709
+				{
1710
+					case 'none':
1711
+						$value = chr(3);
1712
+						break;
1713
+
1714
+					case 'staple':
1715
+						$value = chr(4);
1716
+						break;
1717
+
1718
+					case 'punch':
1719
+						$value = chr(5);
1720
+						break;
1721
+
1722
+					case 'cover':
1723
+						$value = chr(6);
1724
+						break;
1725
+
1726
+					case 'bind':
1727
+						$value = chr(7);
1728
+						break;
1729
+
1730
+					case 'saddle-stitch':
1731
+						$value = chr(8);
1732
+						break;
1733
+
1734
+					case 'edge-stitch':
1735
+						$value = chr(9);
1736
+						break;
1737
+
1738
+					case 'staple-top-left':
1739
+						$value = chr(20);
1740
+						break;
1741
+
1742
+					case 'staple-bottom-left':
1743
+						$value = chr(21);
1744
+						break;
1745
+
1746
+					case 'staple-top-right':
1747
+						$value = chr(22);
1748
+						break;
1749
+
1750
+					case 'staple-bottom-right':
1751
+						$value = chr(23);
1752
+						break;
1753
+
1754
+					case 'edge-stitch-left':
1755
+						$value = chr(24);
1756
+						break;
1757
+
1758
+					case 'edge-stitch-top':
1759
+						$value = chr(25);
1760
+						break;
1761
+
1762
+					case 'edge-stitch-right':
1763
+						$value = chr(26);
1764
+						break;
1765
+
1766
+					case 'edge-stitch-bottom':
1767
+						$value = chr(27);
1768
+						break;
1769
+
1770
+					case 'staple-dual-left':
1771
+						$value = chr(28);
1772
+						break;
1773
+
1774
+					case 'staple-dual-top':
1775
+						$value = chr(29);
1776
+						break;
1777
+
1778
+					case 'staple-dual-right':
1779
+						$value = chr(30);
1780
+						break;
1781
+
1782
+					case 'staple-dual-bottom':
1783
+						$value = chr(31);
1784
+						break;
1785
+				}
1786
+				break;
1787
+		}
1788
+		$prepend = '';
1789
+		while ((strlen($value) + strlen($prepend)) < 4)
1790
+		{
1791
+			$prepend .= chr(0);
1792
+		}
1793
+		return $prepend . $value;
1794
+	}
1795
+
1796
+	protected function _integerBuild($value)
1797
+	{
1798
+		if ($value >= 2147483647 || $value < - 2147483648)
1799
+		{
1800
+			trigger_error(
1801
+				_("Values must be between -2147483648 and 2147483647: assuming '0'") , E_USER_WARNING);
1802
+			return chr(0x00) . chr(0x00) . chr(0x00) . chr(0x00);
1803
+		}
1804
+		$initial_value = $value;
1805
+		$int1 = $value & 0xFF;
1806
+		$value -= $int1;
1807
+		$value = $value >> 8;
1808
+		$int2 = $value & 0xFF;
1809
+		$value-= $int2;
1810
+		$value = $value >> 8;
1811
+		$int3 = $value & 0xFF;
1812
+		$value-= $int3;
1813
+		$value = $value >> 8;
1814
+		$int4 = $value & 0xFF; //64bits
1815
+		if ($initial_value < 0) {
1816
+			$int4 = chr($int4) | chr(0x80);
1817
+		}
1818
+		else {
1819
+			$int4 = chr($int4);
1820
+		}
1821
+		$value = $int4 . chr($int3) . chr($int2) . chr($int1);
1822
+		return $value;
1823
+	}
1824
+
1825
+	protected function _rangeOfIntegerBuild($integers)
1826
+	{
1827
+		#$integers = split(":", $integers);
1828
+		$integers = preg_split("#:#", $integers);
1829
+		for ($i = 0; $i < 2; $i++) {
1830
+			$outvalue[$i] = self::_integerBuild($integers[$i]);
1831
+		}
1832
+		return $outvalue[0] . $outvalue[1];
1833
+	}
1834
+
1835
+	protected function _setJobAttribute($attribute, $value)
1836
+	{
1837
+		//used by setAttribute
1838
+		$tag_type = $this->job_tags[$attribute]['tag'];
1839
+		switch ($tag_type)
1840
+		{
1841
+			case 'integer':
1842
+				$this->job_tags[$attribute]['value'][] = self::_integerBuild($value);
1843
+				break;
1844
+
1845
+			case 'boolean':
1846
+			case 'nameWithoutLanguage':
1847
+			case 'nameWithLanguage':
1848
+			case 'textWithoutLanguage':
1849
+			case 'textWithLanguage':
1850
+			case 'keyword':
1851
+			case 'naturalLanguage':
1852
+				$this->job_tags[$attribute]['value'][] = $value;
1853
+				break;
1854
+
1855
+			case 'enum':
1856
+				$value = $this->_enumBuild($attribute, $value); // may be overwritten by children
1857
+				$this->job_tags[$attribute]['value'][] = $value;
1858
+				break;
1859
+
1860
+			case 'rangeOfInteger':
1861
+				// $value have to be: INT1:INT2 , eg 100:1000
1862
+				$this->job_tags[$attribute]['value'][] = self::_rangeOfIntegerBuild($value);
1863
+				break;
1864
+
1865
+			case 'resolution':
1866
+				if (preg_match("#dpi#", $value)) {
1867
+					$unit = chr(0x3);
1868
+				}
1869
+				if (preg_match("#dpc#", $value)) {
1870
+					$unit = chr(0x4);
1871
+				}
1872
+				$search = array(
1873
+					"#(dpi|dpc)#",
1874
+					'#(x|-)#'
1875
+				);
1876
+				$replace = array(
1877
+					"",
1878
+					":"
1879
+				);
1880
+				$value = self::_rangeOfIntegerBuild(preg_replace($search, $replace, $value)) . $unit;
1881
+				$this->job_tags[$attribute]['value'][] = $value;
1882
+				break;
1883
+
1884
+			default:
1885
+				trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1886
+				self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1887
+				self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1888
+				return FALSE;
1889
+				break;
1890
+		}
1891
+		$this->job_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1892
+	}
1893
+
1894
+	protected function _setOperationAttribute($attribute, $value)
1895
+	{
1896
+		//used by setAttribute
1897
+		$tag_type = $this->operation_tags[$attribute]['tag'];
1898
+		switch ($tag_type)
1899
+		{
1900
+			case 'integer':
1901
+				$this->operation_tags[$attribute]['value'][] = self::_integerBuild($value);
1902
+				break;
1903
+
1904
+			case 'keyword':
1905
+			case 'naturalLanguage':
1906
+				$this->operation_tags[$attribute]['value'][] = $value;
1907
+				break;
1908
+
1909
+			default:
1910
+				trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1911
+				self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1912
+				self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1913
+				return FALSE;
1914
+				break;
1915
+		}
1916
+		$this->operation_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1917
+	}
1918
+
1919
+	protected function _setPrinterAttribute($attribute, $value)
1920
+	{
1921
+		//used by setAttribute
1922
+		$tag_type = $this->printer_tags[$attribute]['tag'];
1923
+		switch ($tag_type)
1924
+		{
1925
+			case 'integer':
1926
+				$this->printer_tags[$attribute]['value'][] = self::_integerBuild($value);
1927
+				break;
1928
+
1929
+			case 'keyword':
1930
+			case 'naturalLanguage':
1931
+				$this->printer_tags[$attribute]['value'][] = $value;
1932
+				break;
1933
+
1934
+			default:
1935
+				trigger_error(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , E_USER_NOTICE);
1936
+				self::_putDebug(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1937
+				self::_errorLog(sprintf(_('SetAttribute: Tag "%s": cannot set attribute') , $attribute) , 2);
1938
+				return FALSE;
1939
+				break;
1940
+		}
1941
+		$this->printer_tags[$attribute]['systag'] = $this->tags_types[$tag_type]['tag'];
1942
+	}
1943
+
1944
+	//
1945
+	// DEBUGGING
1946
+	//
1947
+	protected function _putDebug($string, $level = 1)
1948
+	{
1949
+		if ($level === false) {
1950
+			return;
1951
+		}
1952
+
1953
+		if ($level < $this->debug_level) {
1954
+			return;
1955
+		}
1956
+
1957
+		$this->debug[$this->debug_count] = substr($string, 0, 1024);
1958
+		$this->debug_count++;
1959
+		//$this->debug .= substr($string,0,1024);
1960
+
1961
+	}
1962
+
1963
+	//
1964
+	// LOGGING
1965
+	//
1966
+	protected function _errorLog($string_to_log, $level)
1967
+	{
1968
+		if ($level > $this->log_level) {
1969
+			return;
1970
+		}
1971
+
1972
+		$string = sprintf('%s : %s:%s user %s : %s', basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log);
1973
+
1974
+		if ($this->log_type == 0)
1975
+		{
1976
+			error_log($string);
1977
+			return;
1978
+		}
1979
+
1980
+		$string = sprintf("%s %s Host %s:%s user %s : %s\n", date('M d H:i:s') , basename($_SERVER['PHP_SELF']) , $this->host, $this->port, $this->requesting_user, $string_to_log);
1981
+		error_log($string, $this->log_type, $this->log_destination);
1982
+		return;
1983
+	}
1984 1984
 }
Please login to merge, or discard this patch.