@@ -11,275 +11,275 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class nusoap_xmlschema extends nusoap_base |
13 | 13 | { |
14 | - // files |
|
15 | - var $schema = ''; |
|
16 | - var $xml = ''; |
|
17 | - // namespaces |
|
18 | - var $enclosingNamespaces; |
|
19 | - // schema info |
|
20 | - var $schemaInfo = array(); |
|
21 | - var $schemaTargetNamespace = ''; |
|
22 | - // types, elements, attributes defined by the schema |
|
23 | - var $attributes = array(); |
|
24 | - var $complexTypes = array(); |
|
25 | - var $complexTypeStack = array(); |
|
26 | - var $currentComplexType = null; |
|
27 | - var $elements = array(); |
|
28 | - var $elementStack = array(); |
|
29 | - var $currentElement = null; |
|
30 | - var $simpleTypes = array(); |
|
31 | - var $simpleTypeStack = array(); |
|
32 | - var $currentSimpleType = null; |
|
33 | - // imports |
|
34 | - var $imports = array(); |
|
35 | - // parser vars |
|
36 | - var $parser; |
|
37 | - var $position = 0; |
|
38 | - var $depth = 0; |
|
39 | - var $depth_array = array(); |
|
40 | - var $message = array(); |
|
41 | - var $defaultNamespace = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * constructor |
|
45 | - * |
|
46 | - * @param string $schema schema document URI |
|
47 | - * @param string $xml xml document URI |
|
48 | - * @param string $namespaces namespaces defined in enclosing XML |
|
49 | - * @access public |
|
50 | - */ |
|
51 | - function __construct($schema='',$xml='',$namespaces=array()){ |
|
52 | - parent::__construct(); |
|
53 | - $this->debug('nusoap_xmlschema class instantiated, inside constructor'); |
|
54 | - // files |
|
55 | - $this->schema = $schema; |
|
56 | - $this->xml = $xml; |
|
57 | - |
|
58 | - // namespaces |
|
59 | - $this->enclosingNamespaces = $namespaces; |
|
60 | - $this->namespaces = array_merge($this->namespaces, $namespaces); |
|
61 | - |
|
62 | - // parse schema file |
|
63 | - if($schema != ''){ |
|
64 | - $this->debug('initial schema file: '.$schema); |
|
65 | - $this->parseFile($schema, 'schema'); |
|
66 | - } |
|
67 | - |
|
68 | - // parse xml file |
|
69 | - if($xml != ''){ |
|
70 | - $this->debug('initial xml file: '.$xml); |
|
71 | - $this->parseFile($xml, 'xml'); |
|
72 | - } |
|
73 | - |
|
74 | - } |
|
14 | + // files |
|
15 | + var $schema = ''; |
|
16 | + var $xml = ''; |
|
17 | + // namespaces |
|
18 | + var $enclosingNamespaces; |
|
19 | + // schema info |
|
20 | + var $schemaInfo = array(); |
|
21 | + var $schemaTargetNamespace = ''; |
|
22 | + // types, elements, attributes defined by the schema |
|
23 | + var $attributes = array(); |
|
24 | + var $complexTypes = array(); |
|
25 | + var $complexTypeStack = array(); |
|
26 | + var $currentComplexType = null; |
|
27 | + var $elements = array(); |
|
28 | + var $elementStack = array(); |
|
29 | + var $currentElement = null; |
|
30 | + var $simpleTypes = array(); |
|
31 | + var $simpleTypeStack = array(); |
|
32 | + var $currentSimpleType = null; |
|
33 | + // imports |
|
34 | + var $imports = array(); |
|
35 | + // parser vars |
|
36 | + var $parser; |
|
37 | + var $position = 0; |
|
38 | + var $depth = 0; |
|
39 | + var $depth_array = array(); |
|
40 | + var $message = array(); |
|
41 | + var $defaultNamespace = array(); |
|
75 | 42 | |
76 | 43 | /** |
77 | - * parse an XML file |
|
78 | - * |
|
79 | - * @param string $xml path/URL to XML file |
|
80 | - * @param string $type (schema | xml) |
|
81 | - * @return boolean |
|
82 | - * @access public |
|
83 | - */ |
|
84 | - function parseFile($xml,$type){ |
|
85 | - // parse xml file |
|
86 | - if($xml != ""){ |
|
87 | - $xmlStr = @join("",@file($xml)); |
|
88 | - if($xmlStr == ""){ |
|
89 | - $msg = 'Error reading XML from '.$xml; |
|
90 | - $this->setError($msg); |
|
91 | - $this->debug($msg); |
|
92 | - return false; |
|
93 | - } else { |
|
94 | - $this->debug("parsing $xml"); |
|
95 | - $this->parseString($xmlStr,$type); |
|
96 | - $this->debug("done parsing $xml"); |
|
97 | - return true; |
|
98 | - } |
|
99 | - } |
|
100 | - return false; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * parse an XML string |
|
105 | - * |
|
106 | - * @param string $xml path or URL |
|
107 | - * @param string $type (schema|xml) |
|
108 | - * @access private |
|
109 | - */ |
|
110 | - function parseString($xml,$type){ |
|
111 | - // parse xml string |
|
112 | - if($xml != ""){ |
|
113 | - |
|
114 | - // Create an XML parser. |
|
115 | - $this->parser = xml_parser_create(); |
|
116 | - // Set the options for parsing the XML data. |
|
117 | - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
118 | - |
|
119 | - // Set the object for the parser. |
|
120 | - xml_set_object($this->parser, $this); |
|
121 | - |
|
122 | - // Set the element handlers for the parser. |
|
123 | - if($type == "schema"){ |
|
124 | - xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); |
|
125 | - xml_set_character_data_handler($this->parser,'schemaCharacterData'); |
|
126 | - } elseif($type == "xml"){ |
|
127 | - xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); |
|
128 | - xml_set_character_data_handler($this->parser,'xmlCharacterData'); |
|
129 | - } |
|
130 | - |
|
131 | - // Parse the XML file. |
|
132 | - if(!xml_parse($this->parser,$xml,true)){ |
|
133 | - // Display an error message. |
|
134 | - $errstr = sprintf('XML error parsing XML schema on line %d: %s', |
|
135 | - xml_get_current_line_number($this->parser), |
|
136 | - xml_error_string(xml_get_error_code($this->parser)) |
|
137 | - ); |
|
138 | - $this->debug($errstr); |
|
139 | - $this->debug("XML payload:\n" . $xml); |
|
140 | - $this->setError($errstr); |
|
141 | - } |
|
142 | - |
|
143 | - xml_parser_free($this->parser); |
|
144 | - } else{ |
|
145 | - $this->debug('no xml passed to parseString()!!'); |
|
146 | - $this->setError('no xml passed to parseString()!!'); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * gets a type name for an unnamed type |
|
152 | - * |
|
153 | - * @param string Element name |
|
154 | - * @return string A type name for an unnamed type |
|
155 | - * @access private |
|
156 | - */ |
|
157 | - function CreateTypeName($ename) { |
|
158 | - $scope = ''; |
|
159 | - for ($i = 0; $i < count($this->complexTypeStack); $i++) { |
|
160 | - $scope .= $this->complexTypeStack[$i] . '_'; |
|
161 | - } |
|
162 | - return $scope . $ename . '_ContainedType'; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * start-element handler |
|
167 | - * |
|
168 | - * @param string $parser XML parser object |
|
169 | - * @param string $name element name |
|
170 | - * @param string $attrs associative array of attributes |
|
171 | - * @access private |
|
172 | - */ |
|
173 | - function schemaStartElement($parser, $name, $attrs) { |
|
174 | - |
|
175 | - // position in the total number of elements, starting from 0 |
|
176 | - $pos = $this->position++; |
|
177 | - $depth = $this->depth++; |
|
178 | - // set self as current value for this depth |
|
179 | - $this->depth_array[$depth] = $pos; |
|
180 | - $this->message[$pos] = array('cdata' => ''); |
|
181 | - if ($depth > 0) { |
|
182 | - $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]]; |
|
183 | - } else { |
|
184 | - $this->defaultNamespace[$pos] = false; |
|
185 | - } |
|
186 | - |
|
187 | - // get element prefix |
|
188 | - if($prefix = $this->getPrefix($name)){ |
|
189 | - // get unqualified name |
|
190 | - $name = $this->getLocalPart($name); |
|
191 | - } else { |
|
192 | - $prefix = ''; |
|
44 | + * constructor |
|
45 | + * |
|
46 | + * @param string $schema schema document URI |
|
47 | + * @param string $xml xml document URI |
|
48 | + * @param string $namespaces namespaces defined in enclosing XML |
|
49 | + * @access public |
|
50 | + */ |
|
51 | + function __construct($schema='',$xml='',$namespaces=array()){ |
|
52 | + parent::__construct(); |
|
53 | + $this->debug('nusoap_xmlschema class instantiated, inside constructor'); |
|
54 | + // files |
|
55 | + $this->schema = $schema; |
|
56 | + $this->xml = $xml; |
|
57 | + |
|
58 | + // namespaces |
|
59 | + $this->enclosingNamespaces = $namespaces; |
|
60 | + $this->namespaces = array_merge($this->namespaces, $namespaces); |
|
61 | + |
|
62 | + // parse schema file |
|
63 | + if($schema != ''){ |
|
64 | + $this->debug('initial schema file: '.$schema); |
|
65 | + $this->parseFile($schema, 'schema'); |
|
66 | + } |
|
67 | + |
|
68 | + // parse xml file |
|
69 | + if($xml != ''){ |
|
70 | + $this->debug('initial xml file: '.$xml); |
|
71 | + $this->parseFile($xml, 'xml'); |
|
72 | + } |
|
73 | + |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * parse an XML file |
|
78 | + * |
|
79 | + * @param string $xml path/URL to XML file |
|
80 | + * @param string $type (schema | xml) |
|
81 | + * @return boolean |
|
82 | + * @access public |
|
83 | + */ |
|
84 | + function parseFile($xml,$type){ |
|
85 | + // parse xml file |
|
86 | + if($xml != ""){ |
|
87 | + $xmlStr = @join("",@file($xml)); |
|
88 | + if($xmlStr == ""){ |
|
89 | + $msg = 'Error reading XML from '.$xml; |
|
90 | + $this->setError($msg); |
|
91 | + $this->debug($msg); |
|
92 | + return false; |
|
93 | + } else { |
|
94 | + $this->debug("parsing $xml"); |
|
95 | + $this->parseString($xmlStr,$type); |
|
96 | + $this->debug("done parsing $xml"); |
|
97 | + return true; |
|
98 | + } |
|
99 | + } |
|
100 | + return false; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * parse an XML string |
|
105 | + * |
|
106 | + * @param string $xml path or URL |
|
107 | + * @param string $type (schema|xml) |
|
108 | + * @access private |
|
109 | + */ |
|
110 | + function parseString($xml,$type){ |
|
111 | + // parse xml string |
|
112 | + if($xml != ""){ |
|
113 | + |
|
114 | + // Create an XML parser. |
|
115 | + $this->parser = xml_parser_create(); |
|
116 | + // Set the options for parsing the XML data. |
|
117 | + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
118 | + |
|
119 | + // Set the object for the parser. |
|
120 | + xml_set_object($this->parser, $this); |
|
121 | + |
|
122 | + // Set the element handlers for the parser. |
|
123 | + if($type == "schema"){ |
|
124 | + xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); |
|
125 | + xml_set_character_data_handler($this->parser,'schemaCharacterData'); |
|
126 | + } elseif($type == "xml"){ |
|
127 | + xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); |
|
128 | + xml_set_character_data_handler($this->parser,'xmlCharacterData'); |
|
129 | + } |
|
130 | + |
|
131 | + // Parse the XML file. |
|
132 | + if(!xml_parse($this->parser,$xml,true)){ |
|
133 | + // Display an error message. |
|
134 | + $errstr = sprintf('XML error parsing XML schema on line %d: %s', |
|
135 | + xml_get_current_line_number($this->parser), |
|
136 | + xml_error_string(xml_get_error_code($this->parser)) |
|
137 | + ); |
|
138 | + $this->debug($errstr); |
|
139 | + $this->debug("XML payload:\n" . $xml); |
|
140 | + $this->setError($errstr); |
|
141 | + } |
|
142 | + |
|
143 | + xml_parser_free($this->parser); |
|
144 | + } else{ |
|
145 | + $this->debug('no xml passed to parseString()!!'); |
|
146 | + $this->setError('no xml passed to parseString()!!'); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * gets a type name for an unnamed type |
|
152 | + * |
|
153 | + * @param string Element name |
|
154 | + * @return string A type name for an unnamed type |
|
155 | + * @access private |
|
156 | + */ |
|
157 | + function CreateTypeName($ename) { |
|
158 | + $scope = ''; |
|
159 | + for ($i = 0; $i < count($this->complexTypeStack); $i++) { |
|
160 | + $scope .= $this->complexTypeStack[$i] . '_'; |
|
161 | + } |
|
162 | + return $scope . $ename . '_ContainedType'; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * start-element handler |
|
167 | + * |
|
168 | + * @param string $parser XML parser object |
|
169 | + * @param string $name element name |
|
170 | + * @param string $attrs associative array of attributes |
|
171 | + * @access private |
|
172 | + */ |
|
173 | + function schemaStartElement($parser, $name, $attrs) { |
|
174 | + |
|
175 | + // position in the total number of elements, starting from 0 |
|
176 | + $pos = $this->position++; |
|
177 | + $depth = $this->depth++; |
|
178 | + // set self as current value for this depth |
|
179 | + $this->depth_array[$depth] = $pos; |
|
180 | + $this->message[$pos] = array('cdata' => ''); |
|
181 | + if ($depth > 0) { |
|
182 | + $this->defaultNamespace[$pos] = $this->defaultNamespace[$this->depth_array[$depth - 1]]; |
|
183 | + } else { |
|
184 | + $this->defaultNamespace[$pos] = false; |
|
185 | + } |
|
186 | + |
|
187 | + // get element prefix |
|
188 | + if($prefix = $this->getPrefix($name)){ |
|
189 | + // get unqualified name |
|
190 | + $name = $this->getLocalPart($name); |
|
191 | + } else { |
|
192 | + $prefix = ''; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | // loop thru attributes, expanding, and registering namespace declarations |
196 | 196 | if(count($attrs) > 0){ |
197 | - foreach($attrs as $k => $v){ |
|
197 | + foreach($attrs as $k => $v){ |
|
198 | 198 | // if ns declarations, add to class level array of valid namespaces |
199 | - if(preg_match('/^xmlns/',$k)){ |
|
200 | - //$this->xdebug("$k: $v"); |
|
201 | - //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); |
|
202 | - if($ns_prefix = substr(strrchr($k,':'),1)){ |
|
203 | - //$this->xdebug("Add namespace[$ns_prefix] = $v"); |
|
204 | - $this->namespaces[$ns_prefix] = $v; |
|
205 | - } else { |
|
206 | - $this->defaultNamespace[$pos] = $v; |
|
207 | - if (! $this->getPrefixFromNamespace($v)) { |
|
208 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; |
|
209 | - } |
|
210 | - } |
|
211 | - if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){ |
|
212 | - $this->XMLSchemaVersion = $v; |
|
213 | - $this->namespaces['xsi'] = $v.'-instance'; |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - foreach($attrs as $k => $v){ |
|
199 | + if(preg_match('/^xmlns/',$k)){ |
|
200 | + //$this->xdebug("$k: $v"); |
|
201 | + //$this->xdebug('ns_prefix: '.$this->getPrefix($k)); |
|
202 | + if($ns_prefix = substr(strrchr($k,':'),1)){ |
|
203 | + //$this->xdebug("Add namespace[$ns_prefix] = $v"); |
|
204 | + $this->namespaces[$ns_prefix] = $v; |
|
205 | + } else { |
|
206 | + $this->defaultNamespace[$pos] = $v; |
|
207 | + if (! $this->getPrefixFromNamespace($v)) { |
|
208 | + $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; |
|
209 | + } |
|
210 | + } |
|
211 | + if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){ |
|
212 | + $this->XMLSchemaVersion = $v; |
|
213 | + $this->namespaces['xsi'] = $v.'-instance'; |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + foreach($attrs as $k => $v){ |
|
218 | 218 | // expand each attribute |
219 | 219 | $k = strpos($k,':') ? $this->expandQname($k) : $k; |
220 | 220 | $v = strpos($v,':') ? $this->expandQname($v) : $v; |
221 | - $eAttrs[$k] = $v; |
|
222 | - } |
|
223 | - $attrs = $eAttrs; |
|
221 | + $eAttrs[$k] = $v; |
|
222 | + } |
|
223 | + $attrs = $eAttrs; |
|
224 | 224 | } else { |
225 | - $attrs = array(); |
|
225 | + $attrs = array(); |
|
226 | 226 | } |
227 | - // find status, register data |
|
228 | - switch($name){ |
|
229 | - case 'all': // (optional) compositor content for a complexType |
|
230 | - case 'choice': |
|
231 | - case 'group': |
|
232 | - case 'sequence': |
|
233 | - //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement"); |
|
234 | - $this->complexTypes[$this->currentComplexType]['compositor'] = $name; |
|
235 | - //if($name == 'all' || $name == 'sequence'){ |
|
236 | - // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
237 | - //} |
|
238 | - break; |
|
239 | - case 'attribute': // complexType attribute |
|
240 | - //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); |
|
241 | - $this->xdebug("parsing attribute:"); |
|
242 | - $this->appendDebug($this->varDump($attrs)); |
|
243 | - if (!isset($attrs['form'])) { |
|
244 | - // TODO: handle globals |
|
245 | - $attrs['form'] = $this->schemaInfo['attributeFormDefault']; |
|
246 | - } |
|
247 | - if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
248 | - $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
249 | - if (!strpos($v, ':')) { |
|
250 | - // no namespace in arrayType attribute value... |
|
251 | - if ($this->defaultNamespace[$pos]) { |
|
252 | - // ...so use the default |
|
253 | - $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
227 | + // find status, register data |
|
228 | + switch($name){ |
|
229 | + case 'all': // (optional) compositor content for a complexType |
|
230 | + case 'choice': |
|
231 | + case 'group': |
|
232 | + case 'sequence': |
|
233 | + //$this->xdebug("compositor $name for currentComplexType: $this->currentComplexType and currentElement: $this->currentElement"); |
|
234 | + $this->complexTypes[$this->currentComplexType]['compositor'] = $name; |
|
235 | + //if($name == 'all' || $name == 'sequence'){ |
|
236 | + // $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
237 | + //} |
|
238 | + break; |
|
239 | + case 'attribute': // complexType attribute |
|
240 | + //$this->xdebug("parsing attribute $attrs[name] $attrs[ref] of value: ".$attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']); |
|
241 | + $this->xdebug("parsing attribute:"); |
|
242 | + $this->appendDebug($this->varDump($attrs)); |
|
243 | + if (!isset($attrs['form'])) { |
|
244 | + // TODO: handle globals |
|
245 | + $attrs['form'] = $this->schemaInfo['attributeFormDefault']; |
|
246 | + } |
|
247 | + if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
248 | + $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
249 | + if (!strpos($v, ':')) { |
|
250 | + // no namespace in arrayType attribute value... |
|
251 | + if ($this->defaultNamespace[$pos]) { |
|
252 | + // ...so use the default |
|
253 | + $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | 257 | if(isset($attrs['name'])){ |
258 | - $this->attributes[$attrs['name']] = $attrs; |
|
259 | - $aname = $attrs['name']; |
|
260 | - } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){ |
|
261 | - if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
262 | - $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
263 | - } else { |
|
264 | - $aname = ''; |
|
265 | - } |
|
266 | - } elseif(isset($attrs['ref'])){ |
|
267 | - $aname = $attrs['ref']; |
|
258 | + $this->attributes[$attrs['name']] = $attrs; |
|
259 | + $aname = $attrs['name']; |
|
260 | + } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){ |
|
261 | + if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
262 | + $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
263 | + } else { |
|
264 | + $aname = ''; |
|
265 | + } |
|
266 | + } elseif(isset($attrs['ref'])){ |
|
267 | + $aname = $attrs['ref']; |
|
268 | 268 | $this->attributes[$attrs['ref']] = $attrs; |
269 | - } |
|
270 | - |
|
271 | - if($this->currentComplexType){ // This should *always* be |
|
272 | - $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; |
|
273 | - } |
|
274 | - // arrayType attribute |
|
275 | - if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){ |
|
276 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
277 | - $prefix = $this->getPrefix($aname); |
|
278 | - if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){ |
|
279 | - $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
280 | - } else { |
|
281 | - $v = ''; |
|
282 | - } |
|
269 | + } |
|
270 | + |
|
271 | + if($this->currentComplexType){ // This should *always* be |
|
272 | + $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; |
|
273 | + } |
|
274 | + // arrayType attribute |
|
275 | + if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){ |
|
276 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
277 | + $prefix = $this->getPrefix($aname); |
|
278 | + if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){ |
|
279 | + $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
280 | + } else { |
|
281 | + $v = ''; |
|
282 | + } |
|
283 | 283 | if(strpos($v,'[,]')){ |
284 | 284 | $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; |
285 | 285 | } |
@@ -288,676 +288,676 @@ discard block |
||
288 | 288 | $v = $this->XMLSchemaVersion.':'.$v; |
289 | 289 | } |
290 | 290 | $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; |
291 | - } |
|
292 | - break; |
|
293 | - case 'complexContent': // (optional) content for a complexType |
|
294 | - $this->xdebug("do nothing for element $name"); |
|
295 | - break; |
|
296 | - case 'complexType': |
|
297 | - array_push($this->complexTypeStack, $this->currentComplexType); |
|
298 | - if(isset($attrs['name'])){ |
|
299 | - // TODO: what is the scope of named complexTypes that appear |
|
300 | - // nested within other c complexTypes? |
|
301 | - $this->xdebug('processing named complexType '.$attrs['name']); |
|
302 | - //$this->currentElement = false; |
|
303 | - $this->currentComplexType = $attrs['name']; |
|
304 | - $this->complexTypes[$this->currentComplexType] = $attrs; |
|
305 | - $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
|
306 | - // This is for constructs like |
|
307 | - // <complexType name="ListOfString" base="soap:Array"> |
|
308 | - // <sequence> |
|
309 | - // <element name="string" type="xsd:string" |
|
310 | - // minOccurs="0" maxOccurs="unbounded" /> |
|
311 | - // </sequence> |
|
312 | - // </complexType> |
|
313 | - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
314 | - $this->xdebug('complexType is unusual array'); |
|
315 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
316 | - } else { |
|
317 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
318 | - } |
|
319 | - } else { |
|
320 | - $name = $this->CreateTypeName($this->currentElement); |
|
321 | - $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name); |
|
322 | - $this->currentComplexType = $name; |
|
323 | - //$this->currentElement = false; |
|
324 | - $this->complexTypes[$this->currentComplexType] = $attrs; |
|
325 | - $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
|
326 | - // This is for constructs like |
|
327 | - // <complexType name="ListOfString" base="soap:Array"> |
|
328 | - // <sequence> |
|
329 | - // <element name="string" type="xsd:string" |
|
330 | - // minOccurs="0" maxOccurs="unbounded" /> |
|
331 | - // </sequence> |
|
332 | - // </complexType> |
|
333 | - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
334 | - $this->xdebug('complexType is unusual array'); |
|
335 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
336 | - } else { |
|
337 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
338 | - } |
|
339 | - } |
|
340 | - $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; |
|
341 | - break; |
|
342 | - case 'element': |
|
343 | - array_push($this->elementStack, $this->currentElement); |
|
344 | - if (!isset($attrs['form'])) { |
|
345 | - if ($this->currentComplexType) { |
|
346 | - $attrs['form'] = $this->schemaInfo['elementFormDefault']; |
|
347 | - } else { |
|
348 | - // global |
|
349 | - $attrs['form'] = 'qualified'; |
|
350 | - } |
|
351 | - } |
|
352 | - if(isset($attrs['type'])){ |
|
353 | - $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); |
|
354 | - if (! $this->getPrefix($attrs['type'])) { |
|
355 | - if ($this->defaultNamespace[$pos]) { |
|
356 | - $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; |
|
357 | - $this->xdebug('used default namespace to make type ' . $attrs['type']); |
|
358 | - } |
|
359 | - } |
|
360 | - // This is for constructs like |
|
361 | - // <complexType name="ListOfString" base="soap:Array"> |
|
362 | - // <sequence> |
|
363 | - // <element name="string" type="xsd:string" |
|
364 | - // minOccurs="0" maxOccurs="unbounded" /> |
|
365 | - // </sequence> |
|
366 | - // </complexType> |
|
367 | - if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') { |
|
368 | - $this->xdebug('arrayType for unusual array is ' . $attrs['type']); |
|
369 | - $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type']; |
|
370 | - } |
|
371 | - $this->currentElement = $attrs['name']; |
|
372 | - $ename = $attrs['name']; |
|
373 | - } elseif(isset($attrs['ref'])){ |
|
374 | - $this->xdebug("processing element as ref to ".$attrs['ref']); |
|
375 | - $this->currentElement = "ref to ".$attrs['ref']; |
|
376 | - $ename = $this->getLocalPart($attrs['ref']); |
|
377 | - } else { |
|
378 | - $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); |
|
379 | - $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type); |
|
380 | - $this->currentElement = $attrs['name']; |
|
381 | - $attrs['type'] = $this->schemaTargetNamespace . ':' . $type; |
|
382 | - $ename = $attrs['name']; |
|
383 | - } |
|
384 | - if (isset($ename) && $this->currentComplexType) { |
|
385 | - $this->xdebug("add element $ename to complexType $this->currentComplexType"); |
|
386 | - $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; |
|
387 | - } elseif (!isset($attrs['ref'])) { |
|
388 | - $this->xdebug("add element $ename to elements array"); |
|
389 | - $this->elements[ $attrs['name'] ] = $attrs; |
|
390 | - $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
391 | - } |
|
392 | - break; |
|
393 | - case 'enumeration': // restriction value list member |
|
394 | - $this->xdebug('enumeration ' . $attrs['value']); |
|
395 | - if ($this->currentSimpleType) { |
|
396 | - $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value']; |
|
397 | - } elseif ($this->currentComplexType) { |
|
398 | - $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value']; |
|
399 | - } |
|
400 | - break; |
|
401 | - case 'extension': // simpleContent or complexContent type extension |
|
402 | - $this->xdebug('extension ' . $attrs['base']); |
|
403 | - if ($this->currentComplexType) { |
|
404 | - $ns = $this->getPrefix($attrs['base']); |
|
405 | - if ($ns == '') { |
|
406 | - $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; |
|
407 | - } else { |
|
408 | - $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; |
|
409 | - } |
|
410 | - } else { |
|
411 | - $this->xdebug('no current complexType to set extensionBase'); |
|
412 | - } |
|
413 | - break; |
|
414 | - case 'import': |
|
415 | - if (isset($attrs['schemaLocation'])) { |
|
416 | - $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); |
|
291 | + } |
|
292 | + break; |
|
293 | + case 'complexContent': // (optional) content for a complexType |
|
294 | + $this->xdebug("do nothing for element $name"); |
|
295 | + break; |
|
296 | + case 'complexType': |
|
297 | + array_push($this->complexTypeStack, $this->currentComplexType); |
|
298 | + if(isset($attrs['name'])){ |
|
299 | + // TODO: what is the scope of named complexTypes that appear |
|
300 | + // nested within other c complexTypes? |
|
301 | + $this->xdebug('processing named complexType '.$attrs['name']); |
|
302 | + //$this->currentElement = false; |
|
303 | + $this->currentComplexType = $attrs['name']; |
|
304 | + $this->complexTypes[$this->currentComplexType] = $attrs; |
|
305 | + $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
|
306 | + // This is for constructs like |
|
307 | + // <complexType name="ListOfString" base="soap:Array"> |
|
308 | + // <sequence> |
|
309 | + // <element name="string" type="xsd:string" |
|
310 | + // minOccurs="0" maxOccurs="unbounded" /> |
|
311 | + // </sequence> |
|
312 | + // </complexType> |
|
313 | + if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
314 | + $this->xdebug('complexType is unusual array'); |
|
315 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
316 | + } else { |
|
317 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
318 | + } |
|
319 | + } else { |
|
320 | + $name = $this->CreateTypeName($this->currentElement); |
|
321 | + $this->xdebug('processing unnamed complexType for element ' . $this->currentElement . ' named ' . $name); |
|
322 | + $this->currentComplexType = $name; |
|
323 | + //$this->currentElement = false; |
|
324 | + $this->complexTypes[$this->currentComplexType] = $attrs; |
|
325 | + $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
|
326 | + // This is for constructs like |
|
327 | + // <complexType name="ListOfString" base="soap:Array"> |
|
328 | + // <sequence> |
|
329 | + // <element name="string" type="xsd:string" |
|
330 | + // minOccurs="0" maxOccurs="unbounded" /> |
|
331 | + // </sequence> |
|
332 | + // </complexType> |
|
333 | + if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
334 | + $this->xdebug('complexType is unusual array'); |
|
335 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
336 | + } else { |
|
337 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'struct'; |
|
338 | + } |
|
339 | + } |
|
340 | + $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'false'; |
|
341 | + break; |
|
342 | + case 'element': |
|
343 | + array_push($this->elementStack, $this->currentElement); |
|
344 | + if (!isset($attrs['form'])) { |
|
345 | + if ($this->currentComplexType) { |
|
346 | + $attrs['form'] = $this->schemaInfo['elementFormDefault']; |
|
347 | + } else { |
|
348 | + // global |
|
349 | + $attrs['form'] = 'qualified'; |
|
350 | + } |
|
351 | + } |
|
352 | + if(isset($attrs['type'])){ |
|
353 | + $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); |
|
354 | + if (! $this->getPrefix($attrs['type'])) { |
|
355 | + if ($this->defaultNamespace[$pos]) { |
|
356 | + $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; |
|
357 | + $this->xdebug('used default namespace to make type ' . $attrs['type']); |
|
358 | + } |
|
359 | + } |
|
360 | + // This is for constructs like |
|
361 | + // <complexType name="ListOfString" base="soap:Array"> |
|
362 | + // <sequence> |
|
363 | + // <element name="string" type="xsd:string" |
|
364 | + // minOccurs="0" maxOccurs="unbounded" /> |
|
365 | + // </sequence> |
|
366 | + // </complexType> |
|
367 | + if ($this->currentComplexType && $this->complexTypes[$this->currentComplexType]['phpType'] == 'array') { |
|
368 | + $this->xdebug('arrayType for unusual array is ' . $attrs['type']); |
|
369 | + $this->complexTypes[$this->currentComplexType]['arrayType'] = $attrs['type']; |
|
370 | + } |
|
371 | + $this->currentElement = $attrs['name']; |
|
372 | + $ename = $attrs['name']; |
|
373 | + } elseif(isset($attrs['ref'])){ |
|
374 | + $this->xdebug("processing element as ref to ".$attrs['ref']); |
|
375 | + $this->currentElement = "ref to ".$attrs['ref']; |
|
376 | + $ename = $this->getLocalPart($attrs['ref']); |
|
377 | + } else { |
|
378 | + $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); |
|
379 | + $this->xdebug("processing untyped element " . $attrs['name'] . ' type ' . $type); |
|
380 | + $this->currentElement = $attrs['name']; |
|
381 | + $attrs['type'] = $this->schemaTargetNamespace . ':' . $type; |
|
382 | + $ename = $attrs['name']; |
|
383 | + } |
|
384 | + if (isset($ename) && $this->currentComplexType) { |
|
385 | + $this->xdebug("add element $ename to complexType $this->currentComplexType"); |
|
386 | + $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; |
|
387 | + } elseif (!isset($attrs['ref'])) { |
|
388 | + $this->xdebug("add element $ename to elements array"); |
|
389 | + $this->elements[ $attrs['name'] ] = $attrs; |
|
390 | + $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
391 | + } |
|
392 | + break; |
|
393 | + case 'enumeration': // restriction value list member |
|
394 | + $this->xdebug('enumeration ' . $attrs['value']); |
|
395 | + if ($this->currentSimpleType) { |
|
396 | + $this->simpleTypes[$this->currentSimpleType]['enumeration'][] = $attrs['value']; |
|
397 | + } elseif ($this->currentComplexType) { |
|
398 | + $this->complexTypes[$this->currentComplexType]['enumeration'][] = $attrs['value']; |
|
399 | + } |
|
400 | + break; |
|
401 | + case 'extension': // simpleContent or complexContent type extension |
|
402 | + $this->xdebug('extension ' . $attrs['base']); |
|
403 | + if ($this->currentComplexType) { |
|
404 | + $ns = $this->getPrefix($attrs['base']); |
|
405 | + if ($ns == '') { |
|
406 | + $this->complexTypes[$this->currentComplexType]['extensionBase'] = $this->schemaTargetNamespace . ':' . $attrs['base']; |
|
407 | + } else { |
|
408 | + $this->complexTypes[$this->currentComplexType]['extensionBase'] = $attrs['base']; |
|
409 | + } |
|
410 | + } else { |
|
411 | + $this->xdebug('no current complexType to set extensionBase'); |
|
412 | + } |
|
413 | + break; |
|
414 | + case 'import': |
|
415 | + if (isset($attrs['schemaLocation'])) { |
|
416 | + $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); |
|
417 | 417 | $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
418 | - } else { |
|
419 | - $this->xdebug('import namespace ' . $attrs['namespace']); |
|
418 | + } else { |
|
419 | + $this->xdebug('import namespace ' . $attrs['namespace']); |
|
420 | 420 | $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
421 | - if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
422 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
423 | - } |
|
424 | - } |
|
425 | - break; |
|
426 | - case 'include': |
|
427 | - if (isset($attrs['schemaLocation'])) { |
|
428 | - $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); |
|
421 | + if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
422 | + $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
423 | + } |
|
424 | + } |
|
425 | + break; |
|
426 | + case 'include': |
|
427 | + if (isset($attrs['schemaLocation'])) { |
|
428 | + $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); |
|
429 | 429 | $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
430 | - } else { |
|
431 | - $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); |
|
432 | - } |
|
433 | - break; |
|
434 | - case 'list': // simpleType value list |
|
435 | - $this->xdebug("do nothing for element $name"); |
|
436 | - break; |
|
437 | - case 'restriction': // simpleType, simpleContent or complexContent value restriction |
|
438 | - $this->xdebug('restriction ' . $attrs['base']); |
|
439 | - if($this->currentSimpleType){ |
|
440 | - $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; |
|
441 | - } elseif($this->currentComplexType){ |
|
442 | - $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; |
|
443 | - if(strstr($attrs['base'],':') == ':Array'){ |
|
444 | - $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
445 | - } |
|
446 | - } |
|
447 | - break; |
|
448 | - case 'schema': |
|
449 | - $this->schemaInfo = $attrs; |
|
450 | - $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix); |
|
451 | - if (isset($attrs['targetNamespace'])) { |
|
452 | - $this->schemaTargetNamespace = $attrs['targetNamespace']; |
|
453 | - } |
|
454 | - if (!isset($attrs['elementFormDefault'])) { |
|
455 | - $this->schemaInfo['elementFormDefault'] = 'unqualified'; |
|
456 | - } |
|
457 | - if (!isset($attrs['attributeFormDefault'])) { |
|
458 | - $this->schemaInfo['attributeFormDefault'] = 'unqualified'; |
|
459 | - } |
|
460 | - break; |
|
461 | - case 'simpleContent': // (optional) content for a complexType |
|
462 | - if ($this->currentComplexType) { // This should *always* be |
|
463 | - $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; |
|
464 | - } else { |
|
465 | - $this->xdebug("do nothing for element $name because there is no current complexType"); |
|
466 | - } |
|
467 | - break; |
|
468 | - case 'simpleType': |
|
469 | - array_push($this->simpleTypeStack, $this->currentSimpleType); |
|
470 | - if(isset($attrs['name'])){ |
|
471 | - $this->xdebug("processing simpleType for name " . $attrs['name']); |
|
472 | - $this->currentSimpleType = $attrs['name']; |
|
473 | - $this->simpleTypes[ $attrs['name'] ] = $attrs; |
|
474 | - $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; |
|
475 | - $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; |
|
476 | - } else { |
|
477 | - $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); |
|
478 | - $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name); |
|
479 | - $this->currentSimpleType = $name; |
|
480 | - //$this->currentElement = false; |
|
481 | - $this->simpleTypes[$this->currentSimpleType] = $attrs; |
|
482 | - $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar'; |
|
483 | - } |
|
484 | - break; |
|
485 | - case 'union': // simpleType type list |
|
486 | - $this->xdebug("do nothing for element $name"); |
|
487 | - break; |
|
488 | - default: |
|
489 | - $this->xdebug("do not have any logic to process element $name"); |
|
490 | - } |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * end-element handler |
|
495 | - * |
|
496 | - * @param string $parser XML parser object |
|
497 | - * @param string $name element name |
|
498 | - * @access private |
|
499 | - */ |
|
500 | - function schemaEndElement($parser, $name) { |
|
501 | - // bring depth down a notch |
|
502 | - $this->depth--; |
|
503 | - // position of current element is equal to the last value left in depth_array for my depth |
|
504 | - if(isset($this->depth_array[$this->depth])){ |
|
505 | - $pos = $this->depth_array[$this->depth]; |
|
430 | + } else { |
|
431 | + $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); |
|
432 | + } |
|
433 | + break; |
|
434 | + case 'list': // simpleType value list |
|
435 | + $this->xdebug("do nothing for element $name"); |
|
436 | + break; |
|
437 | + case 'restriction': // simpleType, simpleContent or complexContent value restriction |
|
438 | + $this->xdebug('restriction ' . $attrs['base']); |
|
439 | + if($this->currentSimpleType){ |
|
440 | + $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; |
|
441 | + } elseif($this->currentComplexType){ |
|
442 | + $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; |
|
443 | + if(strstr($attrs['base'],':') == ':Array'){ |
|
444 | + $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
|
445 | + } |
|
446 | + } |
|
447 | + break; |
|
448 | + case 'schema': |
|
449 | + $this->schemaInfo = $attrs; |
|
450 | + $this->schemaInfo['schemaVersion'] = $this->getNamespaceFromPrefix($prefix); |
|
451 | + if (isset($attrs['targetNamespace'])) { |
|
452 | + $this->schemaTargetNamespace = $attrs['targetNamespace']; |
|
453 | + } |
|
454 | + if (!isset($attrs['elementFormDefault'])) { |
|
455 | + $this->schemaInfo['elementFormDefault'] = 'unqualified'; |
|
456 | + } |
|
457 | + if (!isset($attrs['attributeFormDefault'])) { |
|
458 | + $this->schemaInfo['attributeFormDefault'] = 'unqualified'; |
|
459 | + } |
|
460 | + break; |
|
461 | + case 'simpleContent': // (optional) content for a complexType |
|
462 | + if ($this->currentComplexType) { // This should *always* be |
|
463 | + $this->complexTypes[$this->currentComplexType]['simpleContent'] = 'true'; |
|
464 | + } else { |
|
465 | + $this->xdebug("do nothing for element $name because there is no current complexType"); |
|
466 | + } |
|
467 | + break; |
|
468 | + case 'simpleType': |
|
469 | + array_push($this->simpleTypeStack, $this->currentSimpleType); |
|
470 | + if(isset($attrs['name'])){ |
|
471 | + $this->xdebug("processing simpleType for name " . $attrs['name']); |
|
472 | + $this->currentSimpleType = $attrs['name']; |
|
473 | + $this->simpleTypes[ $attrs['name'] ] = $attrs; |
|
474 | + $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; |
|
475 | + $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; |
|
476 | + } else { |
|
477 | + $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); |
|
478 | + $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name); |
|
479 | + $this->currentSimpleType = $name; |
|
480 | + //$this->currentElement = false; |
|
481 | + $this->simpleTypes[$this->currentSimpleType] = $attrs; |
|
482 | + $this->simpleTypes[$this->currentSimpleType]['phpType'] = 'scalar'; |
|
483 | + } |
|
484 | + break; |
|
485 | + case 'union': // simpleType type list |
|
486 | + $this->xdebug("do nothing for element $name"); |
|
487 | + break; |
|
488 | + default: |
|
489 | + $this->xdebug("do not have any logic to process element $name"); |
|
490 | + } |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * end-element handler |
|
495 | + * |
|
496 | + * @param string $parser XML parser object |
|
497 | + * @param string $name element name |
|
498 | + * @access private |
|
499 | + */ |
|
500 | + function schemaEndElement($parser, $name) { |
|
501 | + // bring depth down a notch |
|
502 | + $this->depth--; |
|
503 | + // position of current element is equal to the last value left in depth_array for my depth |
|
504 | + if(isset($this->depth_array[$this->depth])){ |
|
505 | + $pos = $this->depth_array[$this->depth]; |
|
506 | + } |
|
507 | + // get element prefix |
|
508 | + if ($prefix = $this->getPrefix($name)){ |
|
509 | + // get unqualified name |
|
510 | + $name = $this->getLocalPart($name); |
|
511 | + } else { |
|
512 | + $prefix = ''; |
|
513 | + } |
|
514 | + // move on... |
|
515 | + if($name == 'complexType'){ |
|
516 | + $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); |
|
517 | + $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); |
|
518 | + $this->currentComplexType = array_pop($this->complexTypeStack); |
|
519 | + //$this->currentElement = false; |
|
520 | + } |
|
521 | + if($name == 'element'){ |
|
522 | + $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)')); |
|
523 | + $this->currentElement = array_pop($this->elementStack); |
|
506 | 524 | } |
507 | - // get element prefix |
|
508 | - if ($prefix = $this->getPrefix($name)){ |
|
509 | - // get unqualified name |
|
510 | - $name = $this->getLocalPart($name); |
|
511 | - } else { |
|
512 | - $prefix = ''; |
|
525 | + if($name == 'simpleType'){ |
|
526 | + $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); |
|
527 | + $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); |
|
528 | + $this->currentSimpleType = array_pop($this->simpleTypeStack); |
|
513 | 529 | } |
514 | - // move on... |
|
515 | - if($name == 'complexType'){ |
|
516 | - $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); |
|
517 | - $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); |
|
518 | - $this->currentComplexType = array_pop($this->complexTypeStack); |
|
519 | - //$this->currentElement = false; |
|
520 | - } |
|
521 | - if($name == 'element'){ |
|
522 | - $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)')); |
|
523 | - $this->currentElement = array_pop($this->elementStack); |
|
524 | - } |
|
525 | - if($name == 'simpleType'){ |
|
526 | - $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); |
|
527 | - $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); |
|
528 | - $this->currentSimpleType = array_pop($this->simpleTypeStack); |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - /** |
|
533 | - * element content handler |
|
534 | - * |
|
535 | - * @param string $parser XML parser object |
|
536 | - * @param string $data element content |
|
537 | - * @access private |
|
538 | - */ |
|
539 | - function schemaCharacterData($parser, $data){ |
|
540 | - $pos = $this->depth_array[$this->depth - 1]; |
|
541 | - $this->message[$pos]['cdata'] .= $data; |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * serialize the schema |
|
546 | - * |
|
547 | - * @access public |
|
548 | - */ |
|
549 | - function serializeSchema(){ |
|
550 | - |
|
551 | - $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); |
|
552 | - $xml = ''; |
|
553 | - // imports |
|
554 | - if (sizeof($this->imports) > 0) { |
|
555 | - foreach($this->imports as $ns => $list) { |
|
556 | - foreach ($list as $ii) { |
|
557 | - if ($ii['location'] != '') { |
|
558 | - $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n"; |
|
559 | - } else { |
|
560 | - $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n"; |
|
561 | - } |
|
562 | - } |
|
563 | - } |
|
564 | - } |
|
565 | - // complex types |
|
566 | - foreach($this->complexTypes as $typeName => $attrs){ |
|
567 | - $contentStr = ''; |
|
568 | - // serialize child elements |
|
569 | - if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){ |
|
570 | - foreach($attrs['elements'] as $element => $eParts){ |
|
571 | - if(isset($eParts['ref'])){ |
|
572 | - $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n"; |
|
573 | - } else { |
|
574 | - $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\""; |
|
575 | - foreach ($eParts as $aName => $aValue) { |
|
576 | - // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable |
|
577 | - if ($aName != 'name' && $aName != 'type') { |
|
578 | - $contentStr .= " $aName=\"$aValue\""; |
|
579 | - } |
|
580 | - } |
|
581 | - $contentStr .= "/>\n"; |
|
582 | - } |
|
583 | - } |
|
584 | - // compositor wraps elements |
|
585 | - if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) { |
|
586 | - $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n"; |
|
587 | - } |
|
588 | - } |
|
589 | - // attributes |
|
590 | - if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){ |
|
591 | - foreach($attrs['attrs'] as $attr => $aParts){ |
|
592 | - $contentStr .= " <$schemaPrefix:attribute"; |
|
593 | - foreach ($aParts as $a => $v) { |
|
594 | - if ($a == 'ref' || $a == 'type') { |
|
595 | - $contentStr .= " $a=\"".$this->contractQName($v).'"'; |
|
596 | - } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') { |
|
597 | - $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl']; |
|
598 | - $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"'; |
|
599 | - } else { |
|
600 | - $contentStr .= " $a=\"$v\""; |
|
601 | - } |
|
602 | - } |
|
603 | - $contentStr .= "/>\n"; |
|
604 | - } |
|
605 | - } |
|
606 | - // if restriction |
|
607 | - if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){ |
|
608 | - $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n"; |
|
609 | - // complex or simple content |
|
610 | - if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){ |
|
611 | - $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n"; |
|
612 | - } |
|
613 | - } |
|
614 | - // finalize complex type |
|
615 | - if($contentStr != ''){ |
|
616 | - $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n"; |
|
617 | - } else { |
|
618 | - $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n"; |
|
619 | - } |
|
620 | - $xml .= $contentStr; |
|
621 | - } |
|
622 | - // simple types |
|
623 | - if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){ |
|
624 | - foreach($this->simpleTypes as $typeName => $eParts){ |
|
625 | - $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n"; |
|
626 | - if (isset($eParts['enumeration'])) { |
|
627 | - foreach ($eParts['enumeration'] as $e) { |
|
628 | - $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n"; |
|
629 | - } |
|
630 | - } |
|
631 | - $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>"; |
|
632 | - } |
|
633 | - } |
|
634 | - // elements |
|
635 | - if(isset($this->elements) && count($this->elements) > 0){ |
|
636 | - foreach($this->elements as $element => $eParts){ |
|
637 | - $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n"; |
|
638 | - } |
|
639 | - } |
|
640 | - // attributes |
|
641 | - if(isset($this->attributes) && count($this->attributes) > 0){ |
|
642 | - foreach($this->attributes as $attr => $aParts){ |
|
643 | - $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>"; |
|
644 | - } |
|
645 | - } |
|
646 | - // finish 'er up |
|
647 | - $attr = ''; |
|
648 | - foreach ($this->schemaInfo as $k => $v) { |
|
649 | - if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') { |
|
650 | - $attr .= " $k=\"$v\""; |
|
651 | - } |
|
652 | - } |
|
653 | - $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n"; |
|
654 | - foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) { |
|
655 | - $el .= " xmlns:$nsp=\"$ns\""; |
|
656 | - } |
|
657 | - $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n"; |
|
658 | - return $xml; |
|
659 | - } |
|
660 | - |
|
661 | - /** |
|
662 | - * adds debug data to the clas level debug string |
|
663 | - * |
|
664 | - * @param string $string debug data |
|
665 | - * @access private |
|
666 | - */ |
|
667 | - function xdebug($string){ |
|
668 | - $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); |
|
669 | - } |
|
530 | + } |
|
531 | + |
|
532 | + /** |
|
533 | + * element content handler |
|
534 | + * |
|
535 | + * @param string $parser XML parser object |
|
536 | + * @param string $data element content |
|
537 | + * @access private |
|
538 | + */ |
|
539 | + function schemaCharacterData($parser, $data){ |
|
540 | + $pos = $this->depth_array[$this->depth - 1]; |
|
541 | + $this->message[$pos]['cdata'] .= $data; |
|
542 | + } |
|
670 | 543 | |
671 | 544 | /** |
672 | - * get the PHP type of a user defined type in the schema |
|
673 | - * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays |
|
674 | - * returns false if no type exists, or not w/ the given namespace |
|
675 | - * else returns a string that is either a native php type, or 'struct' |
|
676 | - * |
|
677 | - * @param string $type name of defined type |
|
678 | - * @param string $ns namespace of type |
|
679 | - * @return mixed |
|
680 | - * @access public |
|
681 | - * @deprecated |
|
682 | - */ |
|
683 | - function getPHPType($type,$ns){ |
|
684 | - if(isset($this->typemap[$ns][$type])){ |
|
685 | - //print "found type '$type' and ns $ns in typemap<br>"; |
|
686 | - return $this->typemap[$ns][$type]; |
|
687 | - } elseif(isset($this->complexTypes[$type])){ |
|
688 | - //print "getting type '$type' and ns $ns from complexTypes array<br>"; |
|
689 | - return $this->complexTypes[$type]['phpType']; |
|
690 | - } |
|
691 | - return false; |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * returns an associative array of information about a given type |
|
696 | - * returns false if no type exists by the given name |
|
697 | - * |
|
698 | - * For a complexType typeDef = array( |
|
699 | - * 'restrictionBase' => '', |
|
700 | - * 'phpType' => '', |
|
701 | - * 'compositor' => '(sequence|all)', |
|
702 | - * 'elements' => array(), // refs to elements array |
|
703 | - * 'attrs' => array() // refs to attributes array |
|
704 | - * ... and so on (see addComplexType) |
|
705 | - * ) |
|
706 | - * |
|
707 | - * For simpleType or element, the array has different keys. |
|
708 | - * |
|
709 | - * @param string $type |
|
710 | - * @return mixed |
|
711 | - * @access public |
|
712 | - * @see addComplexType |
|
713 | - * @see addSimpleType |
|
714 | - * @see addElement |
|
715 | - */ |
|
716 | - function getTypeDef($type){ |
|
717 | - //$this->debug("in getTypeDef for type $type"); |
|
718 | - if (substr($type, -1) == '^') { |
|
719 | - $is_element = 1; |
|
720 | - $type = substr($type, 0, -1); |
|
721 | - } else { |
|
722 | - $is_element = 0; |
|
723 | - } |
|
724 | - |
|
725 | - if((! $is_element) && isset($this->complexTypes[$type])){ |
|
726 | - $this->xdebug("in getTypeDef, found complexType $type"); |
|
727 | - return $this->complexTypes[$type]; |
|
728 | - } elseif((! $is_element) && isset($this->simpleTypes[$type])){ |
|
729 | - $this->xdebug("in getTypeDef, found simpleType $type"); |
|
730 | - if (!isset($this->simpleTypes[$type]['phpType'])) { |
|
731 | - // get info for type to tack onto the simple type |
|
732 | - // TODO: can this ever really apply (i.e. what is a simpleType really?) |
|
733 | - $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1); |
|
734 | - $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':')); |
|
735 | - $etype = $this->getTypeDef($uqType); |
|
736 | - if ($etype) { |
|
737 | - $this->xdebug("in getTypeDef, found type for simpleType $type:"); |
|
738 | - $this->xdebug($this->varDump($etype)); |
|
739 | - if (isset($etype['phpType'])) { |
|
740 | - $this->simpleTypes[$type]['phpType'] = $etype['phpType']; |
|
741 | - } |
|
742 | - if (isset($etype['elements'])) { |
|
743 | - $this->simpleTypes[$type]['elements'] = $etype['elements']; |
|
744 | - } |
|
745 | - } |
|
746 | - } |
|
747 | - return $this->simpleTypes[$type]; |
|
748 | - } elseif(isset($this->elements[$type])){ |
|
749 | - $this->xdebug("in getTypeDef, found element $type"); |
|
750 | - if (!isset($this->elements[$type]['phpType'])) { |
|
751 | - // get info for type to tack onto the element |
|
752 | - $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1); |
|
753 | - $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':')); |
|
754 | - $etype = $this->getTypeDef($uqType); |
|
755 | - if ($etype) { |
|
756 | - $this->xdebug("in getTypeDef, found type for element $type:"); |
|
757 | - $this->xdebug($this->varDump($etype)); |
|
758 | - if (isset($etype['phpType'])) { |
|
759 | - $this->elements[$type]['phpType'] = $etype['phpType']; |
|
760 | - } |
|
761 | - if (isset($etype['elements'])) { |
|
762 | - $this->elements[$type]['elements'] = $etype['elements']; |
|
763 | - } |
|
764 | - if (isset($etype['extensionBase'])) { |
|
765 | - $this->elements[$type]['extensionBase'] = $etype['extensionBase']; |
|
766 | - } |
|
767 | - } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') { |
|
768 | - $this->xdebug("in getTypeDef, element $type is an XSD type"); |
|
769 | - $this->elements[$type]['phpType'] = 'scalar'; |
|
770 | - } |
|
771 | - } |
|
772 | - return $this->elements[$type]; |
|
773 | - } elseif(isset($this->attributes[$type])){ |
|
774 | - $this->xdebug("in getTypeDef, found attribute $type"); |
|
775 | - return $this->attributes[$type]; |
|
776 | - } elseif (preg_match('/_ContainedType$/', $type)) { |
|
777 | - $this->xdebug("in getTypeDef, have an untyped element $type"); |
|
778 | - $typeDef['typeClass'] = 'simpleType'; |
|
779 | - $typeDef['phpType'] = 'scalar'; |
|
780 | - $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string'; |
|
781 | - return $typeDef; |
|
782 | - } |
|
783 | - $this->xdebug("in getTypeDef, did not find $type"); |
|
784 | - return false; |
|
785 | - } |
|
786 | - |
|
787 | - /** |
|
788 | - * returns a sample serialization of a given type, or false if no type by the given name |
|
789 | - * |
|
790 | - * @param string $type name of type |
|
791 | - * @return mixed |
|
792 | - * @access public |
|
793 | - * @deprecated |
|
794 | - */ |
|
545 | + * serialize the schema |
|
546 | + * |
|
547 | + * @access public |
|
548 | + */ |
|
549 | + function serializeSchema(){ |
|
550 | + |
|
551 | + $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); |
|
552 | + $xml = ''; |
|
553 | + // imports |
|
554 | + if (sizeof($this->imports) > 0) { |
|
555 | + foreach($this->imports as $ns => $list) { |
|
556 | + foreach ($list as $ii) { |
|
557 | + if ($ii['location'] != '') { |
|
558 | + $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n"; |
|
559 | + } else { |
|
560 | + $xml .= " <$schemaPrefix:import namespace=\"" . $ns . "\" />\n"; |
|
561 | + } |
|
562 | + } |
|
563 | + } |
|
564 | + } |
|
565 | + // complex types |
|
566 | + foreach($this->complexTypes as $typeName => $attrs){ |
|
567 | + $contentStr = ''; |
|
568 | + // serialize child elements |
|
569 | + if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){ |
|
570 | + foreach($attrs['elements'] as $element => $eParts){ |
|
571 | + if(isset($eParts['ref'])){ |
|
572 | + $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n"; |
|
573 | + } else { |
|
574 | + $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\""; |
|
575 | + foreach ($eParts as $aName => $aValue) { |
|
576 | + // handle, e.g., abstract, default, form, minOccurs, maxOccurs, nillable |
|
577 | + if ($aName != 'name' && $aName != 'type') { |
|
578 | + $contentStr .= " $aName=\"$aValue\""; |
|
579 | + } |
|
580 | + } |
|
581 | + $contentStr .= "/>\n"; |
|
582 | + } |
|
583 | + } |
|
584 | + // compositor wraps elements |
|
585 | + if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) { |
|
586 | + $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n"; |
|
587 | + } |
|
588 | + } |
|
589 | + // attributes |
|
590 | + if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){ |
|
591 | + foreach($attrs['attrs'] as $attr => $aParts){ |
|
592 | + $contentStr .= " <$schemaPrefix:attribute"; |
|
593 | + foreach ($aParts as $a => $v) { |
|
594 | + if ($a == 'ref' || $a == 'type') { |
|
595 | + $contentStr .= " $a=\"".$this->contractQName($v).'"'; |
|
596 | + } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') { |
|
597 | + $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl']; |
|
598 | + $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"'; |
|
599 | + } else { |
|
600 | + $contentStr .= " $a=\"$v\""; |
|
601 | + } |
|
602 | + } |
|
603 | + $contentStr .= "/>\n"; |
|
604 | + } |
|
605 | + } |
|
606 | + // if restriction |
|
607 | + if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){ |
|
608 | + $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n"; |
|
609 | + // complex or simple content |
|
610 | + if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){ |
|
611 | + $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n"; |
|
612 | + } |
|
613 | + } |
|
614 | + // finalize complex type |
|
615 | + if($contentStr != ''){ |
|
616 | + $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n"; |
|
617 | + } else { |
|
618 | + $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n"; |
|
619 | + } |
|
620 | + $xml .= $contentStr; |
|
621 | + } |
|
622 | + // simple types |
|
623 | + if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){ |
|
624 | + foreach($this->simpleTypes as $typeName => $eParts){ |
|
625 | + $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n"; |
|
626 | + if (isset($eParts['enumeration'])) { |
|
627 | + foreach ($eParts['enumeration'] as $e) { |
|
628 | + $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n"; |
|
629 | + } |
|
630 | + } |
|
631 | + $xml .= " </$schemaPrefix:restriction>\n </$schemaPrefix:simpleType>"; |
|
632 | + } |
|
633 | + } |
|
634 | + // elements |
|
635 | + if(isset($this->elements) && count($this->elements) > 0){ |
|
636 | + foreach($this->elements as $element => $eParts){ |
|
637 | + $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n"; |
|
638 | + } |
|
639 | + } |
|
640 | + // attributes |
|
641 | + if(isset($this->attributes) && count($this->attributes) > 0){ |
|
642 | + foreach($this->attributes as $attr => $aParts){ |
|
643 | + $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>"; |
|
644 | + } |
|
645 | + } |
|
646 | + // finish 'er up |
|
647 | + $attr = ''; |
|
648 | + foreach ($this->schemaInfo as $k => $v) { |
|
649 | + if ($k == 'elementFormDefault' || $k == 'attributeFormDefault') { |
|
650 | + $attr .= " $k=\"$v\""; |
|
651 | + } |
|
652 | + } |
|
653 | + $el = "<$schemaPrefix:schema$attr targetNamespace=\"$this->schemaTargetNamespace\"\n"; |
|
654 | + foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) { |
|
655 | + $el .= " xmlns:$nsp=\"$ns\""; |
|
656 | + } |
|
657 | + $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n"; |
|
658 | + return $xml; |
|
659 | + } |
|
660 | + |
|
661 | + /** |
|
662 | + * adds debug data to the clas level debug string |
|
663 | + * |
|
664 | + * @param string $string debug data |
|
665 | + * @access private |
|
666 | + */ |
|
667 | + function xdebug($string){ |
|
668 | + $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * get the PHP type of a user defined type in the schema |
|
673 | + * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays |
|
674 | + * returns false if no type exists, or not w/ the given namespace |
|
675 | + * else returns a string that is either a native php type, or 'struct' |
|
676 | + * |
|
677 | + * @param string $type name of defined type |
|
678 | + * @param string $ns namespace of type |
|
679 | + * @return mixed |
|
680 | + * @access public |
|
681 | + * @deprecated |
|
682 | + */ |
|
683 | + function getPHPType($type,$ns){ |
|
684 | + if(isset($this->typemap[$ns][$type])){ |
|
685 | + //print "found type '$type' and ns $ns in typemap<br>"; |
|
686 | + return $this->typemap[$ns][$type]; |
|
687 | + } elseif(isset($this->complexTypes[$type])){ |
|
688 | + //print "getting type '$type' and ns $ns from complexTypes array<br>"; |
|
689 | + return $this->complexTypes[$type]['phpType']; |
|
690 | + } |
|
691 | + return false; |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * returns an associative array of information about a given type |
|
696 | + * returns false if no type exists by the given name |
|
697 | + * |
|
698 | + * For a complexType typeDef = array( |
|
699 | + * 'restrictionBase' => '', |
|
700 | + * 'phpType' => '', |
|
701 | + * 'compositor' => '(sequence|all)', |
|
702 | + * 'elements' => array(), // refs to elements array |
|
703 | + * 'attrs' => array() // refs to attributes array |
|
704 | + * ... and so on (see addComplexType) |
|
705 | + * ) |
|
706 | + * |
|
707 | + * For simpleType or element, the array has different keys. |
|
708 | + * |
|
709 | + * @param string $type |
|
710 | + * @return mixed |
|
711 | + * @access public |
|
712 | + * @see addComplexType |
|
713 | + * @see addSimpleType |
|
714 | + * @see addElement |
|
715 | + */ |
|
716 | + function getTypeDef($type){ |
|
717 | + //$this->debug("in getTypeDef for type $type"); |
|
718 | + if (substr($type, -1) == '^') { |
|
719 | + $is_element = 1; |
|
720 | + $type = substr($type, 0, -1); |
|
721 | + } else { |
|
722 | + $is_element = 0; |
|
723 | + } |
|
724 | + |
|
725 | + if((! $is_element) && isset($this->complexTypes[$type])){ |
|
726 | + $this->xdebug("in getTypeDef, found complexType $type"); |
|
727 | + return $this->complexTypes[$type]; |
|
728 | + } elseif((! $is_element) && isset($this->simpleTypes[$type])){ |
|
729 | + $this->xdebug("in getTypeDef, found simpleType $type"); |
|
730 | + if (!isset($this->simpleTypes[$type]['phpType'])) { |
|
731 | + // get info for type to tack onto the simple type |
|
732 | + // TODO: can this ever really apply (i.e. what is a simpleType really?) |
|
733 | + $uqType = substr($this->simpleTypes[$type]['type'], strrpos($this->simpleTypes[$type]['type'], ':') + 1); |
|
734 | + $ns = substr($this->simpleTypes[$type]['type'], 0, strrpos($this->simpleTypes[$type]['type'], ':')); |
|
735 | + $etype = $this->getTypeDef($uqType); |
|
736 | + if ($etype) { |
|
737 | + $this->xdebug("in getTypeDef, found type for simpleType $type:"); |
|
738 | + $this->xdebug($this->varDump($etype)); |
|
739 | + if (isset($etype['phpType'])) { |
|
740 | + $this->simpleTypes[$type]['phpType'] = $etype['phpType']; |
|
741 | + } |
|
742 | + if (isset($etype['elements'])) { |
|
743 | + $this->simpleTypes[$type]['elements'] = $etype['elements']; |
|
744 | + } |
|
745 | + } |
|
746 | + } |
|
747 | + return $this->simpleTypes[$type]; |
|
748 | + } elseif(isset($this->elements[$type])){ |
|
749 | + $this->xdebug("in getTypeDef, found element $type"); |
|
750 | + if (!isset($this->elements[$type]['phpType'])) { |
|
751 | + // get info for type to tack onto the element |
|
752 | + $uqType = substr($this->elements[$type]['type'], strrpos($this->elements[$type]['type'], ':') + 1); |
|
753 | + $ns = substr($this->elements[$type]['type'], 0, strrpos($this->elements[$type]['type'], ':')); |
|
754 | + $etype = $this->getTypeDef($uqType); |
|
755 | + if ($etype) { |
|
756 | + $this->xdebug("in getTypeDef, found type for element $type:"); |
|
757 | + $this->xdebug($this->varDump($etype)); |
|
758 | + if (isset($etype['phpType'])) { |
|
759 | + $this->elements[$type]['phpType'] = $etype['phpType']; |
|
760 | + } |
|
761 | + if (isset($etype['elements'])) { |
|
762 | + $this->elements[$type]['elements'] = $etype['elements']; |
|
763 | + } |
|
764 | + if (isset($etype['extensionBase'])) { |
|
765 | + $this->elements[$type]['extensionBase'] = $etype['extensionBase']; |
|
766 | + } |
|
767 | + } elseif ($ns == 'http://www.w3.org/2001/XMLSchema') { |
|
768 | + $this->xdebug("in getTypeDef, element $type is an XSD type"); |
|
769 | + $this->elements[$type]['phpType'] = 'scalar'; |
|
770 | + } |
|
771 | + } |
|
772 | + return $this->elements[$type]; |
|
773 | + } elseif(isset($this->attributes[$type])){ |
|
774 | + $this->xdebug("in getTypeDef, found attribute $type"); |
|
775 | + return $this->attributes[$type]; |
|
776 | + } elseif (preg_match('/_ContainedType$/', $type)) { |
|
777 | + $this->xdebug("in getTypeDef, have an untyped element $type"); |
|
778 | + $typeDef['typeClass'] = 'simpleType'; |
|
779 | + $typeDef['phpType'] = 'scalar'; |
|
780 | + $typeDef['type'] = 'http://www.w3.org/2001/XMLSchema:string'; |
|
781 | + return $typeDef; |
|
782 | + } |
|
783 | + $this->xdebug("in getTypeDef, did not find $type"); |
|
784 | + return false; |
|
785 | + } |
|
786 | + |
|
787 | + /** |
|
788 | + * returns a sample serialization of a given type, or false if no type by the given name |
|
789 | + * |
|
790 | + * @param string $type name of type |
|
791 | + * @return mixed |
|
792 | + * @access public |
|
793 | + * @deprecated |
|
794 | + */ |
|
795 | 795 | function serializeTypeDef($type){ |
796 | - //print "in sTD() for type $type<br>"; |
|
797 | - if($typeDef = $this->getTypeDef($type)){ |
|
798 | - $str .= '<'.$type; |
|
799 | - if(is_array($typeDef['attrs'])){ |
|
800 | - foreach($typeDef['attrs'] as $attName => $data){ |
|
801 | - $str .= " $attName=\"{type = ".$data['type']."}\""; |
|
802 | - } |
|
803 | - } |
|
804 | - $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; |
|
805 | - if(count($typeDef['elements']) > 0){ |
|
806 | - $str .= ">"; |
|
807 | - foreach($typeDef['elements'] as $element => $eData){ |
|
808 | - $str .= $this->serializeTypeDef($element); |
|
809 | - } |
|
810 | - $str .= "</$type>"; |
|
811 | - } elseif($typeDef['typeClass'] == 'element') { |
|
812 | - $str .= "></$type>"; |
|
813 | - } else { |
|
814 | - $str .= "/>"; |
|
815 | - } |
|
816 | - return $str; |
|
817 | - } |
|
818 | - return false; |
|
796 | + //print "in sTD() for type $type<br>"; |
|
797 | + if($typeDef = $this->getTypeDef($type)){ |
|
798 | + $str .= '<'.$type; |
|
799 | + if(is_array($typeDef['attrs'])){ |
|
800 | + foreach($typeDef['attrs'] as $attName => $data){ |
|
801 | + $str .= " $attName=\"{type = ".$data['type']."}\""; |
|
802 | + } |
|
803 | + } |
|
804 | + $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; |
|
805 | + if(count($typeDef['elements']) > 0){ |
|
806 | + $str .= ">"; |
|
807 | + foreach($typeDef['elements'] as $element => $eData){ |
|
808 | + $str .= $this->serializeTypeDef($element); |
|
809 | + } |
|
810 | + $str .= "</$type>"; |
|
811 | + } elseif($typeDef['typeClass'] == 'element') { |
|
812 | + $str .= "></$type>"; |
|
813 | + } else { |
|
814 | + $str .= "/>"; |
|
815 | + } |
|
816 | + return $str; |
|
817 | + } |
|
818 | + return false; |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /** |
822 | - * returns HTML form elements that allow a user |
|
823 | - * to enter values for creating an instance of the given type. |
|
824 | - * |
|
825 | - * @param string $name name for type instance |
|
826 | - * @param string $type name of type |
|
827 | - * @return string |
|
828 | - * @access public |
|
829 | - * @deprecated |
|
830 | - */ |
|
831 | - function typeToForm($name,$type){ |
|
832 | - // get typedef |
|
833 | - if($typeDef = $this->getTypeDef($type)){ |
|
834 | - // if struct |
|
835 | - if($typeDef['phpType'] == 'struct'){ |
|
836 | - $buffer .= '<table>'; |
|
837 | - foreach($typeDef['elements'] as $child => $childDef){ |
|
838 | - $buffer .= " |
|
822 | + * returns HTML form elements that allow a user |
|
823 | + * to enter values for creating an instance of the given type. |
|
824 | + * |
|
825 | + * @param string $name name for type instance |
|
826 | + * @param string $type name of type |
|
827 | + * @return string |
|
828 | + * @access public |
|
829 | + * @deprecated |
|
830 | + */ |
|
831 | + function typeToForm($name,$type){ |
|
832 | + // get typedef |
|
833 | + if($typeDef = $this->getTypeDef($type)){ |
|
834 | + // if struct |
|
835 | + if($typeDef['phpType'] == 'struct'){ |
|
836 | + $buffer .= '<table>'; |
|
837 | + foreach($typeDef['elements'] as $child => $childDef){ |
|
838 | + $buffer .= " |
|
839 | 839 | <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td> |
840 | 840 | <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>"; |
841 | - } |
|
842 | - $buffer .= '</table>'; |
|
843 | - // if array |
|
844 | - } elseif($typeDef['phpType'] == 'array'){ |
|
845 | - $buffer .= '<table>'; |
|
846 | - for($i=0;$i < 3; $i++){ |
|
847 | - $buffer .= " |
|
841 | + } |
|
842 | + $buffer .= '</table>'; |
|
843 | + // if array |
|
844 | + } elseif($typeDef['phpType'] == 'array'){ |
|
845 | + $buffer .= '<table>'; |
|
846 | + for($i=0;$i < 3; $i++){ |
|
847 | + $buffer .= " |
|
848 | 848 | <tr><td align='right'>array item (type: $typeDef[arrayType]):</td> |
849 | 849 | <td><input type='text' name='parameters[".$name."][]'></td></tr>"; |
850 | - } |
|
851 | - $buffer .= '</table>'; |
|
852 | - // if scalar |
|
853 | - } else { |
|
854 | - $buffer .= "<input type='text' name='parameters[$name]'>"; |
|
855 | - } |
|
856 | - } else { |
|
857 | - $buffer .= "<input type='text' name='parameters[$name]'>"; |
|
858 | - } |
|
859 | - return $buffer; |
|
860 | - } |
|
861 | - |
|
862 | - /** |
|
863 | - * adds a complex type to the schema |
|
864 | - * |
|
865 | - * example: array |
|
866 | - * |
|
867 | - * addType( |
|
868 | - * 'ArrayOfstring', |
|
869 | - * 'complexType', |
|
870 | - * 'array', |
|
871 | - * '', |
|
872 | - * 'SOAP-ENC:Array', |
|
873 | - * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), |
|
874 | - * 'xsd:string' |
|
875 | - * ); |
|
876 | - * |
|
877 | - * example: PHP associative array ( SOAP Struct ) |
|
878 | - * |
|
879 | - * addType( |
|
880 | - * 'SOAPStruct', |
|
881 | - * 'complexType', |
|
882 | - * 'struct', |
|
883 | - * 'all', |
|
884 | - * array('myVar'=> array('name'=>'myVar','type'=>'string') |
|
885 | - * ); |
|
886 | - * |
|
887 | - * @param name |
|
888 | - * @param typeClass (complexType|simpleType|attribute) |
|
889 | - * @param phpType: currently supported are array and struct (php assoc array) |
|
890 | - * @param compositor (all|sequence|choice) |
|
891 | - * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
892 | - * @param elements = array ( name = array(name=>'',type=>'') ) |
|
893 | - * @param attrs = array( |
|
894 | - * array( |
|
895 | - * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", |
|
896 | - * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" |
|
897 | - * ) |
|
898 | - * ) |
|
899 | - * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) |
|
900 | - * @access public |
|
901 | - * @see getTypeDef |
|
902 | - */ |
|
903 | - function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ |
|
904 | - $this->complexTypes[$name] = array( |
|
905 | - 'name' => $name, |
|
906 | - 'typeClass' => $typeClass, |
|
907 | - 'phpType' => $phpType, |
|
908 | - 'compositor'=> $compositor, |
|
909 | - 'restrictionBase' => $restrictionBase, |
|
910 | - 'elements' => $elements, |
|
911 | - 'attrs' => $attrs, |
|
912 | - 'arrayType' => $arrayType |
|
913 | - ); |
|
914 | - |
|
915 | - $this->xdebug("addComplexType $name:"); |
|
916 | - $this->appendDebug($this->varDump($this->complexTypes[$name])); |
|
917 | - } |
|
918 | - |
|
919 | - /** |
|
920 | - * adds a simple type to the schema |
|
921 | - * |
|
922 | - * @param string $name |
|
923 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
924 | - * @param string $typeClass (should always be simpleType) |
|
925 | - * @param string $phpType (should always be scalar) |
|
926 | - * @param array $enumeration array of values |
|
927 | - * @access public |
|
928 | - * @see nusoap_xmlschema |
|
929 | - * @see getTypeDef |
|
930 | - */ |
|
931 | - function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
932 | - $this->simpleTypes[$name] = array( |
|
933 | - 'name' => $name, |
|
934 | - 'typeClass' => $typeClass, |
|
935 | - 'phpType' => $phpType, |
|
936 | - 'type' => $restrictionBase, |
|
937 | - 'enumeration' => $enumeration |
|
938 | - ); |
|
939 | - |
|
940 | - $this->xdebug("addSimpleType $name:"); |
|
941 | - $this->appendDebug($this->varDump($this->simpleTypes[$name])); |
|
942 | - } |
|
943 | - |
|
944 | - /** |
|
945 | - * adds an element to the schema |
|
946 | - * |
|
947 | - * @param array $attrs attributes that must include name and type |
|
948 | - * @see nusoap_xmlschema |
|
949 | - * @access public |
|
950 | - */ |
|
951 | - function addElement($attrs) { |
|
952 | - if (! $this->getPrefix($attrs['type'])) { |
|
953 | - $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; |
|
954 | - } |
|
955 | - $this->elements[ $attrs['name'] ] = $attrs; |
|
956 | - $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
957 | - |
|
958 | - $this->xdebug("addElement " . $attrs['name']); |
|
959 | - $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ])); |
|
960 | - } |
|
850 | + } |
|
851 | + $buffer .= '</table>'; |
|
852 | + // if scalar |
|
853 | + } else { |
|
854 | + $buffer .= "<input type='text' name='parameters[$name]'>"; |
|
855 | + } |
|
856 | + } else { |
|
857 | + $buffer .= "<input type='text' name='parameters[$name]'>"; |
|
858 | + } |
|
859 | + return $buffer; |
|
860 | + } |
|
861 | + |
|
862 | + /** |
|
863 | + * adds a complex type to the schema |
|
864 | + * |
|
865 | + * example: array |
|
866 | + * |
|
867 | + * addType( |
|
868 | + * 'ArrayOfstring', |
|
869 | + * 'complexType', |
|
870 | + * 'array', |
|
871 | + * '', |
|
872 | + * 'SOAP-ENC:Array', |
|
873 | + * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), |
|
874 | + * 'xsd:string' |
|
875 | + * ); |
|
876 | + * |
|
877 | + * example: PHP associative array ( SOAP Struct ) |
|
878 | + * |
|
879 | + * addType( |
|
880 | + * 'SOAPStruct', |
|
881 | + * 'complexType', |
|
882 | + * 'struct', |
|
883 | + * 'all', |
|
884 | + * array('myVar'=> array('name'=>'myVar','type'=>'string') |
|
885 | + * ); |
|
886 | + * |
|
887 | + * @param name |
|
888 | + * @param typeClass (complexType|simpleType|attribute) |
|
889 | + * @param phpType: currently supported are array and struct (php assoc array) |
|
890 | + * @param compositor (all|sequence|choice) |
|
891 | + * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
892 | + * @param elements = array ( name = array(name=>'',type=>'') ) |
|
893 | + * @param attrs = array( |
|
894 | + * array( |
|
895 | + * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", |
|
896 | + * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" |
|
897 | + * ) |
|
898 | + * ) |
|
899 | + * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) |
|
900 | + * @access public |
|
901 | + * @see getTypeDef |
|
902 | + */ |
|
903 | + function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ |
|
904 | + $this->complexTypes[$name] = array( |
|
905 | + 'name' => $name, |
|
906 | + 'typeClass' => $typeClass, |
|
907 | + 'phpType' => $phpType, |
|
908 | + 'compositor'=> $compositor, |
|
909 | + 'restrictionBase' => $restrictionBase, |
|
910 | + 'elements' => $elements, |
|
911 | + 'attrs' => $attrs, |
|
912 | + 'arrayType' => $arrayType |
|
913 | + ); |
|
914 | + |
|
915 | + $this->xdebug("addComplexType $name:"); |
|
916 | + $this->appendDebug($this->varDump($this->complexTypes[$name])); |
|
917 | + } |
|
918 | + |
|
919 | + /** |
|
920 | + * adds a simple type to the schema |
|
921 | + * |
|
922 | + * @param string $name |
|
923 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
924 | + * @param string $typeClass (should always be simpleType) |
|
925 | + * @param string $phpType (should always be scalar) |
|
926 | + * @param array $enumeration array of values |
|
927 | + * @access public |
|
928 | + * @see nusoap_xmlschema |
|
929 | + * @see getTypeDef |
|
930 | + */ |
|
931 | + function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
932 | + $this->simpleTypes[$name] = array( |
|
933 | + 'name' => $name, |
|
934 | + 'typeClass' => $typeClass, |
|
935 | + 'phpType' => $phpType, |
|
936 | + 'type' => $restrictionBase, |
|
937 | + 'enumeration' => $enumeration |
|
938 | + ); |
|
939 | + |
|
940 | + $this->xdebug("addSimpleType $name:"); |
|
941 | + $this->appendDebug($this->varDump($this->simpleTypes[$name])); |
|
942 | + } |
|
943 | + |
|
944 | + /** |
|
945 | + * adds an element to the schema |
|
946 | + * |
|
947 | + * @param array $attrs attributes that must include name and type |
|
948 | + * @see nusoap_xmlschema |
|
949 | + * @access public |
|
950 | + */ |
|
951 | + function addElement($attrs) { |
|
952 | + if (! $this->getPrefix($attrs['type'])) { |
|
953 | + $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; |
|
954 | + } |
|
955 | + $this->elements[ $attrs['name'] ] = $attrs; |
|
956 | + $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
957 | + |
|
958 | + $this->xdebug("addElement " . $attrs['name']); |
|
959 | + $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ])); |
|
960 | + } |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | /** |
@@ -52,224 +52,224 @@ discard block |
||
52 | 52 | * @access public |
53 | 53 | */ |
54 | 54 | class nusoap_client_mime extends nusoap_client { |
55 | - /** |
|
56 | - * @var array Each array element in the return is an associative array with keys |
|
57 | - * data, filename, contenttype, cid |
|
58 | - * @access private |
|
59 | - */ |
|
60 | - var $requestAttachments = array(); |
|
61 | - /** |
|
62 | - * @var array Each array element in the return is an associative array with keys |
|
63 | - * data, filename, contenttype, cid |
|
64 | - * @access private |
|
65 | - */ |
|
66 | - var $responseAttachments; |
|
67 | - /** |
|
68 | - * @var string |
|
69 | - * @access private |
|
70 | - */ |
|
71 | - var $mimeContentType; |
|
72 | - |
|
73 | - /** |
|
74 | - * adds a MIME attachment to the current request. |
|
75 | - * |
|
76 | - * If the $data parameter contains an empty string, this method will read |
|
77 | - * the contents of the file named by the $filename parameter. |
|
78 | - * |
|
79 | - * If the $cid parameter is false, this method will generate the cid. |
|
80 | - * |
|
81 | - * @param string $data The data of the attachment |
|
82 | - * @param string $filename The filename of the attachment (default is empty string) |
|
83 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
84 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
85 | - * @return string The content-id (cid) of the attachment |
|
86 | - * @access public |
|
87 | - */ |
|
88 | - function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
89 | - if (! $cid) { |
|
90 | - $cid = md5(uniqid(time())); |
|
91 | - } |
|
92 | - |
|
93 | - $info['data'] = $data; |
|
94 | - $info['filename'] = $filename; |
|
95 | - $info['contenttype'] = $contenttype; |
|
96 | - $info['cid'] = $cid; |
|
97 | - |
|
98 | - $this->requestAttachments[] = $info; |
|
99 | - |
|
100 | - return $cid; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * clears the MIME attachments for the current request. |
|
105 | - * |
|
106 | - * @access public |
|
107 | - */ |
|
108 | - function clearAttachments() { |
|
109 | - $this->requestAttachments = array(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * gets the MIME attachments from the current response. |
|
114 | - * |
|
115 | - * Each array element in the return is an associative array with keys |
|
116 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
117 | - * for addAttachment. |
|
118 | - * |
|
119 | - * @return array The attachments. |
|
120 | - * @access public |
|
121 | - */ |
|
122 | - function getAttachments() { |
|
123 | - return $this->responseAttachments; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * gets the HTTP body for the current request. |
|
128 | - * |
|
129 | - * @param string $soapmsg The SOAP payload |
|
130 | - * @return string The HTTP body, which includes the SOAP payload |
|
131 | - * @access private |
|
132 | - */ |
|
133 | - function getHTTPBody($soapmsg) { |
|
134 | - if (count($this->requestAttachments) > 0) { |
|
135 | - $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
136 | - $mimeMessage = new Mail_mimePart('', $params); |
|
137 | - unset($params); |
|
138 | - |
|
139 | - $params['content_type'] = 'text/xml'; |
|
140 | - $params['encoding'] = '8bit'; |
|
141 | - $params['charset'] = $this->soap_defencoding; |
|
142 | - $mimeMessage->addSubpart($soapmsg, $params); |
|
143 | - |
|
144 | - foreach ($this->requestAttachments as $att) { |
|
145 | - unset($params); |
|
146 | - |
|
147 | - $params['content_type'] = $att['contenttype']; |
|
148 | - $params['encoding'] = 'base64'; |
|
149 | - $params['disposition'] = 'attachment'; |
|
150 | - $params['dfilename'] = $att['filename']; |
|
151 | - $params['cid'] = $att['cid']; |
|
152 | - |
|
153 | - if ($att['data'] == '' && $att['filename'] <> '') { |
|
154 | - if ($fd = fopen($att['filename'], 'rb')) { |
|
155 | - $data = fread($fd, filesize($att['filename'])); |
|
156 | - fclose($fd); |
|
157 | - } else { |
|
158 | - $data = ''; |
|
159 | - } |
|
160 | - $mimeMessage->addSubpart($data, $params); |
|
161 | - } else { |
|
162 | - $mimeMessage->addSubpart($att['data'], $params); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - $output = $mimeMessage->encode(); |
|
167 | - $mimeHeaders = $output['headers']; |
|
168 | - |
|
169 | - foreach ($mimeHeaders as $k => $v) { |
|
170 | - $this->debug("MIME header $k: $v"); |
|
171 | - if (strtolower($k) == 'content-type') { |
|
172 | - // PHP header() seems to strip leading whitespace starting |
|
173 | - // the second line, so force everything to one line |
|
174 | - $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - return $output['body']; |
|
179 | - } |
|
180 | - |
|
181 | - return parent::getHTTPBody($soapmsg); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * gets the HTTP content type for the current request. |
|
186 | - * |
|
187 | - * Note: getHTTPBody must be called before this. |
|
188 | - * |
|
189 | - * @return string the HTTP content type for the current request. |
|
190 | - * @access private |
|
191 | - */ |
|
192 | - function getHTTPContentType() { |
|
193 | - if (count($this->requestAttachments) > 0) { |
|
194 | - return $this->mimeContentType; |
|
195 | - } |
|
196 | - return parent::getHTTPContentType(); |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * gets the HTTP content type charset for the current request. |
|
201 | - * returns false for non-text content types. |
|
202 | - * |
|
203 | - * Note: getHTTPBody must be called before this. |
|
204 | - * |
|
205 | - * @return string the HTTP content type charset for the current request. |
|
206 | - * @access private |
|
207 | - */ |
|
208 | - function getHTTPContentTypeCharset() { |
|
209 | - if (count($this->requestAttachments) > 0) { |
|
210 | - return false; |
|
211 | - } |
|
212 | - return parent::getHTTPContentTypeCharset(); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * processes SOAP message returned from server |
|
217 | - * |
|
218 | - * @param array $headers The HTTP headers |
|
219 | - * @param string $data unprocessed response data from server |
|
220 | - * @return mixed value of the message, decoded into a PHP type |
|
221 | - * @access private |
|
222 | - */ |
|
55 | + /** |
|
56 | + * @var array Each array element in the return is an associative array with keys |
|
57 | + * data, filename, contenttype, cid |
|
58 | + * @access private |
|
59 | + */ |
|
60 | + var $requestAttachments = array(); |
|
61 | + /** |
|
62 | + * @var array Each array element in the return is an associative array with keys |
|
63 | + * data, filename, contenttype, cid |
|
64 | + * @access private |
|
65 | + */ |
|
66 | + var $responseAttachments; |
|
67 | + /** |
|
68 | + * @var string |
|
69 | + * @access private |
|
70 | + */ |
|
71 | + var $mimeContentType; |
|
72 | + |
|
73 | + /** |
|
74 | + * adds a MIME attachment to the current request. |
|
75 | + * |
|
76 | + * If the $data parameter contains an empty string, this method will read |
|
77 | + * the contents of the file named by the $filename parameter. |
|
78 | + * |
|
79 | + * If the $cid parameter is false, this method will generate the cid. |
|
80 | + * |
|
81 | + * @param string $data The data of the attachment |
|
82 | + * @param string $filename The filename of the attachment (default is empty string) |
|
83 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
84 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
85 | + * @return string The content-id (cid) of the attachment |
|
86 | + * @access public |
|
87 | + */ |
|
88 | + function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
89 | + if (! $cid) { |
|
90 | + $cid = md5(uniqid(time())); |
|
91 | + } |
|
92 | + |
|
93 | + $info['data'] = $data; |
|
94 | + $info['filename'] = $filename; |
|
95 | + $info['contenttype'] = $contenttype; |
|
96 | + $info['cid'] = $cid; |
|
97 | + |
|
98 | + $this->requestAttachments[] = $info; |
|
99 | + |
|
100 | + return $cid; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * clears the MIME attachments for the current request. |
|
105 | + * |
|
106 | + * @access public |
|
107 | + */ |
|
108 | + function clearAttachments() { |
|
109 | + $this->requestAttachments = array(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * gets the MIME attachments from the current response. |
|
114 | + * |
|
115 | + * Each array element in the return is an associative array with keys |
|
116 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
117 | + * for addAttachment. |
|
118 | + * |
|
119 | + * @return array The attachments. |
|
120 | + * @access public |
|
121 | + */ |
|
122 | + function getAttachments() { |
|
123 | + return $this->responseAttachments; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * gets the HTTP body for the current request. |
|
128 | + * |
|
129 | + * @param string $soapmsg The SOAP payload |
|
130 | + * @return string The HTTP body, which includes the SOAP payload |
|
131 | + * @access private |
|
132 | + */ |
|
133 | + function getHTTPBody($soapmsg) { |
|
134 | + if (count($this->requestAttachments) > 0) { |
|
135 | + $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
136 | + $mimeMessage = new Mail_mimePart('', $params); |
|
137 | + unset($params); |
|
138 | + |
|
139 | + $params['content_type'] = 'text/xml'; |
|
140 | + $params['encoding'] = '8bit'; |
|
141 | + $params['charset'] = $this->soap_defencoding; |
|
142 | + $mimeMessage->addSubpart($soapmsg, $params); |
|
143 | + |
|
144 | + foreach ($this->requestAttachments as $att) { |
|
145 | + unset($params); |
|
146 | + |
|
147 | + $params['content_type'] = $att['contenttype']; |
|
148 | + $params['encoding'] = 'base64'; |
|
149 | + $params['disposition'] = 'attachment'; |
|
150 | + $params['dfilename'] = $att['filename']; |
|
151 | + $params['cid'] = $att['cid']; |
|
152 | + |
|
153 | + if ($att['data'] == '' && $att['filename'] <> '') { |
|
154 | + if ($fd = fopen($att['filename'], 'rb')) { |
|
155 | + $data = fread($fd, filesize($att['filename'])); |
|
156 | + fclose($fd); |
|
157 | + } else { |
|
158 | + $data = ''; |
|
159 | + } |
|
160 | + $mimeMessage->addSubpart($data, $params); |
|
161 | + } else { |
|
162 | + $mimeMessage->addSubpart($att['data'], $params); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + $output = $mimeMessage->encode(); |
|
167 | + $mimeHeaders = $output['headers']; |
|
168 | + |
|
169 | + foreach ($mimeHeaders as $k => $v) { |
|
170 | + $this->debug("MIME header $k: $v"); |
|
171 | + if (strtolower($k) == 'content-type') { |
|
172 | + // PHP header() seems to strip leading whitespace starting |
|
173 | + // the second line, so force everything to one line |
|
174 | + $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + return $output['body']; |
|
179 | + } |
|
180 | + |
|
181 | + return parent::getHTTPBody($soapmsg); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * gets the HTTP content type for the current request. |
|
186 | + * |
|
187 | + * Note: getHTTPBody must be called before this. |
|
188 | + * |
|
189 | + * @return string the HTTP content type for the current request. |
|
190 | + * @access private |
|
191 | + */ |
|
192 | + function getHTTPContentType() { |
|
193 | + if (count($this->requestAttachments) > 0) { |
|
194 | + return $this->mimeContentType; |
|
195 | + } |
|
196 | + return parent::getHTTPContentType(); |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * gets the HTTP content type charset for the current request. |
|
201 | + * returns false for non-text content types. |
|
202 | + * |
|
203 | + * Note: getHTTPBody must be called before this. |
|
204 | + * |
|
205 | + * @return string the HTTP content type charset for the current request. |
|
206 | + * @access private |
|
207 | + */ |
|
208 | + function getHTTPContentTypeCharset() { |
|
209 | + if (count($this->requestAttachments) > 0) { |
|
210 | + return false; |
|
211 | + } |
|
212 | + return parent::getHTTPContentTypeCharset(); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * processes SOAP message returned from server |
|
217 | + * |
|
218 | + * @param array $headers The HTTP headers |
|
219 | + * @param string $data unprocessed response data from server |
|
220 | + * @return mixed value of the message, decoded into a PHP type |
|
221 | + * @access private |
|
222 | + */ |
|
223 | 223 | function parseResponse($headers, $data) { |
224 | - $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
225 | - $this->responseAttachments = array(); |
|
226 | - if (strstr($headers['content-type'], 'multipart/related')) { |
|
227 | - $this->debug('Decode multipart/related'); |
|
228 | - $input = ''; |
|
229 | - foreach ($headers as $k => $v) { |
|
230 | - $input .= "$k: $v\r\n"; |
|
231 | - } |
|
232 | - $params['input'] = $input . "\r\n" . $data; |
|
233 | - $params['include_bodies'] = true; |
|
234 | - $params['decode_bodies'] = true; |
|
235 | - $params['decode_headers'] = true; |
|
236 | - |
|
237 | - $structure = Mail_mimeDecode::decode($params); |
|
238 | - |
|
239 | - foreach ($structure->parts as $part) { |
|
240 | - if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
241 | - $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
242 | - $root = $part->body; |
|
243 | - $return = parent::parseResponse($part->headers, $part->body); |
|
244 | - } else { |
|
245 | - $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
246 | - $info['data'] = $part->body; |
|
247 | - $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
248 | - $info['contenttype'] = $part->headers['content-type']; |
|
249 | - $info['cid'] = $part->headers['content-id']; |
|
250 | - $this->responseAttachments[] = $info; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - if (isset($return)) { |
|
255 | - $this->responseData = $root; |
|
256 | - return $return; |
|
257 | - } |
|
258 | - |
|
259 | - $this->setError('No root part found in multipart/related content'); |
|
260 | - return ''; |
|
261 | - } |
|
262 | - $this->debug('Not multipart/related'); |
|
263 | - return parent::parseResponse($headers, $data); |
|
264 | - } |
|
224 | + $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
225 | + $this->responseAttachments = array(); |
|
226 | + if (strstr($headers['content-type'], 'multipart/related')) { |
|
227 | + $this->debug('Decode multipart/related'); |
|
228 | + $input = ''; |
|
229 | + foreach ($headers as $k => $v) { |
|
230 | + $input .= "$k: $v\r\n"; |
|
231 | + } |
|
232 | + $params['input'] = $input . "\r\n" . $data; |
|
233 | + $params['include_bodies'] = true; |
|
234 | + $params['decode_bodies'] = true; |
|
235 | + $params['decode_headers'] = true; |
|
236 | + |
|
237 | + $structure = Mail_mimeDecode::decode($params); |
|
238 | + |
|
239 | + foreach ($structure->parts as $part) { |
|
240 | + if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
241 | + $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
242 | + $root = $part->body; |
|
243 | + $return = parent::parseResponse($part->headers, $part->body); |
|
244 | + } else { |
|
245 | + $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
246 | + $info['data'] = $part->body; |
|
247 | + $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
248 | + $info['contenttype'] = $part->headers['content-type']; |
|
249 | + $info['cid'] = $part->headers['content-id']; |
|
250 | + $this->responseAttachments[] = $info; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + if (isset($return)) { |
|
255 | + $this->responseData = $root; |
|
256 | + return $return; |
|
257 | + } |
|
258 | + |
|
259 | + $this->setError('No root part found in multipart/related content'); |
|
260 | + return ''; |
|
261 | + } |
|
262 | + $this->debug('Not multipart/related'); |
|
263 | + return parent::parseResponse($headers, $data); |
|
264 | + } |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /* |
268 | 268 | * For backwards compatiblity, define soapclientmime unless the PHP SOAP extension is loaded. |
269 | 269 | */ |
270 | 270 | if (!extension_loaded('soap')) { |
271 | - class soapclientmime extends nusoap_client_mime { |
|
272 | - } |
|
271 | + class soapclientmime extends nusoap_client_mime { |
|
272 | + } |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -282,214 +282,214 @@ discard block |
||
282 | 282 | * @access public |
283 | 283 | */ |
284 | 284 | class nusoap_server_mime extends nusoap_server { |
285 | - /** |
|
286 | - * @var array Each array element in the return is an associative array with keys |
|
287 | - * data, filename, contenttype, cid |
|
288 | - * @access private |
|
289 | - */ |
|
290 | - var $requestAttachments = array(); |
|
291 | - /** |
|
292 | - * @var array Each array element in the return is an associative array with keys |
|
293 | - * data, filename, contenttype, cid |
|
294 | - * @access private |
|
295 | - */ |
|
296 | - var $responseAttachments; |
|
297 | - /** |
|
298 | - * @var string |
|
299 | - * @access private |
|
300 | - */ |
|
301 | - var $mimeContentType; |
|
302 | - |
|
303 | - /** |
|
304 | - * adds a MIME attachment to the current response. |
|
305 | - * |
|
306 | - * If the $data parameter contains an empty string, this method will read |
|
307 | - * the contents of the file named by the $filename parameter. |
|
308 | - * |
|
309 | - * If the $cid parameter is false, this method will generate the cid. |
|
310 | - * |
|
311 | - * @param string $data The data of the attachment |
|
312 | - * @param string $filename The filename of the attachment (default is empty string) |
|
313 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
314 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
315 | - * @return string The content-id (cid) of the attachment |
|
316 | - * @access public |
|
317 | - */ |
|
318 | - function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
319 | - if (! $cid) { |
|
320 | - $cid = md5(uniqid(time())); |
|
321 | - } |
|
322 | - |
|
323 | - $info['data'] = $data; |
|
324 | - $info['filename'] = $filename; |
|
325 | - $info['contenttype'] = $contenttype; |
|
326 | - $info['cid'] = $cid; |
|
327 | - |
|
328 | - $this->responseAttachments[] = $info; |
|
329 | - |
|
330 | - return $cid; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * clears the MIME attachments for the current response. |
|
335 | - * |
|
336 | - * @access public |
|
337 | - */ |
|
338 | - function clearAttachments() { |
|
339 | - $this->responseAttachments = array(); |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * gets the MIME attachments from the current request. |
|
344 | - * |
|
345 | - * Each array element in the return is an associative array with keys |
|
346 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
347 | - * for addAttachment. |
|
348 | - * |
|
349 | - * @return array The attachments. |
|
350 | - * @access public |
|
351 | - */ |
|
352 | - function getAttachments() { |
|
353 | - return $this->requestAttachments; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * gets the HTTP body for the current response. |
|
358 | - * |
|
359 | - * @param string $soapmsg The SOAP payload |
|
360 | - * @return string The HTTP body, which includes the SOAP payload |
|
361 | - * @access private |
|
362 | - */ |
|
363 | - function getHTTPBody($soapmsg) { |
|
364 | - if (count($this->responseAttachments) > 0) { |
|
365 | - $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
366 | - $mimeMessage = new Mail_mimePart('', $params); |
|
367 | - unset($params); |
|
368 | - |
|
369 | - $params['content_type'] = 'text/xml'; |
|
370 | - $params['encoding'] = '8bit'; |
|
371 | - $params['charset'] = $this->soap_defencoding; |
|
372 | - $mimeMessage->addSubpart($soapmsg, $params); |
|
373 | - |
|
374 | - foreach ($this->responseAttachments as $att) { |
|
375 | - unset($params); |
|
376 | - |
|
377 | - $params['content_type'] = $att['contenttype']; |
|
378 | - $params['encoding'] = 'base64'; |
|
379 | - $params['disposition'] = 'attachment'; |
|
380 | - $params['dfilename'] = $att['filename']; |
|
381 | - $params['cid'] = $att['cid']; |
|
382 | - |
|
383 | - if ($att['data'] == '' && $att['filename'] <> '') { |
|
384 | - if ($fd = fopen($att['filename'], 'rb')) { |
|
385 | - $data = fread($fd, filesize($att['filename'])); |
|
386 | - fclose($fd); |
|
387 | - } else { |
|
388 | - $data = ''; |
|
389 | - } |
|
390 | - $mimeMessage->addSubpart($data, $params); |
|
391 | - } else { |
|
392 | - $mimeMessage->addSubpart($att['data'], $params); |
|
393 | - } |
|
394 | - } |
|
395 | - |
|
396 | - $output = $mimeMessage->encode(); |
|
397 | - $mimeHeaders = $output['headers']; |
|
398 | - |
|
399 | - foreach ($mimeHeaders as $k => $v) { |
|
400 | - $this->debug("MIME header $k: $v"); |
|
401 | - if (strtolower($k) == 'content-type') { |
|
402 | - // PHP header() seems to strip leading whitespace starting |
|
403 | - // the second line, so force everything to one line |
|
404 | - $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
405 | - } |
|
406 | - } |
|
407 | - |
|
408 | - return $output['body']; |
|
409 | - } |
|
410 | - |
|
411 | - return parent::getHTTPBody($soapmsg); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * gets the HTTP content type for the current response. |
|
416 | - * |
|
417 | - * Note: getHTTPBody must be called before this. |
|
418 | - * |
|
419 | - * @return string the HTTP content type for the current response. |
|
420 | - * @access private |
|
421 | - */ |
|
422 | - function getHTTPContentType() { |
|
423 | - if (count($this->responseAttachments) > 0) { |
|
424 | - return $this->mimeContentType; |
|
425 | - } |
|
426 | - return parent::getHTTPContentType(); |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * gets the HTTP content type charset for the current response. |
|
431 | - * returns false for non-text content types. |
|
432 | - * |
|
433 | - * Note: getHTTPBody must be called before this. |
|
434 | - * |
|
435 | - * @return string the HTTP content type charset for the current response. |
|
436 | - * @access private |
|
437 | - */ |
|
438 | - function getHTTPContentTypeCharset() { |
|
439 | - if (count($this->responseAttachments) > 0) { |
|
440 | - return false; |
|
441 | - } |
|
442 | - return parent::getHTTPContentTypeCharset(); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * processes SOAP message received from client |
|
447 | - * |
|
448 | - * @param array $headers The HTTP headers |
|
449 | - * @param string $data unprocessed request data from client |
|
450 | - * @return mixed value of the message, decoded into a PHP type |
|
451 | - * @access private |
|
452 | - */ |
|
285 | + /** |
|
286 | + * @var array Each array element in the return is an associative array with keys |
|
287 | + * data, filename, contenttype, cid |
|
288 | + * @access private |
|
289 | + */ |
|
290 | + var $requestAttachments = array(); |
|
291 | + /** |
|
292 | + * @var array Each array element in the return is an associative array with keys |
|
293 | + * data, filename, contenttype, cid |
|
294 | + * @access private |
|
295 | + */ |
|
296 | + var $responseAttachments; |
|
297 | + /** |
|
298 | + * @var string |
|
299 | + * @access private |
|
300 | + */ |
|
301 | + var $mimeContentType; |
|
302 | + |
|
303 | + /** |
|
304 | + * adds a MIME attachment to the current response. |
|
305 | + * |
|
306 | + * If the $data parameter contains an empty string, this method will read |
|
307 | + * the contents of the file named by the $filename parameter. |
|
308 | + * |
|
309 | + * If the $cid parameter is false, this method will generate the cid. |
|
310 | + * |
|
311 | + * @param string $data The data of the attachment |
|
312 | + * @param string $filename The filename of the attachment (default is empty string) |
|
313 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
314 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
315 | + * @return string The content-id (cid) of the attachment |
|
316 | + * @access public |
|
317 | + */ |
|
318 | + function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
|
319 | + if (! $cid) { |
|
320 | + $cid = md5(uniqid(time())); |
|
321 | + } |
|
322 | + |
|
323 | + $info['data'] = $data; |
|
324 | + $info['filename'] = $filename; |
|
325 | + $info['contenttype'] = $contenttype; |
|
326 | + $info['cid'] = $cid; |
|
327 | + |
|
328 | + $this->responseAttachments[] = $info; |
|
329 | + |
|
330 | + return $cid; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * clears the MIME attachments for the current response. |
|
335 | + * |
|
336 | + * @access public |
|
337 | + */ |
|
338 | + function clearAttachments() { |
|
339 | + $this->responseAttachments = array(); |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * gets the MIME attachments from the current request. |
|
344 | + * |
|
345 | + * Each array element in the return is an associative array with keys |
|
346 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
347 | + * for addAttachment. |
|
348 | + * |
|
349 | + * @return array The attachments. |
|
350 | + * @access public |
|
351 | + */ |
|
352 | + function getAttachments() { |
|
353 | + return $this->requestAttachments; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * gets the HTTP body for the current response. |
|
358 | + * |
|
359 | + * @param string $soapmsg The SOAP payload |
|
360 | + * @return string The HTTP body, which includes the SOAP payload |
|
361 | + * @access private |
|
362 | + */ |
|
363 | + function getHTTPBody($soapmsg) { |
|
364 | + if (count($this->responseAttachments) > 0) { |
|
365 | + $params['content_type'] = 'multipart/related; type="text/xml"'; |
|
366 | + $mimeMessage = new Mail_mimePart('', $params); |
|
367 | + unset($params); |
|
368 | + |
|
369 | + $params['content_type'] = 'text/xml'; |
|
370 | + $params['encoding'] = '8bit'; |
|
371 | + $params['charset'] = $this->soap_defencoding; |
|
372 | + $mimeMessage->addSubpart($soapmsg, $params); |
|
373 | + |
|
374 | + foreach ($this->responseAttachments as $att) { |
|
375 | + unset($params); |
|
376 | + |
|
377 | + $params['content_type'] = $att['contenttype']; |
|
378 | + $params['encoding'] = 'base64'; |
|
379 | + $params['disposition'] = 'attachment'; |
|
380 | + $params['dfilename'] = $att['filename']; |
|
381 | + $params['cid'] = $att['cid']; |
|
382 | + |
|
383 | + if ($att['data'] == '' && $att['filename'] <> '') { |
|
384 | + if ($fd = fopen($att['filename'], 'rb')) { |
|
385 | + $data = fread($fd, filesize($att['filename'])); |
|
386 | + fclose($fd); |
|
387 | + } else { |
|
388 | + $data = ''; |
|
389 | + } |
|
390 | + $mimeMessage->addSubpart($data, $params); |
|
391 | + } else { |
|
392 | + $mimeMessage->addSubpart($att['data'], $params); |
|
393 | + } |
|
394 | + } |
|
395 | + |
|
396 | + $output = $mimeMessage->encode(); |
|
397 | + $mimeHeaders = $output['headers']; |
|
398 | + |
|
399 | + foreach ($mimeHeaders as $k => $v) { |
|
400 | + $this->debug("MIME header $k: $v"); |
|
401 | + if (strtolower($k) == 'content-type') { |
|
402 | + // PHP header() seems to strip leading whitespace starting |
|
403 | + // the second line, so force everything to one line |
|
404 | + $this->mimeContentType = str_replace("\r\n", " ", $v); |
|
405 | + } |
|
406 | + } |
|
407 | + |
|
408 | + return $output['body']; |
|
409 | + } |
|
410 | + |
|
411 | + return parent::getHTTPBody($soapmsg); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * gets the HTTP content type for the current response. |
|
416 | + * |
|
417 | + * Note: getHTTPBody must be called before this. |
|
418 | + * |
|
419 | + * @return string the HTTP content type for the current response. |
|
420 | + * @access private |
|
421 | + */ |
|
422 | + function getHTTPContentType() { |
|
423 | + if (count($this->responseAttachments) > 0) { |
|
424 | + return $this->mimeContentType; |
|
425 | + } |
|
426 | + return parent::getHTTPContentType(); |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * gets the HTTP content type charset for the current response. |
|
431 | + * returns false for non-text content types. |
|
432 | + * |
|
433 | + * Note: getHTTPBody must be called before this. |
|
434 | + * |
|
435 | + * @return string the HTTP content type charset for the current response. |
|
436 | + * @access private |
|
437 | + */ |
|
438 | + function getHTTPContentTypeCharset() { |
|
439 | + if (count($this->responseAttachments) > 0) { |
|
440 | + return false; |
|
441 | + } |
|
442 | + return parent::getHTTPContentTypeCharset(); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * processes SOAP message received from client |
|
447 | + * |
|
448 | + * @param array $headers The HTTP headers |
|
449 | + * @param string $data unprocessed request data from client |
|
450 | + * @return mixed value of the message, decoded into a PHP type |
|
451 | + * @access private |
|
452 | + */ |
|
453 | 453 | function parseRequest($headers, $data) { |
454 | - $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
455 | - $this->requestAttachments = array(); |
|
456 | - if (strstr($headers['content-type'], 'multipart/related')) { |
|
457 | - $this->debug('Decode multipart/related'); |
|
458 | - $input = ''; |
|
459 | - foreach ($headers as $k => $v) { |
|
460 | - $input .= "$k: $v\r\n"; |
|
461 | - } |
|
462 | - $params['input'] = $input . "\r\n" . $data; |
|
463 | - $params['include_bodies'] = true; |
|
464 | - $params['decode_bodies'] = true; |
|
465 | - $params['decode_headers'] = true; |
|
466 | - |
|
467 | - $structure = Mail_mimeDecode::decode($params); |
|
468 | - |
|
469 | - foreach ($structure->parts as $part) { |
|
470 | - if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
471 | - $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
472 | - $return = parent::parseRequest($part->headers, $part->body); |
|
473 | - } else { |
|
474 | - $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
475 | - $info['data'] = $part->body; |
|
476 | - $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
477 | - $info['contenttype'] = $part->headers['content-type']; |
|
478 | - $info['cid'] = $part->headers['content-id']; |
|
479 | - $this->requestAttachments[] = $info; |
|
480 | - } |
|
481 | - } |
|
482 | - |
|
483 | - if (isset($return)) { |
|
484 | - return $return; |
|
485 | - } |
|
486 | - |
|
487 | - $this->setError('No root part found in multipart/related content'); |
|
488 | - return; |
|
489 | - } |
|
490 | - $this->debug('Not multipart/related'); |
|
491 | - return parent::parseRequest($headers, $data); |
|
492 | - } |
|
454 | + $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
|
455 | + $this->requestAttachments = array(); |
|
456 | + if (strstr($headers['content-type'], 'multipart/related')) { |
|
457 | + $this->debug('Decode multipart/related'); |
|
458 | + $input = ''; |
|
459 | + foreach ($headers as $k => $v) { |
|
460 | + $input .= "$k: $v\r\n"; |
|
461 | + } |
|
462 | + $params['input'] = $input . "\r\n" . $data; |
|
463 | + $params['include_bodies'] = true; |
|
464 | + $params['decode_bodies'] = true; |
|
465 | + $params['decode_headers'] = true; |
|
466 | + |
|
467 | + $structure = Mail_mimeDecode::decode($params); |
|
468 | + |
|
469 | + foreach ($structure->parts as $part) { |
|
470 | + if (!isset($part->disposition) && (strstr($part->headers['content-type'], 'text/xml'))) { |
|
471 | + $this->debug('Have root part of type ' . $part->headers['content-type']); |
|
472 | + $return = parent::parseRequest($part->headers, $part->body); |
|
473 | + } else { |
|
474 | + $this->debug('Have an attachment of type ' . $part->headers['content-type']); |
|
475 | + $info['data'] = $part->body; |
|
476 | + $info['filename'] = isset($part->d_parameters['filename']) ? $part->d_parameters['filename'] : ''; |
|
477 | + $info['contenttype'] = $part->headers['content-type']; |
|
478 | + $info['cid'] = $part->headers['content-id']; |
|
479 | + $this->requestAttachments[] = $info; |
|
480 | + } |
|
481 | + } |
|
482 | + |
|
483 | + if (isset($return)) { |
|
484 | + return $return; |
|
485 | + } |
|
486 | + |
|
487 | + $this->setError('No root part found in multipart/related content'); |
|
488 | + return; |
|
489 | + } |
|
490 | + $this->debug('Not multipart/related'); |
|
491 | + return parent::parseRequest($headers, $data); |
|
492 | + } |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /* |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | if ($exercise_info->start_time != '0000-00-00 00:00:00') { |
283 | 283 | $allowed_time = api_strtotime($exercise_info->start_time, 'UTC'); |
284 | 284 | if ($now < $allowed_time) { |
285 | - continue; |
|
285 | + continue; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 | $exercise_info->exercise = Display::url( |
@@ -512,11 +512,11 @@ discard block |
||
512 | 512 | window.location.href=ui.tab; |
513 | 513 | }); |
514 | 514 | <?php |
515 | - //Displays js code to use a jqgrid |
|
516 | - echo Display::grid_js('courses', '', $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list); |
|
517 | - echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), ''); |
|
518 | - echo Display::grid_js('list_course', $url_by_course, $columns, $column_model,$extra_params_course,array(),''); |
|
519 | - echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),''); |
|
515 | + //Displays js code to use a jqgrid |
|
516 | + echo Display::grid_js('courses', '', $columns_courses, $column_model_courses, $extra_params_courses, $new_course_list); |
|
517 | + echo Display::grid_js('list_default', $url, $columns, $column_model,$extra_params,array(), ''); |
|
518 | + echo Display::grid_js('list_course', $url_by_course, $columns, $column_model,$extra_params_course,array(),''); |
|
519 | + echo Display::grid_js('list_week', $url_week, $column_week, $column_week_model, $extra_params_week,array(),''); |
|
520 | 520 | |
521 | 521 | if (!api_is_anonymous()) { |
522 | 522 | echo Display::grid_js('exercises', '', $column_exercise, $column_exercise_model, $extra_params_exercise, $my_real_array); |
@@ -18,24 +18,24 @@ discard block |
||
18 | 18 | private $_nonce_chars; |
19 | 19 | |
20 | 20 | /** |
21 | - * Constructor |
|
21 | + * Constructor |
|
22 | 22 | * |
23 | - * @access public |
|
23 | + * @access public |
|
24 | 24 | * @param api_key (String) The API Key (sometimes referred to as the consumer key) This value is usually supplied by the site you wish to use. |
25 | 25 | * @param shared_secret (String) The shared secret. This value is also usually provided by the site you wish to use. |
26 | - * @return OAuthSimple (Object) |
|
26 | + * @return OAuthSimple (Object) |
|
27 | 27 | */ |
28 | 28 | function __construct ($APIKey = "", $sharedSecret=""){ |
29 | 29 | |
30 | 30 | if (!empty($APIKey)) |
31 | - { |
|
32 | - $this->_secrets['consumer_key'] = $APIKey; |
|
33 | - } |
|
31 | + { |
|
32 | + $this->_secrets['consumer_key'] = $APIKey; |
|
33 | + } |
|
34 | 34 | |
35 | 35 | if (!empty($sharedSecret)) |
36 | - { |
|
37 | - $this->_secrets['shared_secret'] = $sharedSecret; |
|
38 | - } |
|
36 | + { |
|
37 | + $this->_secrets['shared_secret'] = $sharedSecret; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | $this->_default_signature_method = "HMAC-SHA1"; |
41 | 41 | $this->_action = "GET"; |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * Reset the parameters and URL |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @return OAuthSimple (Object) |
|
52 | - */ |
|
48 | + * Reset the parameters and URL |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @return OAuthSimple (Object) |
|
52 | + */ |
|
53 | 53 | public function reset() { |
54 | 54 | $this->_parameters = Array(); |
55 | 55 | $this->path = NULL; |
@@ -59,87 +59,87 @@ discard block |
||
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
62 | - * Set the parameters either from a hash or a string |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash) |
|
66 | - * @return OAuthSimple (Object) |
|
67 | - */ |
|
62 | + * Set the parameters either from a hash or a string |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash) |
|
66 | + * @return OAuthSimple (Object) |
|
67 | + */ |
|
68 | 68 | public function setParameters ($parameters=Array()) { |
69 | 69 | |
70 | 70 | if (is_string($parameters)) |
71 | - { |
|
72 | - $parameters = $this->_parseParameterString($parameters); |
|
73 | - } |
|
71 | + { |
|
72 | + $parameters = $this->_parseParameterString($parameters); |
|
73 | + } |
|
74 | 74 | if (empty($this->_parameters)) |
75 | - { |
|
76 | - $this->_parameters = $parameters; |
|
77 | - } |
|
75 | + { |
|
76 | + $this->_parameters = $parameters; |
|
77 | + } |
|
78 | 78 | else if (!empty($parameters)) |
79 | - { |
|
80 | - $this->_parameters = array_merge($this->_parameters,$parameters); |
|
81 | - } |
|
79 | + { |
|
80 | + $this->_parameters = array_merge($this->_parameters,$parameters); |
|
81 | + } |
|
82 | 82 | if (empty($this->_parameters['oauth_nonce'])) |
83 | - { |
|
84 | - $this->_getNonce(); |
|
85 | - } |
|
83 | + { |
|
84 | + $this->_getNonce(); |
|
85 | + } |
|
86 | 86 | if (empty($this->_parameters['oauth_timestamp'])) |
87 | - { |
|
88 | - $this->_getTimeStamp(); |
|
89 | - } |
|
87 | + { |
|
88 | + $this->_getTimeStamp(); |
|
89 | + } |
|
90 | 90 | if (empty($this->_parameters['oauth_consumer_key'])) |
91 | - { |
|
92 | - $this->_getApiKey(); |
|
93 | - } |
|
91 | + { |
|
92 | + $this->_getApiKey(); |
|
93 | + } |
|
94 | 94 | if (empty($this->_parameters['oauth_token'])) |
95 | - { |
|
96 | - $this->_getAccessToken(); |
|
97 | - } |
|
95 | + { |
|
96 | + $this->_getAccessToken(); |
|
97 | + } |
|
98 | 98 | if (empty($this->_parameters['oauth_signature_method'])) |
99 | - { |
|
99 | + { |
|
100 | 100 | $this->setSignatureMethod(); |
101 | - } |
|
101 | + } |
|
102 | 102 | if (empty($this->_parameters['oauth_version'])) |
103 | - { |
|
103 | + { |
|
104 | 104 | $this->_parameters['oauth_version']="1.0"; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | return $this; |
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Convenience method for setParameters |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @see setParameters |
|
115 | - */ |
|
111 | + * Convenience method for setParameters |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @see setParameters |
|
115 | + */ |
|
116 | 116 | public function setQueryString ($parameters) |
117 | 117 | { |
118 | 118 | return $this->setParameters($parameters); |
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | - * Set the target URL (does not include the parameters) |
|
123 | - * |
|
122 | + * Set the target URL (does not include the parameters) |
|
123 | + * |
|
124 | 124 | * @param path (String) the fully qualified URI (excluding query arguments) (e.g "http://example.org/foo") |
125 | - * @return OAuthSimple (Object) |
|
125 | + * @return OAuthSimple (Object) |
|
126 | 126 | */ |
127 | 127 | public function setURL ($path) |
128 | - { |
|
128 | + { |
|
129 | 129 | if (empty($path)) |
130 | - { |
|
130 | + { |
|
131 | 131 | throw new OAuthSimpleException('No path specified for OAuthSimple.setURL'); |
132 | - } |
|
132 | + } |
|
133 | 133 | $this->_path=$path; |
134 | 134 | |
135 | 135 | return $this; |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Convenience method for setURL |
|
139 | + * Convenience method for setURL |
|
140 | 140 | * |
141 | 141 | * @param path (String) |
142 | - * @see setURL |
|
142 | + * @see setURL |
|
143 | 143 | */ |
144 | 144 | public function setPath ($path) |
145 | 145 | { |
@@ -147,39 +147,39 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
150 | - * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.) |
|
150 | + * Set the "action" for the url, (e.g. GET,POST, DELETE, etc.) |
|
151 | 151 | * |
152 | 152 | * @param action (String) HTTP Action word. |
153 | - * @return OAuthSimple (Object) |
|
153 | + * @return OAuthSimple (Object) |
|
154 | 154 | */ |
155 | 155 | public function setAction ($action) |
156 | 156 | { |
157 | 157 | if (empty($action)) |
158 | - { |
|
159 | - $action = 'GET'; |
|
160 | - } |
|
158 | + { |
|
159 | + $action = 'GET'; |
|
160 | + } |
|
161 | 161 | $action = strtoupper($action); |
162 | 162 | if (preg_match('/[^A-Z]/',$action)) |
163 | - { |
|
163 | + { |
|
164 | 164 | throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction'); |
165 | - } |
|
165 | + } |
|
166 | 166 | $this->_action = $action; |
167 | 167 | |
168 | 168 | return $this; |
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
172 | - * Set the signatures (as well as validate the ones you have) |
|
172 | + * Set the signatures (as well as validate the ones you have) |
|
173 | 173 | * |
174 | 174 | * @param signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:} |
175 | - * @return OAuthSimple (Object) |
|
175 | + * @return OAuthSimple (Object) |
|
176 | 176 | */ |
177 | 177 | public function signatures ($signatures) |
178 | 178 | { |
179 | 179 | if (!empty($signatures) && !is_array($signatures)) |
180 | - { |
|
180 | + { |
|
181 | 181 | throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures'); |
182 | - } |
|
182 | + } |
|
183 | 183 | if (!empty($signatures)) |
184 | 184 | { |
185 | 185 | if (empty($this->_secrets)) |
@@ -189,33 +189,33 @@ discard block |
||
189 | 189 | $this->_secrets=array_merge($this->_secrets,$signatures); |
190 | 190 | } |
191 | 191 | if (isset($this->_secrets['api_key'])) |
192 | - { |
|
192 | + { |
|
193 | 193 | $this->_secrets['consumer_key'] = $this->_secrets['api_key']; |
194 | - } |
|
194 | + } |
|
195 | 195 | if (isset($this->_secrets['access_token'])) |
196 | - { |
|
196 | + { |
|
197 | 197 | $this->_secrets['oauth_token'] = $this->_secrets['access_token']; |
198 | - } |
|
198 | + } |
|
199 | 199 | if (isset($this->_secrets['access_secret'])) |
200 | - { |
|
200 | + { |
|
201 | 201 | $this->_secrets['shared_secret'] = $this->_secrets['access_secret']; |
202 | 202 | } |
203 | 203 | if (isset($this->_secrets['oauth_token_secret'])) |
204 | - { |
|
204 | + { |
|
205 | 205 | $this->_secrets['oauth_secret'] = $this->_secrets['oauth_token_secret']; |
206 | - } |
|
206 | + } |
|
207 | 207 | if (empty($this->_secrets['consumer_key'])) |
208 | - { |
|
208 | + { |
|
209 | 209 | throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures'); |
210 | 210 | } |
211 | 211 | if (empty($this->_secrets['shared_secret'])) |
212 | - { |
|
212 | + { |
|
213 | 213 | throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures'); |
214 | - } |
|
214 | + } |
|
215 | 215 | if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret'])) |
216 | - { |
|
216 | + { |
|
217 | 217 | throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures'); |
218 | - } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | return $this; |
221 | 221 | } |
@@ -226,30 +226,30 @@ discard block |
||
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
229 | - * Set the signature method (currently only Plaintext or SHA-MAC1) |
|
229 | + * Set the signature method (currently only Plaintext or SHA-MAC1) |
|
230 | 230 | * |
231 | 231 | * @param method (String) Method of signing the transaction (only PLAINTEXT and SHA-MAC1 allowed for now) |
232 | - * @return OAuthSimple (Object) |
|
233 | - */ |
|
232 | + * @return OAuthSimple (Object) |
|
233 | + */ |
|
234 | 234 | public function setSignatureMethod ($method="") |
235 | - { |
|
235 | + { |
|
236 | 236 | if (empty($method)) |
237 | - { |
|
237 | + { |
|
238 | 238 | $method = $this->_default_signature_method; |
239 | - } |
|
239 | + } |
|
240 | 240 | $method = strtoupper($method); |
241 | 241 | switch($method) |
242 | 242 | { |
243 | 243 | case 'PLAINTEXT': |
244 | 244 | case 'HMAC-SHA1': |
245 | 245 | $this->_parameters['oauth_signature_method']=$method; |
246 | - break; |
|
246 | + break; |
|
247 | 247 | default: |
248 | 248 | throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod"); |
249 | - break; |
|
249 | + break; |
|
250 | 250 | } |
251 | 251 | |
252 | - return $this; |
|
252 | + return $this; |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | /** sign the request |
@@ -258,30 +258,30 @@ discard block |
||
258 | 258 | * other helper functions. |
259 | 259 | * |
260 | 260 | * @param args (Array) hash of arguments for the call {action, path, parameters (array), method, signatures (array)} all arguments are optional. |
261 | - * @return (Array) signed values |
|
261 | + * @return (Array) signed values |
|
262 | 262 | */ |
263 | 263 | public function sign($args=array()) |
264 | 264 | { |
265 | 265 | if (!empty($args['action'])) |
266 | - { |
|
266 | + { |
|
267 | 267 | $this->setAction($args['action']); |
268 | - } |
|
268 | + } |
|
269 | 269 | if (!empty($args['path'])) |
270 | - { |
|
270 | + { |
|
271 | 271 | $this->setPath($args['path']); |
272 | 272 | } |
273 | 273 | if (!empty($args['method'])) |
274 | - { |
|
274 | + { |
|
275 | 275 | $this->setSignatureMethod($args['method']); |
276 | - } |
|
276 | + } |
|
277 | 277 | if (!empty($args['signatures'])) |
278 | - { |
|
278 | + { |
|
279 | 279 | $this->signatures($args['signatures']); |
280 | - } |
|
280 | + } |
|
281 | 281 | if (empty($args['parameters'])) |
282 | - { |
|
282 | + { |
|
283 | 283 | $args['parameters']=array(); |
284 | - } |
|
284 | + } |
|
285 | 285 | $this->setParameters($args['parameters']); |
286 | 286 | $normParams = $this->_normalizedParameters(); |
287 | 287 | |
@@ -295,29 +295,29 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | - * Return a formatted "header" string |
|
298 | + * Return a formatted "header" string |
|
299 | 299 | * |
300 | 300 | * NOTE: This doesn't set the "Authorization: " prefix, which is required. |
301 | 301 | * It's not set because various set header functions prefer different |
302 | 302 | * ways to do that. |
303 | 303 | * |
304 | 304 | * @param args (Array) |
305 | - * @return $result (String) |
|
306 | - */ |
|
305 | + * @return $result (String) |
|
306 | + */ |
|
307 | 307 | public function getHeaderString ($args=array()) |
308 | 308 | { |
309 | 309 | if (empty($this->_parameters['oauth_signature'])) |
310 | - { |
|
310 | + { |
|
311 | 311 | $this->sign($args); |
312 | - } |
|
312 | + } |
|
313 | 313 | $result = 'OAuth '; |
314 | 314 | |
315 | 315 | foreach ($this->_parameters as $pName => $pValue) |
316 | 316 | { |
317 | 317 | if (strpos($pName,'oauth_') !== 0) |
318 | - { |
|
318 | + { |
|
319 | 319 | continue; |
320 | - } |
|
320 | + } |
|
321 | 321 | if (is_array($pValue)) |
322 | 322 | { |
323 | 323 | foreach ($pValue as $val) |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | { |
343 | 343 | list ($key,$token) = explode('=',$element); |
344 | 344 | if ($token) |
345 | - { |
|
345 | + { |
|
346 | 346 | $token = urldecode($token); |
347 | - } |
|
347 | + } |
|
348 | 348 | if (!empty($result[$key])) |
349 | 349 | { |
350 | 350 | if (!is_array($result[$key])) |
351 | - { |
|
351 | + { |
|
352 | 352 | $result[$key] = array($result[$key],$token); |
353 | - } |
|
353 | + } |
|
354 | 354 | else |
355 | - { |
|
355 | + { |
|
356 | 356 | array_push($result[$key],$token); |
357 | - } |
|
357 | + } |
|
358 | 358 | } |
359 | 359 | else |
360 | 360 | $result[$key]=$token; |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | private static function _oauthEscape($string) |
367 | 367 | { |
368 | 368 | if ($string === 0) { return 0; } |
369 | - if ($string == '0') { return '0'; } |
|
369 | + if ($string == '0') { return '0'; } |
|
370 | 370 | if (strlen($string) == 0) { return ''; } |
371 | 371 | if (is_array($string)) { |
372 | 372 | throw new OAuthSimpleException('Array passed to _oauthEscape'); |
373 | - } |
|
373 | + } |
|
374 | 374 | $string = urlencode($string); |
375 | 375 | |
376 | - //FIX: urlencode of ~ and '+' |
|
376 | + //FIX: urlencode of ~ and '+' |
|
377 | 377 | $string = str_replace( |
378 | 378 | Array('%7E','+' ), // Replace these |
379 | 379 | Array('~', '%20'), // with these |
@@ -410,13 +410,13 @@ discard block |
||
410 | 410 | private function _getAccessToken() |
411 | 411 | { |
412 | 412 | if (!isset($this->_secrets['oauth_secret'])) |
413 | - { |
|
413 | + { |
|
414 | 414 | return ''; |
415 | - } |
|
415 | + } |
|
416 | 416 | if (!isset($this->_secrets['oauth_token'])) |
417 | - { |
|
417 | + { |
|
418 | 418 | throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.'); |
419 | - } |
|
419 | + } |
|
420 | 420 | $this->_parameters['oauth_token'] = $this->_secrets['oauth_token']; |
421 | 421 | |
422 | 422 | return $this->_parameters['oauth_token']; |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | |
430 | 430 | private function _normalizedParameters() |
431 | 431 | { |
432 | - $normalized_keys = array(); |
|
433 | - $return_array = array(); |
|
432 | + $normalized_keys = array(); |
|
433 | + $return_array = array(); |
|
434 | 434 | |
435 | 435 | foreach ( $this->_parameters as $paramName=>$paramValue) { |
436 | 436 | if (preg_match('/w+_secret/', $paramName) OR |
@@ -439,59 +439,59 @@ discard block |
||
439 | 439 | } |
440 | 440 | // Read parameters from a file. Hope you're practicing safe PHP. |
441 | 441 | //if (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1))) |
442 | - //{ |
|
443 | - if (is_array($paramValue)) |
|
444 | - { |
|
445 | - $normalized_keys[self::_oauthEscape($paramName)] = array(); |
|
446 | - foreach($paramValue as $item) |
|
447 | - { |
|
448 | - array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item)); |
|
449 | - } |
|
450 | - } |
|
451 | - else |
|
452 | - { |
|
453 | - $normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue); |
|
454 | - } |
|
455 | - //} |
|
456 | - } |
|
457 | - |
|
458 | - ksort($normalized_keys); |
|
459 | - |
|
460 | - foreach($normalized_keys as $key=>$val) |
|
461 | - { |
|
462 | - if (is_array($val)) |
|
463 | - { |
|
464 | - sort($val); |
|
465 | - foreach($val as $element) |
|
466 | - { |
|
467 | - array_push($return_array, $key . "=" . $element); |
|
468 | - } |
|
469 | - } |
|
470 | - else |
|
471 | - { |
|
472 | - array_push($return_array, $key .'='. $val); |
|
473 | - } |
|
442 | + //{ |
|
443 | + if (is_array($paramValue)) |
|
444 | + { |
|
445 | + $normalized_keys[self::_oauthEscape($paramName)] = array(); |
|
446 | + foreach($paramValue as $item) |
|
447 | + { |
|
448 | + array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item)); |
|
449 | + } |
|
450 | + } |
|
451 | + else |
|
452 | + { |
|
453 | + $normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue); |
|
454 | + } |
|
455 | + //} |
|
456 | + } |
|
457 | + |
|
458 | + ksort($normalized_keys); |
|
459 | + |
|
460 | + foreach($normalized_keys as $key=>$val) |
|
461 | + { |
|
462 | + if (is_array($val)) |
|
463 | + { |
|
464 | + sort($val); |
|
465 | + foreach($val as $element) |
|
466 | + { |
|
467 | + array_push($return_array, $key . "=" . $element); |
|
468 | + } |
|
469 | + } |
|
470 | + else |
|
471 | + { |
|
472 | + array_push($return_array, $key .'='. $val); |
|
473 | + } |
|
474 | 474 | |
475 | 475 | } |
476 | 476 | $presig = join("&", $return_array); |
477 | 477 | $sig = $this->_generateSignature($presig); |
478 | 478 | $this->_parameters['oauth_signature']=$sig; |
479 | 479 | array_push($return_array, "oauth_signature=$sig"); |
480 | - return join("&", $return_array); |
|
480 | + return join("&", $return_array); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | |
484 | 484 | private function _generateSignature ($parameters="") |
485 | 485 | { |
486 | 486 | $secretKey = ''; |
487 | - if(isset($this->_secrets['shared_secret'])) |
|
488 | - { |
|
489 | - $secretKey = self::_oauthEscape($this->_secrets['shared_secret']); |
|
490 | - } |
|
491 | - |
|
492 | - $secretKey .= '&'; |
|
493 | - if(isset($this->_secrets['oauth_secret'])) |
|
494 | - { |
|
487 | + if(isset($this->_secrets['shared_secret'])) |
|
488 | + { |
|
489 | + $secretKey = self::_oauthEscape($this->_secrets['shared_secret']); |
|
490 | + } |
|
491 | + |
|
492 | + $secretKey .= '&'; |
|
493 | + if(isset($this->_secrets['oauth_secret'])) |
|
494 | + { |
|
495 | 495 | $secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']); |
496 | 496 | } |
497 | 497 | if(!empty($parameters)){ |
@@ -507,33 +507,33 @@ discard block |
||
507 | 507 | return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE)); |
508 | 508 | default: |
509 | 509 | throw new OAuthSimpleException('Unknown signature method for OAuthSimple'); |
510 | - break; |
|
510 | + break; |
|
511 | 511 | } |
512 | 512 | } |
513 | 513 | } |
514 | 514 | |
515 | 515 | class OAuthSimpleException extends Exception { |
516 | 516 | |
517 | - public function __construct($err, $isDebug = FALSE) |
|
518 | - { |
|
519 | - self::log_error($err); |
|
520 | - if ($isDebug) |
|
521 | - { |
|
522 | - self::display_error($err, TRUE); |
|
523 | - } |
|
524 | - } |
|
525 | - |
|
526 | - public static function log_error($err) |
|
527 | - { |
|
528 | - error_log($err, 0); |
|
529 | - } |
|
530 | - |
|
531 | - public static function display_error($err, $kill = FALSE) |
|
532 | - { |
|
533 | - print_r($err); |
|
534 | - if ($kill === FALSE) |
|
535 | - { |
|
536 | - die(); |
|
537 | - } |
|
538 | - } |
|
517 | + public function __construct($err, $isDebug = FALSE) |
|
518 | + { |
|
519 | + self::log_error($err); |
|
520 | + if ($isDebug) |
|
521 | + { |
|
522 | + self::display_error($err, TRUE); |
|
523 | + } |
|
524 | + } |
|
525 | + |
|
526 | + public static function log_error($err) |
|
527 | + { |
|
528 | + error_log($err, 0); |
|
529 | + } |
|
530 | + |
|
531 | + public static function display_error($err, $kill = FALSE) |
|
532 | + { |
|
533 | + print_r($err); |
|
534 | + if ($kill === FALSE) |
|
535 | + { |
|
536 | + die(); |
|
537 | + } |
|
538 | + } |
|
539 | 539 | } |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | $last_access = ''; |
8 | 8 | // get the last time the user accessed the tool |
9 | 9 | if (isset($_SESSION[$_course['id']]) && $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] == '') { |
10 | - $last_access = get_last_tool_access(TOOL_DROPBOX); |
|
11 | - $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access; |
|
10 | + $last_access = get_last_tool_access(TOOL_DROPBOX); |
|
11 | + $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX] = $last_access; |
|
12 | 12 | } else { |
13 | - if (isset($_SESSION[$_course['id']])) { |
|
14 | - $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX]; |
|
15 | - } |
|
13 | + if (isset($_SESSION[$_course['id']])) { |
|
14 | + $last_access = $_SESSION[$_course['id']]['last_access'][TOOL_DROPBOX]; |
|
15 | + } |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $postAction = isset($_POST['action']) ? $_POST['action'] : null; |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | |
51 | 51 | // Display the form for adding a new dropbox item. |
52 | 52 | if ($action == 'add') { |
53 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
54 | - api_not_allowed(); |
|
55 | - } |
|
53 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
54 | + api_not_allowed(); |
|
55 | + } |
|
56 | 56 | display_add_form( |
57 | 57 | $dropbox_unid, |
58 | 58 | $viewReceivedCategory, |
@@ -62,56 +62,56 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | if (isset($_POST['submitWork'])) { |
65 | - $check = Security::check_token(); |
|
66 | - if ($check) { |
|
65 | + $check = Security::check_token(); |
|
66 | + if ($check) { |
|
67 | 67 | store_add_dropbox(); |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | // Display the form for adding a category |
72 | 72 | if ($action == 'addreceivedcategory' || $action == 'addsentcategory') { |
73 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
74 | - api_not_allowed(); |
|
75 | - } |
|
76 | - $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : ''; |
|
77 | - display_addcategory_form($categoryName, '', $_GET['action']); |
|
73 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
74 | + api_not_allowed(); |
|
75 | + } |
|
76 | + $categoryName = isset($_POST['category_name']) ? $_POST['category_name'] : ''; |
|
77 | + display_addcategory_form($categoryName, '', $_GET['action']); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Editing a category: displaying the form |
81 | 81 | if ($action == 'editcategory' && isset($_GET['id'])) { |
82 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
83 | - api_not_allowed(); |
|
84 | - } |
|
85 | - if (!$_POST) { |
|
86 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
87 | - api_not_allowed(); |
|
88 | - } |
|
89 | - display_addcategory_form('', $_GET['id'], 'editcategory'); |
|
90 | - } |
|
82 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
83 | + api_not_allowed(); |
|
84 | + } |
|
85 | + if (!$_POST) { |
|
86 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
87 | + api_not_allowed(); |
|
88 | + } |
|
89 | + display_addcategory_form('', $_GET['id'], 'editcategory'); |
|
90 | + } |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Storing a new or edited category |
94 | 94 | if (isset($_POST['StoreCategory'])) { |
95 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
96 | - api_not_allowed(); |
|
97 | - } |
|
98 | - $return_information = store_addcategory(); |
|
99 | - if ($return_information['type'] == 'confirmation') { |
|
100 | - Display :: display_confirmation_message($return_information['message']); |
|
101 | - } |
|
102 | - if ($return_information['type'] == 'error') { |
|
103 | - Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']); |
|
104 | - display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction); |
|
105 | - } |
|
95 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
96 | + api_not_allowed(); |
|
97 | + } |
|
98 | + $return_information = store_addcategory(); |
|
99 | + if ($return_information['type'] == 'confirmation') { |
|
100 | + Display :: display_confirmation_message($return_information['message']); |
|
101 | + } |
|
102 | + if ($return_information['type'] == 'error') { |
|
103 | + Display :: display_error_message(get_lang('FormHasErrorsPleaseComplete').'<br />'.$return_information['message']); |
|
104 | + display_addcategory_form($_POST['category_name'], $_POST['edit_id'], $postAction); |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | 109 | // Move a File |
110 | 110 | if (($action == 'movesent' || $action == 'movereceived') AND isset($_GET['move_id'])) { |
111 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
112 | - api_not_allowed(); |
|
113 | - } |
|
114 | - display_move_form( |
|
111 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
112 | + api_not_allowed(); |
|
113 | + } |
|
114 | + display_move_form( |
|
115 | 115 | str_replace('move', '', $action), |
116 | 116 | $_GET['move_id'], |
117 | 117 | get_dropbox_categories(str_replace('move', '', $action)), |
@@ -122,33 +122,33 @@ discard block |
||
122 | 122 | ); |
123 | 123 | } |
124 | 124 | if (isset($_POST['do_move'])) { |
125 | - Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part'])); |
|
125 | + Display :: display_confirmation_message(store_move($_POST['id'], $_POST['move_target'], $_POST['part'])); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Delete a file |
129 | 129 | if (($action == 'deletereceivedfile' || $action == 'deletesentfile') AND isset($_GET['id']) AND is_numeric($_GET['id'])) { |
130 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
131 | - api_not_allowed(); |
|
132 | - } |
|
133 | - $dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
134 | - if ($action == 'deletereceivedfile') { |
|
135 | - $dropboxfile->deleteReceivedWork($_GET['id']); |
|
136 | - $message = get_lang('ReceivedFileDeleted'); |
|
137 | - } |
|
138 | - if ($action == 'deletesentfile') { |
|
139 | - $dropboxfile->deleteSentWork($_GET['id']); |
|
140 | - $message = get_lang('SentFileDeleted'); |
|
141 | - } |
|
142 | - Display :: display_confirmation_message($message); |
|
130 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
131 | + api_not_allowed(); |
|
132 | + } |
|
133 | + $dropboxfile = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
134 | + if ($action == 'deletereceivedfile') { |
|
135 | + $dropboxfile->deleteReceivedWork($_GET['id']); |
|
136 | + $message = get_lang('ReceivedFileDeleted'); |
|
137 | + } |
|
138 | + if ($action == 'deletesentfile') { |
|
139 | + $dropboxfile->deleteSentWork($_GET['id']); |
|
140 | + $message = get_lang('SentFileDeleted'); |
|
141 | + } |
|
142 | + Display :: display_confirmation_message($message); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // Delete a category |
146 | 146 | if (($action == 'deletereceivedcategory' || $action == 'deletesentcategory') AND isset($_GET['id']) AND is_numeric($_GET['id'])) { |
147 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
148 | - api_not_allowed(); |
|
149 | - } |
|
150 | - $message = delete_category($action, $_GET['id']); |
|
151 | - Display :: display_confirmation_message($message); |
|
147 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
148 | + api_not_allowed(); |
|
149 | + } |
|
150 | + $message = delete_category($action, $_GET['id']); |
|
151 | + Display :: display_confirmation_message($message); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Do an action on multiple files |
@@ -163,27 +163,27 @@ discard block |
||
163 | 163 | $postAction == 'delete_sent' || |
164 | 164 | $postAction == 'download_sent') |
165 | 165 | ) { |
166 | - $display_message = handle_multiple_actions(); |
|
167 | - Display :: display_normal_message($display_message); |
|
166 | + $display_message = handle_multiple_actions(); |
|
167 | + Display :: display_normal_message($display_message); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // Store Feedback |
171 | 171 | |
172 | 172 | if (isset($_POST['feedback'])) { |
173 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
174 | - api_not_allowed(); |
|
175 | - } |
|
176 | - $check = Security::check_token(); |
|
177 | - if ($check) { |
|
178 | - $display_message = store_feedback(); |
|
179 | - Display :: display_normal_message($display_message); |
|
180 | - Security::check_token(); |
|
181 | - } |
|
173 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
174 | + api_not_allowed(); |
|
175 | + } |
|
176 | + $check = Security::check_token(); |
|
177 | + if ($check) { |
|
178 | + $display_message = store_feedback(); |
|
179 | + Display :: display_normal_message($display_message); |
|
180 | + Security::check_token(); |
|
181 | + } |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | // Error Message |
185 | 185 | if (isset($_GET['error']) AND !empty($_GET['error'])) { |
186 | - Display :: display_normal_message(get_lang($_GET['error'])); |
|
186 | + Display :: display_normal_message(get_lang($_GET['error'])); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | $dropbox_data_sent = array(); |
@@ -191,96 +191,96 @@ discard block |
||
191 | 191 | $dropbox_data_recieved = array(); |
192 | 192 | |
193 | 193 | if ($action != 'add') { |
194 | - // Getting all the categories in the dropbox for the given user |
|
195 | - $dropbox_categories = get_dropbox_categories(); |
|
196 | - // Greating the arrays with the categories for the received files and for the sent files |
|
197 | - foreach ($dropbox_categories as $category) { |
|
198 | - if ($category['received'] == '1') { |
|
199 | - $dropbox_received_category[] = $category; |
|
200 | - } |
|
201 | - if ($category['sent'] == '1') { |
|
202 | - $dropbox_sent_category[] = $category; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - // ACTIONS |
|
207 | - if ($view == 'received' || !$showSentReceivedTabs) { |
|
208 | - //echo '<h3>'.get_lang('ReceivedFiles').'</h3>'; |
|
209 | - |
|
210 | - // This is for the categories |
|
211 | - if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
212 | - $view_dropbox_category_received = $viewReceivedCategory; |
|
213 | - } else { |
|
214 | - $view_dropbox_category_received = 0; |
|
215 | - } |
|
216 | - |
|
217 | - /* Menu Received */ |
|
218 | - |
|
219 | - if (api_get_session_id() == 0) { |
|
220 | - echo '<div class="actions">'; |
|
221 | - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
222 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
223 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
224 | - $movelist[0] = 'Root'; // move_received selectbox content |
|
225 | - } else { |
|
226 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
227 | - } |
|
228 | - echo '</div>'; |
|
229 | - } else { |
|
230 | - if (api_is_allowed_to_session_edit(false, true)) { |
|
231 | - echo '<div class="actions">'; |
|
232 | - if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
233 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
234 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
235 | - $movelist[0] = 'Root'; // move_received selectbox content |
|
236 | - } else { |
|
237 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
238 | - } |
|
239 | - echo '</div>'; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
245 | - // This is for the categories |
|
246 | - if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
247 | - $view_dropbox_category_sent = $viewSentCategory; |
|
248 | - } else { |
|
249 | - $view_dropbox_category_sent = 0; |
|
250 | - } |
|
251 | - |
|
252 | - /* Menu Sent */ |
|
253 | - |
|
254 | - if (api_get_session_id() == 0) { |
|
255 | - echo '<div class="actions">'; |
|
256 | - if ($view_dropbox_category_sent != 0) { |
|
257 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
258 | - echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
259 | - } else { |
|
260 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
261 | - } |
|
262 | - if (empty($viewSentCategory)) { |
|
263 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
264 | - } |
|
265 | - echo '</div>'; |
|
266 | - } else { |
|
267 | - if (api_is_allowed_to_session_edit(false, true)) { |
|
268 | - echo '<div class="actions">'; |
|
269 | - if ($view_dropbox_category_sent != 0) { |
|
270 | - echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
271 | - echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
272 | - } else { |
|
273 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
274 | - } |
|
275 | - if (empty($viewSentCategory)) { |
|
276 | - echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
277 | - } |
|
278 | - echo '</div>'; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - /* THE MENU TABS */ |
|
283 | - if ($showSentReceivedTabs) { |
|
194 | + // Getting all the categories in the dropbox for the given user |
|
195 | + $dropbox_categories = get_dropbox_categories(); |
|
196 | + // Greating the arrays with the categories for the received files and for the sent files |
|
197 | + foreach ($dropbox_categories as $category) { |
|
198 | + if ($category['received'] == '1') { |
|
199 | + $dropbox_received_category[] = $category; |
|
200 | + } |
|
201 | + if ($category['sent'] == '1') { |
|
202 | + $dropbox_sent_category[] = $category; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + // ACTIONS |
|
207 | + if ($view == 'received' || !$showSentReceivedTabs) { |
|
208 | + //echo '<h3>'.get_lang('ReceivedFiles').'</h3>'; |
|
209 | + |
|
210 | + // This is for the categories |
|
211 | + if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
212 | + $view_dropbox_category_received = $viewReceivedCategory; |
|
213 | + } else { |
|
214 | + $view_dropbox_category_received = 0; |
|
215 | + } |
|
216 | + |
|
217 | + /* Menu Received */ |
|
218 | + |
|
219 | + if (api_get_session_id() == 0) { |
|
220 | + echo '<div class="actions">'; |
|
221 | + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
222 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
223 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
224 | + $movelist[0] = 'Root'; // move_received selectbox content |
|
225 | + } else { |
|
226 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
227 | + } |
|
228 | + echo '</div>'; |
|
229 | + } else { |
|
230 | + if (api_is_allowed_to_session_edit(false, true)) { |
|
231 | + echo '<div class="actions">'; |
|
232 | + if ($view_dropbox_category_received != 0 && api_is_allowed_to_session_edit(false, true)) { |
|
233 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category=0&view_sent_category='.$viewSentCategory.'&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
234 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_received]['cat_name']).'</strong> '; |
|
235 | + $movelist[0] = 'Root'; // move_received selectbox content |
|
236 | + } else { |
|
237 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=addreceivedcategory&view='.$view.'">'.Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM).'</a>'; |
|
238 | + } |
|
239 | + echo '</div>'; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
245 | + // This is for the categories |
|
246 | + if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
247 | + $view_dropbox_category_sent = $viewSentCategory; |
|
248 | + } else { |
|
249 | + $view_dropbox_category_sent = 0; |
|
250 | + } |
|
251 | + |
|
252 | + /* Menu Sent */ |
|
253 | + |
|
254 | + if (api_get_session_id() == 0) { |
|
255 | + echo '<div class="actions">'; |
|
256 | + if ($view_dropbox_category_sent != 0) { |
|
257 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
258 | + echo get_lang('Category').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
259 | + } else { |
|
260 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
261 | + } |
|
262 | + if (empty($viewSentCategory)) { |
|
263 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
264 | + } |
|
265 | + echo '</div>'; |
|
266 | + } else { |
|
267 | + if (api_is_allowed_to_session_edit(false, true)) { |
|
268 | + echo '<div class="actions">'; |
|
269 | + if ($view_dropbox_category_sent != 0) { |
|
270 | + echo get_lang('CurrentlySeeing').': <strong>'.Security::remove_XSS($dropbox_categories[$view_dropbox_category_sent]['cat_name']).'</strong> '; |
|
271 | + echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category=0&view='.$view.'">'.Display::return_icon('folder_up.png', get_lang('Up').' '.get_lang('Root'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
272 | + } else { |
|
273 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=addsentcategory\">".Display::return_icon('new_folder.png', get_lang('AddNewCategory'),'',ICON_SIZE_MEDIUM)."</a>\n"; |
|
274 | + } |
|
275 | + if (empty($viewSentCategory)) { |
|
276 | + echo "<a href=\"".api_get_self()."?".api_get_cidreq()."&view=".$view."&action=add\">".Display::return_icon('upload_file.png', get_lang('UploadNewFile'),'',ICON_SIZE_MEDIUM)."</a>"; |
|
277 | + } |
|
278 | + echo '</div>'; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + /* THE MENU TABS */ |
|
283 | + if ($showSentReceivedTabs) { |
|
284 | 284 | ?> |
285 | 285 | <ul class="nav nav-tabs"> |
286 | 286 | <li <?php if (!$view || $view == 'sent') { echo 'class="active"'; } ?> > |
@@ -294,80 +294,80 @@ discard block |
||
294 | 294 | </li> |
295 | 295 | </ul> |
296 | 296 | <?php |
297 | - } |
|
297 | + } |
|
298 | 298 | /* RECEIVED FILES */ |
299 | - if ($view == 'received' || !$showSentReceivedTabs) { |
|
300 | - // This is for the categories |
|
301 | - if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
302 | - $view_dropbox_category_received = $viewReceivedCategory; |
|
303 | - } else { |
|
304 | - $view_dropbox_category_received = 0; |
|
305 | - } |
|
306 | - |
|
307 | - // Object initialisation |
|
308 | - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
309 | - // note: are the $is_courseAdmin and $is_courseTutor parameters needed???? |
|
310 | - |
|
311 | - // Constructing the array that contains the total number of feedback messages per document. |
|
312 | - $number_feedback = get_total_number_feedback(); |
|
313 | - |
|
314 | - // Sorting and paging options |
|
315 | - $sorting_options = array(); |
|
316 | - $paging_options = array(); |
|
317 | - |
|
318 | - // The headers of the sortable tables |
|
319 | - $column_header = array(); |
|
320 | - $column_header[] = array('', false, ''); |
|
321 | - $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
322 | - $column_header[] = array(get_lang('ReceivedTitle'), true, ''); |
|
323 | - $column_header[] = array(get_lang('Size'), true, ''); |
|
324 | - $column_header[] = array(get_lang('Authors'), true, ''); |
|
325 | - $column_header[] = array(get_lang('LastResent'), true); |
|
326 | - |
|
327 | - if (api_get_session_id() == 0) { |
|
328 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
329 | - } elseif (api_is_allowed_to_session_edit(false,true)) { |
|
330 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
331 | - } |
|
332 | - |
|
333 | - $column_header[] = array('RealDate', true); |
|
334 | - $column_header[] = array('RealSize', true); |
|
335 | - |
|
336 | - // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
337 | - $column_show[] = 1; |
|
338 | - $column_show[] = 1; |
|
339 | - $column_show[] = 1; |
|
340 | - $column_show[] = 1; |
|
341 | - $column_show[] = 1; |
|
342 | - $column_show[] = 1; |
|
343 | - |
|
344 | - if (api_get_session_id() == 0) { |
|
345 | - $column_show[] = 1; |
|
346 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
347 | - $column_show[] = 1; |
|
348 | - } |
|
349 | - $column_show[] = 0; |
|
350 | - |
|
351 | - // Here we change the way how the columns are going to be sort |
|
352 | - // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
353 | - // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
354 | - |
|
355 | - $column_order[3] = 8; |
|
356 | - $column_order[5] = 7; |
|
357 | - |
|
358 | - // The content of the sortable table = the received files |
|
359 | - foreach ($dropbox_person -> receivedWork as $dropbox_file) { |
|
360 | - $dropbox_file_data = array(); |
|
361 | - if ($view_dropbox_category_received == $dropbox_file->category) { |
|
299 | + if ($view == 'received' || !$showSentReceivedTabs) { |
|
300 | + // This is for the categories |
|
301 | + if (isset($viewReceivedCategory) AND $viewReceivedCategory != '') { |
|
302 | + $view_dropbox_category_received = $viewReceivedCategory; |
|
303 | + } else { |
|
304 | + $view_dropbox_category_received = 0; |
|
305 | + } |
|
306 | + |
|
307 | + // Object initialisation |
|
308 | + $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
309 | + // note: are the $is_courseAdmin and $is_courseTutor parameters needed???? |
|
310 | + |
|
311 | + // Constructing the array that contains the total number of feedback messages per document. |
|
312 | + $number_feedback = get_total_number_feedback(); |
|
313 | + |
|
314 | + // Sorting and paging options |
|
315 | + $sorting_options = array(); |
|
316 | + $paging_options = array(); |
|
317 | + |
|
318 | + // The headers of the sortable tables |
|
319 | + $column_header = array(); |
|
320 | + $column_header[] = array('', false, ''); |
|
321 | + $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
322 | + $column_header[] = array(get_lang('ReceivedTitle'), true, ''); |
|
323 | + $column_header[] = array(get_lang('Size'), true, ''); |
|
324 | + $column_header[] = array(get_lang('Authors'), true, ''); |
|
325 | + $column_header[] = array(get_lang('LastResent'), true); |
|
326 | + |
|
327 | + if (api_get_session_id() == 0) { |
|
328 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
329 | + } elseif (api_is_allowed_to_session_edit(false,true)) { |
|
330 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
331 | + } |
|
332 | + |
|
333 | + $column_header[] = array('RealDate', true); |
|
334 | + $column_header[] = array('RealSize', true); |
|
335 | + |
|
336 | + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
337 | + $column_show[] = 1; |
|
338 | + $column_show[] = 1; |
|
339 | + $column_show[] = 1; |
|
340 | + $column_show[] = 1; |
|
341 | + $column_show[] = 1; |
|
342 | + $column_show[] = 1; |
|
343 | + |
|
344 | + if (api_get_session_id() == 0) { |
|
345 | + $column_show[] = 1; |
|
346 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
347 | + $column_show[] = 1; |
|
348 | + } |
|
349 | + $column_show[] = 0; |
|
350 | + |
|
351 | + // Here we change the way how the columns are going to be sort |
|
352 | + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
353 | + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
354 | + |
|
355 | + $column_order[3] = 8; |
|
356 | + $column_order[5] = 7; |
|
357 | + |
|
358 | + // The content of the sortable table = the received files |
|
359 | + foreach ($dropbox_person -> receivedWork as $dropbox_file) { |
|
360 | + $dropbox_file_data = array(); |
|
361 | + if ($view_dropbox_category_received == $dropbox_file->category) { |
|
362 | 362 | // we only display the files that are in the category that we are in. |
363 | - $dropbox_file_data[] = $dropbox_file->id; |
|
363 | + $dropbox_file_data[] = $dropbox_file->id; |
|
364 | 364 | |
365 | - if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) { |
|
366 | - $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array(); |
|
367 | - } |
|
365 | + if (isset($_SESSION['_seen']) && !is_array($_SESSION['_seen'][$_course['id']][TOOL_DROPBOX])) { |
|
366 | + $_SESSION['_seen'][$_course['id']][TOOL_DROPBOX] = array(); |
|
367 | + } |
|
368 | 368 | |
369 | - // New icon |
|
370 | - $new_icon = ''; |
|
369 | + // New icon |
|
370 | + $new_icon = ''; |
|
371 | 371 | if (isset($_SESSION['_seen'])) { |
372 | 372 | if ($dropbox_file->last_upload_date > $last_access && |
373 | 373 | !in_array( |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | } |
385 | 385 | } |
386 | 386 | |
387 | - $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
388 | - $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
389 | - $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
387 | + $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
388 | + $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
389 | + $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
390 | 390 | Display::return_icon('save.png', get_lang('Download'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a>'.$new_icon.'<br />'.$dropbox_file->description; |
391 | - $file_size = $dropbox_file->filesize; |
|
392 | - $dropbox_file_data[] = format_file_size($file_size); |
|
391 | + $file_size = $dropbox_file->filesize; |
|
392 | + $dropbox_file_data[] = format_file_size($file_size); |
|
393 | 393 | |
394 | 394 | $authorInfo = api_get_user_info($dropbox_file->uploader_id); |
395 | 395 | if ($authorInfo) { |
@@ -398,62 +398,62 @@ discard block |
||
398 | 398 | $dropbox_file_data[] = ''; |
399 | 399 | } |
400 | 400 | |
401 | - $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
402 | - $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
401 | + $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
402 | + $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
403 | 403 | api_format_date($last_upload_date).'</span>'; |
404 | 404 | |
405 | - $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
405 | + $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
406 | 406 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a> |
407 | 407 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movereceived&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a> |
408 | 408 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'. |
409 | 409 | Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
410 | 410 | |
411 | - // This is a hack to have an additional row in a sortable table |
|
412 | - |
|
413 | - if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) { |
|
414 | - $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table |
|
415 | - $action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
416 | - } |
|
417 | - if (api_get_session_id() == 0) { |
|
418 | - $dropbox_file_data[] = $action_icons; |
|
419 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
420 | - $dropbox_file_data[] = $action_icons; |
|
421 | - } |
|
422 | - $action_icons = ''; |
|
423 | - $dropbox_file_data[] = $last_upload_date; |
|
424 | - $dropbox_file_data[] = $file_size; |
|
425 | - $dropbox_data_recieved[] = $dropbox_file_data; |
|
426 | - } |
|
427 | - } |
|
428 | - |
|
429 | - // The content of the sortable table = the categories (if we are not in the root) |
|
430 | - if ($view_dropbox_category_received == 0) { |
|
431 | - foreach ($dropbox_categories as $category) { |
|
432 | - /* Note: This can probably be shortened since the categories |
|
411 | + // This is a hack to have an additional row in a sortable table |
|
412 | + |
|
413 | + if ($action == 'viewfeedback' AND isset($_GET['id']) and is_numeric($_GET['id']) AND $dropbox_file->id == $_GET['id']) { |
|
414 | + $action_icons .= "</td></tr>"; // Ending the normal row of the sortable table |
|
415 | + $action_icons .= '<tr><td colspan="2"><a href="'.api_get_path(WEB_CODE_PATH).'dropbox/index.php?"'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a></td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
416 | + } |
|
417 | + if (api_get_session_id() == 0) { |
|
418 | + $dropbox_file_data[] = $action_icons; |
|
419 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
420 | + $dropbox_file_data[] = $action_icons; |
|
421 | + } |
|
422 | + $action_icons = ''; |
|
423 | + $dropbox_file_data[] = $last_upload_date; |
|
424 | + $dropbox_file_data[] = $file_size; |
|
425 | + $dropbox_data_recieved[] = $dropbox_file_data; |
|
426 | + } |
|
427 | + } |
|
428 | + |
|
429 | + // The content of the sortable table = the categories (if we are not in the root) |
|
430 | + if ($view_dropbox_category_received == 0) { |
|
431 | + foreach ($dropbox_categories as $category) { |
|
432 | + /* Note: This can probably be shortened since the categories |
|
433 | 433 | for the received files are already in the |
434 | 434 | $dropbox_received_category array;*/ |
435 | - $dropbox_category_data = array(); |
|
436 | - if ($category['received'] == '1') { |
|
437 | - $movelist[$category['cat_id']] = $category['cat_name']; |
|
435 | + $dropbox_category_data = array(); |
|
436 | + if ($category['received'] == '1') { |
|
437 | + $movelist[$category['cat_id']] = $category['cat_name']; |
|
438 | 438 | // This is where the checkbox icon for the files appear |
439 | - $dropbox_category_data[] = $category['cat_id']; |
|
440 | - // The icon of the category |
|
441 | - $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">'; |
|
442 | - $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>'; |
|
443 | - $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>'; |
|
444 | - $dropbox_category_data[] = ''; |
|
445 | - $dropbox_category_data[] = ''; |
|
446 | - $dropbox_category_data[] = ''; |
|
447 | - $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
|
439 | + $dropbox_category_data[] = $category['cat_id']; |
|
440 | + // The icon of the category |
|
441 | + $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$category['cat_id'].'&view_sent_category='.$viewSentCategory.'&view='.$view.'">'; |
|
442 | + $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', $category['cat_name']).'</a>'; |
|
443 | + $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=received">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$category['cat_name'].'</a>'; |
|
444 | + $dropbox_category_data[] = ''; |
|
445 | + $dropbox_category_data[] = ''; |
|
446 | + $dropbox_category_data[] = ''; |
|
447 | + $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
|
448 | 448 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletereceivedcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
449 | - } |
|
450 | - if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
451 | - $dropbox_data_recieved[] = $dropbox_category_data; |
|
452 | - } |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - // Displaying the table |
|
449 | + } |
|
450 | + if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
451 | + $dropbox_data_recieved[] = $dropbox_category_data; |
|
452 | + } |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + // Displaying the table |
|
457 | 457 | $additional_get_parameters = array( |
458 | 458 | 'view' => $view, |
459 | 459 | 'view_received_category' => $viewReceivedCategory, |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | 'download_received' => get_lang('Download') |
465 | 465 | ); |
466 | 466 | |
467 | - if (is_array($movelist)) { |
|
468 | - foreach ($movelist as $catid => $catname){ |
|
469 | - $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname); |
|
470 | - } |
|
471 | - } |
|
467 | + if (is_array($movelist)) { |
|
468 | + foreach ($movelist as $catid => $catname){ |
|
469 | + $selectlist['move_received_'.$catid] = get_lang('Move') . '->'. Security::remove_XSS($catname); |
|
470 | + } |
|
471 | + } |
|
472 | 472 | |
473 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
474 | - $selectlist = array(); |
|
475 | - } |
|
473 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
474 | + $selectlist = array(); |
|
475 | + } |
|
476 | 476 | echo '<div class="files-table">'; |
477 | 477 | Display::display_sortable_config_table( |
478 | 478 | 'dropbox', |
@@ -486,154 +486,154 @@ discard block |
||
486 | 486 | $selectlist |
487 | 487 | ); |
488 | 488 | echo '</div>'; |
489 | - } |
|
490 | - |
|
491 | - /* SENT FILES */ |
|
492 | - |
|
493 | - if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
494 | - // This is for the categories |
|
495 | - if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
496 | - $view_dropbox_category_sent = $viewSentCategory; |
|
497 | - } else { |
|
498 | - $view_dropbox_category_sent = 0; |
|
499 | - } |
|
500 | - |
|
501 | - // Object initialisation |
|
502 | - $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
503 | - |
|
504 | - // Constructing the array that contains the total number of feedback messages per document. |
|
505 | - $number_feedback = get_total_number_feedback(); |
|
506 | - |
|
507 | - // Sorting and paging options |
|
508 | - $sorting_options = array(); |
|
509 | - $paging_options = array(); |
|
510 | - |
|
511 | - // The headers of the sortable tables |
|
512 | - $column_header = array(); |
|
513 | - |
|
514 | - $column_header[] = array('', false, ''); |
|
515 | - $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
516 | - $column_header[] = array(get_lang('SentTitle'), true, ''); |
|
517 | - $column_header[] = array(get_lang('Size'), true, ''); |
|
518 | - $column_header[] = array(get_lang('SentTo'), true, ''); |
|
519 | - $column_header[] = array(get_lang('LastResent'), true, ''); |
|
520 | - |
|
521 | - if (api_get_session_id() == 0) { |
|
522 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
523 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
524 | - $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
525 | - } |
|
526 | - |
|
527 | - $column_header[] = array('RealDate', true); |
|
528 | - $column_header[] = array('RealSize', true); |
|
529 | - |
|
530 | - $column_show = array(); |
|
531 | - $column_order = array(); |
|
532 | - |
|
533 | - // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
534 | - $column_show[] = 1; |
|
535 | - $column_show[] = 1; |
|
536 | - $column_show[] = 1; |
|
537 | - $column_show[] = 1; |
|
538 | - $column_show[] = 1; |
|
539 | - $column_show[] = 1; |
|
540 | - if (api_get_session_id() == 0) { |
|
541 | - $column_show[] = 1; |
|
542 | - } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
543 | - $column_show[] = 1; |
|
544 | - } |
|
545 | - $column_show[] = 0; |
|
546 | - |
|
547 | - // Here we change the way how the colums are going to be sort |
|
548 | - // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
549 | - // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
550 | - |
|
551 | - $column_order[3] = 8; |
|
552 | - $column_order[5] = 7; |
|
553 | - |
|
554 | - // The content of the sortable table = the received files |
|
555 | - foreach ($dropbox_person->sentWork as $dropbox_file) { |
|
556 | - $dropbox_file_data = array(); |
|
557 | - |
|
558 | - if ($view_dropbox_category_sent == $dropbox_file->category) { |
|
559 | - $dropbox_file_data[] = $dropbox_file->id; |
|
560 | - $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
561 | - $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
562 | - $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
489 | + } |
|
490 | + |
|
491 | + /* SENT FILES */ |
|
492 | + |
|
493 | + if (!$view || $view == 'sent' || !$showSentReceivedTabs) { |
|
494 | + // This is for the categories |
|
495 | + if (isset($viewSentCategory) AND $viewSentCategory != '') { |
|
496 | + $view_dropbox_category_sent = $viewSentCategory; |
|
497 | + } else { |
|
498 | + $view_dropbox_category_sent = 0; |
|
499 | + } |
|
500 | + |
|
501 | + // Object initialisation |
|
502 | + $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); |
|
503 | + |
|
504 | + // Constructing the array that contains the total number of feedback messages per document. |
|
505 | + $number_feedback = get_total_number_feedback(); |
|
506 | + |
|
507 | + // Sorting and paging options |
|
508 | + $sorting_options = array(); |
|
509 | + $paging_options = array(); |
|
510 | + |
|
511 | + // The headers of the sortable tables |
|
512 | + $column_header = array(); |
|
513 | + |
|
514 | + $column_header[] = array('', false, ''); |
|
515 | + $column_header[] = array(get_lang('Type'), true, 'style="width:40px"', 'style="text-align:center"'); |
|
516 | + $column_header[] = array(get_lang('SentTitle'), true, ''); |
|
517 | + $column_header[] = array(get_lang('Size'), true, ''); |
|
518 | + $column_header[] = array(get_lang('SentTo'), true, ''); |
|
519 | + $column_header[] = array(get_lang('LastResent'), true, ''); |
|
520 | + |
|
521 | + if (api_get_session_id() == 0) { |
|
522 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
523 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
524 | + $column_header[] = array(get_lang('Modify'), false, '', 'nowrap style="text-align: right"'); |
|
525 | + } |
|
526 | + |
|
527 | + $column_header[] = array('RealDate', true); |
|
528 | + $column_header[] = array('RealSize', true); |
|
529 | + |
|
530 | + $column_show = array(); |
|
531 | + $column_order = array(); |
|
532 | + |
|
533 | + // An array with the setting of the columns -> 1: columns that we will show, 0:columns that will be hide |
|
534 | + $column_show[] = 1; |
|
535 | + $column_show[] = 1; |
|
536 | + $column_show[] = 1; |
|
537 | + $column_show[] = 1; |
|
538 | + $column_show[] = 1; |
|
539 | + $column_show[] = 1; |
|
540 | + if (api_get_session_id() == 0) { |
|
541 | + $column_show[] = 1; |
|
542 | + } elseif (api_is_allowed_to_session_edit(false, true)) { |
|
543 | + $column_show[] = 1; |
|
544 | + } |
|
545 | + $column_show[] = 0; |
|
546 | + |
|
547 | + // Here we change the way how the colums are going to be sort |
|
548 | + // in this case the the column of LastResent ( 4th element in $column_header) we will be order like the column RealDate |
|
549 | + // because in the column RealDate we have the days in a correct format "2008-03-12 10:35:48" |
|
550 | + |
|
551 | + $column_order[3] = 8; |
|
552 | + $column_order[5] = 7; |
|
553 | + |
|
554 | + // The content of the sortable table = the received files |
|
555 | + foreach ($dropbox_person->sentWork as $dropbox_file) { |
|
556 | + $dropbox_file_data = array(); |
|
557 | + |
|
558 | + if ($view_dropbox_category_sent == $dropbox_file->category) { |
|
559 | + $dropbox_file_data[] = $dropbox_file->id; |
|
560 | + $link_open = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'">'; |
|
561 | + $dropbox_file_data[] = $link_open.DocumentManager::build_document_icon_tag('file', $dropbox_file->title).'</a>'; |
|
562 | + $dropbox_file_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&id='.$dropbox_file->id.'&action=download">'. |
|
563 | 563 | Display::return_icon('save.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.$dropbox_file->title.'</a><br />'.$dropbox_file->description; |
564 | - $file_size = $dropbox_file->filesize; |
|
565 | - $dropbox_file_data[] = format_file_size($file_size); |
|
564 | + $file_size = $dropbox_file->filesize; |
|
565 | + $dropbox_file_data[] = format_file_size($file_size); |
|
566 | 566 | $receivers_celldata = null; |
567 | - foreach ($dropbox_file->recipients as $recipient) { |
|
568 | - $userInfo = api_get_user_info($recipient['user_id']); |
|
569 | - $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata; |
|
570 | - } |
|
571 | - $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma. |
|
572 | - $dropbox_file_data[] = $receivers_celldata; |
|
573 | - $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
574 | - $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
575 | - api_format_date($last_upload_date).'</span>'; |
|
576 | - |
|
577 | - //$dropbox_file_data[] = $dropbox_file->author; |
|
578 | - $receivers_celldata = ''; |
|
579 | - |
|
580 | - $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
567 | + foreach ($dropbox_file->recipients as $recipient) { |
|
568 | + $userInfo = api_get_user_info($recipient['user_id']); |
|
569 | + $receivers_celldata = UserManager::getUserProfileLink($userInfo).', '.$receivers_celldata; |
|
570 | + } |
|
571 | + $receivers_celldata = trim(trim($receivers_celldata), ','); // Removing the trailing comma. |
|
572 | + $dropbox_file_data[] = $receivers_celldata; |
|
573 | + $last_upload_date = api_get_local_time($dropbox_file->last_upload_date); |
|
574 | + $dropbox_file_data[] = date_to_str_ago($dropbox_file->last_upload_date).'<br /><span class="dropbox_date">'. |
|
575 | + api_format_date($last_upload_date).'</span>'; |
|
576 | + |
|
577 | + //$dropbox_file_data[] = $dropbox_file->author; |
|
578 | + $receivers_celldata = ''; |
|
579 | + |
|
580 | + $action_icons = check_number_feedback($dropbox_file->id, $number_feedback).' '.get_lang('Feedback').' |
|
581 | 581 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=viewfeedback&id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('discuss.png', get_lang('Comment'),'',ICON_SIZE_SMALL).'</a> |
582 | 582 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=movesent&move_id='.$dropbox_file->id.'&'.$sort_params.'">'.Display::return_icon('move.png', get_lang('Move'),'',ICON_SIZE_SMALL).'</a> |
583 | 583 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentfile&id='.$dropbox_file->id.'&'.$sort_params.'" onclick="javascript: return confirmation(\''.$dropbox_file->title.'\');">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
584 | - // This is a hack to have an additional row in a sortable table |
|
585 | - if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) { |
|
586 | - $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table |
|
587 | - $action_icons .= "<tr><td colspan=\"2\">"; |
|
588 | - $action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>"; |
|
589 | - $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
590 | - } |
|
591 | - $dropbox_file_data[] = $action_icons; |
|
592 | - $dropbox_file_data[] = $last_upload_date; |
|
593 | - $dropbox_file_data[] = $file_size; |
|
594 | - $action_icons = ''; |
|
595 | - $dropbox_data_sent[] = $dropbox_file_data; |
|
596 | - } |
|
597 | - } |
|
584 | + // This is a hack to have an additional row in a sortable table |
|
585 | + if ($action == 'viewfeedback' && isset($_GET['id']) && is_numeric($_GET['id']) && $dropbox_file->id == $_GET['id']) { |
|
586 | + $action_icons .= "</td></tr>\n"; // ending the normal row of the sortable table |
|
587 | + $action_icons .= "<tr><td colspan=\"2\">"; |
|
588 | + $action_icons .= "<a href=\"".api_get_path(WEB_CODE_PATH)."dropbox/index.php?".api_get_cidreq()."&view_received_category=".$viewReceivedCategory."&view_sent_category=".$viewSentCategory."&view=".$view.'&'.$sort_params."\">".get_lang('CloseFeedback')."</a>"; |
|
589 | + $action_icons .= "</td><td colspan=\"7\">".feedback($dropbox_file->feedback2)."</td></tr>"; |
|
590 | + } |
|
591 | + $dropbox_file_data[] = $action_icons; |
|
592 | + $dropbox_file_data[] = $last_upload_date; |
|
593 | + $dropbox_file_data[] = $file_size; |
|
594 | + $action_icons = ''; |
|
595 | + $dropbox_data_sent[] = $dropbox_file_data; |
|
596 | + } |
|
597 | + } |
|
598 | 598 | |
599 | 599 | $moveList = array(); |
600 | - // The content of the sortable table = the categories (if we are not in the root) |
|
601 | - if ($view_dropbox_category_sent == 0) { |
|
602 | - foreach ($dropbox_categories as $category) { |
|
603 | - $dropbox_category_data = array(); |
|
600 | + // The content of the sortable table = the categories (if we are not in the root) |
|
601 | + if ($view_dropbox_category_sent == 0) { |
|
602 | + foreach ($dropbox_categories as $category) { |
|
603 | + $dropbox_category_data = array(); |
|
604 | 604 | |
605 | - if ($category['sent'] == '1') { |
|
605 | + if ($category['sent'] == '1') { |
|
606 | 606 | |
607 | 607 | $moveList[$category['cat_id']] = $category['cat_name']; |
608 | - $dropbox_category_data[] = $category['cat_id']; |
|
609 | - // This is where the checkbox icon for the files appear. |
|
610 | - $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">'; |
|
611 | - $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>'; |
|
612 | - $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>'; |
|
613 | - //$dropbox_category_data[] = ''; |
|
614 | - $dropbox_category_data[] = ''; |
|
615 | - //$dropbox_category_data[] = ''; |
|
616 | - $dropbox_category_data[] = ''; |
|
617 | - $dropbox_category_data[] = ''; |
|
618 | - $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'. |
|
608 | + $dropbox_category_data[] = $category['cat_id']; |
|
609 | + // This is where the checkbox icon for the files appear. |
|
610 | + $link_open = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$category['cat_id'].'&view='.$view.'">'; |
|
611 | + $dropbox_category_data[] = $link_open.DocumentManager::build_document_icon_tag('folder', Security::remove_XSS($category['cat_name'])).'</a>'; |
|
612 | + $dropbox_category_data[] = '<a href="'.api_get_path(WEB_CODE_PATH).'dropbox/dropbox_download.php?'.api_get_cidreq().'&cat_id='.$category['cat_id'].'&action=downloadcategory&sent_received=sent">'.Display::return_icon('save_pack.png', get_lang('Save'), array('style' => 'float:right;'),ICON_SIZE_SMALL).'</a>'.$link_open.Security::remove_XSS($category['cat_name']).'</a>'; |
|
613 | + //$dropbox_category_data[] = ''; |
|
614 | + $dropbox_category_data[] = ''; |
|
615 | + //$dropbox_category_data[] = ''; |
|
616 | + $dropbox_category_data[] = ''; |
|
617 | + $dropbox_category_data[] = ''; |
|
618 | + $dropbox_category_data[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=editcategory&id='.$category['cat_id'].'">'. |
|
619 | 619 | Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a> |
620 | 620 | <a href="'.api_get_self().'?'.api_get_cidreq().'&view_received_category='.$viewReceivedCategory.'&view_sent_category='.$viewSentCategory.'&view='.$view.'&action=deletesentcategory&id='.$category['cat_id'].'" onclick="javascript: return confirmation(\''.Security::remove_XSS($category['cat_name']).'\');">'. |
621 | 621 | Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'; |
622 | - } |
|
623 | - if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
624 | - $dropbox_data_sent[] = $dropbox_category_data; |
|
625 | - } |
|
626 | - } |
|
627 | - } |
|
628 | - |
|
629 | - // Displaying the table |
|
630 | - $additional_get_parameters = array( |
|
622 | + } |
|
623 | + if (is_array($dropbox_category_data) && count($dropbox_category_data) > 0) { |
|
624 | + $dropbox_data_sent[] = $dropbox_category_data; |
|
625 | + } |
|
626 | + } |
|
627 | + } |
|
628 | + |
|
629 | + // Displaying the table |
|
630 | + $additional_get_parameters = array( |
|
631 | 631 | 'view' => $view, |
632 | 632 | 'view_received_category' => $viewReceivedCategory, |
633 | 633 | 'view_sent_category' => $viewSentCategory |
634 | 634 | ); |
635 | 635 | |
636 | - $selectlist = array( |
|
636 | + $selectlist = array( |
|
637 | 637 | 'delete_received' => get_lang('Delete'), |
638 | 638 | 'download_received' => get_lang('Download') |
639 | 639 | ); |
@@ -644,12 +644,12 @@ discard block |
||
644 | 644 | } |
645 | 645 | } |
646 | 646 | |
647 | - if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
648 | - $selectlist = array('download_received' => get_lang('Download')); |
|
649 | - } |
|
647 | + if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
|
648 | + $selectlist = array('download_received' => get_lang('Download')); |
|
649 | + } |
|
650 | 650 | |
651 | 651 | echo '<div class="files-table">'; |
652 | - Display::display_sortable_config_table( |
|
652 | + Display::display_sortable_config_table( |
|
653 | 653 | 'dropbox', |
654 | 654 | $column_header, |
655 | 655 | $dropbox_data_sent, |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | $selectlist |
662 | 662 | ); |
663 | 663 | echo '</div>'; |
664 | - } |
|
664 | + } |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | Display::display_footer(); |
@@ -76,20 +76,20 @@ discard block |
||
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * private function creating a new work object |
|
81 | - * |
|
82 | - * @param int $uploader_id |
|
83 | - * @param string $title |
|
84 | - * @param string $description |
|
85 | - * @param string $author |
|
86 | - * @param string $filename |
|
87 | - * @param int $filesize |
|
88 | - * |
|
89 | - * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
90 | - * As a consequence this parameter can be removed |
|
91 | - */ |
|
92 | - public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
79 | + /** |
|
80 | + * private function creating a new work object |
|
81 | + * |
|
82 | + * @param int $uploader_id |
|
83 | + * @param string $title |
|
84 | + * @param string $description |
|
85 | + * @param string $author |
|
86 | + * @param string $filename |
|
87 | + * @param int $filesize |
|
88 | + * |
|
89 | + * @todo $author was originally a field but this has now been replaced by the first and lastname of the uploader (to prevent anonymous uploads) |
|
90 | + * As a consequence this parameter can be removed |
|
91 | + */ |
|
92 | + public function _createNewWork($uploader_id, $title, $description, $author, $filename, $filesize) |
|
93 | 93 | { |
94 | 94 | // Fill in the properties |
95 | 95 | $this->uploader_id = intval($uploader_id); |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | // Check if object exists already. If it does, the old object is used |
105 | 105 | // with updated information (authors, description, upload_date) |
106 | 106 | $this->isOldWork = false; |
107 | - $sql = "SELECT id, upload_date FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
107 | + $sql = "SELECT id, upload_date FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
108 | 108 | WHERE c_id = $course_id AND filename = '".Database::escape_string($this->filename)."'"; |
109 | 109 | $result = Database::query($sql); |
110 | - $res = Database::fetch_array($result); |
|
111 | - if ($res) { |
|
112 | - $this->isOldWork = true; |
|
113 | - } |
|
114 | - // Insert or update the dropbox_file table and set the id property |
|
115 | - if ($this->isOldWork) { |
|
116 | - $this->id = $res['id']; |
|
117 | - $this->upload_date = $res['upload_date']; |
|
110 | + $res = Database::fetch_array($result); |
|
111 | + if ($res) { |
|
112 | + $this->isOldWork = true; |
|
113 | + } |
|
114 | + // Insert or update the dropbox_file table and set the id property |
|
115 | + if ($this->isOldWork) { |
|
116 | + $this->id = $res['id']; |
|
117 | + $this->upload_date = $res['upload_date']; |
|
118 | 118 | |
119 | 119 | $params = [ |
120 | 120 | 'filesize' => $this->filesize, |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | $params, |
131 | 131 | ['c_id = ? AND id = ?' => [$course_id, $this->id]] |
132 | 132 | ); |
133 | - } else { |
|
134 | - $this->upload_date = $this->last_upload_date; |
|
135 | - $params = [ |
|
133 | + } else { |
|
134 | + $this->upload_date = $this->last_upload_date; |
|
135 | + $params = [ |
|
136 | 136 | 'c_id' => $course_id, |
137 | 137 | 'uploader_id' => $this->uploader_id, |
138 | 138 | 'filename' => $this->filename, |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | 'last_upload_date' => $this->last_upload_date, |
145 | 145 | 'session_id' => api_get_session_id(), |
146 | 146 | 'cat_id' => 0 |
147 | - ]; |
|
147 | + ]; |
|
148 | 148 | |
149 | - $this->id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FILE), $params); |
|
150 | - if ($this->id) { |
|
151 | - $sql = "UPDATE ". Database::get_course_table(TABLE_DROPBOX_FILE) ." SET id = iid WHERE iid = {$this->id}"; |
|
152 | - Database::query($sql); |
|
153 | - } |
|
154 | - } |
|
149 | + $this->id = Database::insert(Database::get_course_table(TABLE_DROPBOX_FILE), $params); |
|
150 | + if ($this->id) { |
|
151 | + $sql = "UPDATE ". Database::get_course_table(TABLE_DROPBOX_FILE) ." SET id = iid WHERE iid = {$this->id}"; |
|
152 | + Database::query($sql); |
|
153 | + } |
|
154 | + } |
|
155 | 155 | |
156 | 156 | $sql = "SELECT count(file_id) as count |
157 | 157 | FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
@@ -165,16 +165,16 @@ discard block |
||
165 | 165 | VALUES ($course_id, ".intval($this->id)." , ".intval($this->uploader_id).")"; |
166 | 166 | Database::query($sql); |
167 | 167 | } |
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * private function creating existing object by retreiving info from db |
|
172 | - * |
|
173 | - * @param int $id |
|
174 | - */ |
|
175 | - public function _createExistingWork($id) |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * private function creating existing object by retreiving info from db |
|
172 | + * |
|
173 | + * @param int $id |
|
174 | + */ |
|
175 | + public function _createExistingWork($id) |
|
176 | 176 | { |
177 | - $course_id = api_get_course_int_id(); |
|
177 | + $course_id = api_get_course_int_id(); |
|
178 | 178 | |
179 | 179 | $action = isset($_GET['action']) ? $_GET['action'] : null; |
180 | 180 | |
@@ -222,52 +222,52 @@ discard block |
||
222 | 222 | } |
223 | 223 | $this->feedback2= $feedback2; |
224 | 224 | } |
225 | - } |
|
225 | + } |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | class Dropbox_SentWork extends Dropbox_Work |
229 | 229 | { |
230 | - public $recipients; //array of ['id']['name'] arrays |
|
231 | - |
|
232 | - /** |
|
233 | - * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
234 | - * depending on the number of parameters |
|
235 | - * |
|
236 | - * @param unknown_type $arg1 |
|
237 | - * @param unknown_type $arg2 |
|
238 | - * @param unknown_type $arg3 |
|
239 | - * @param unknown_type $arg4 |
|
240 | - * @param unknown_type $arg5 |
|
241 | - * @param unknown_type $arg6 |
|
242 | - * @param unknown_type $arg7 |
|
243 | - * @return Dropbox_SentWork |
|
244 | - */ |
|
245 | - public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
230 | + public $recipients; //array of ['id']['name'] arrays |
|
231 | + |
|
232 | + /** |
|
233 | + * Constructor calls private functions to create a new work or retreive an existing work from DB |
|
234 | + * depending on the number of parameters |
|
235 | + * |
|
236 | + * @param unknown_type $arg1 |
|
237 | + * @param unknown_type $arg2 |
|
238 | + * @param unknown_type $arg3 |
|
239 | + * @param unknown_type $arg4 |
|
240 | + * @param unknown_type $arg5 |
|
241 | + * @param unknown_type $arg6 |
|
242 | + * @param unknown_type $arg7 |
|
243 | + * @return Dropbox_SentWork |
|
244 | + */ |
|
245 | + public function __construct($arg1, $arg2 = null, $arg3 = null, $arg4 = null, $arg5 = null, $arg6 = null, $arg7 = null) |
|
246 | 246 | { |
247 | - if (func_num_args() > 1) { |
|
248 | - $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
249 | - } else { |
|
250 | - $this->_createExistingSentWork($arg1); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * private function creating a new SentWork object |
|
256 | - * |
|
257 | - * @param int $uploader_id |
|
258 | - * @param string $title |
|
259 | - * @param string $description |
|
260 | - * @param string $author |
|
261 | - * @param string $filename |
|
262 | - * @param int $filesize |
|
263 | - * @param array $recipient_ids |
|
264 | - */ |
|
265 | - public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
247 | + if (func_num_args() > 1) { |
|
248 | + $this->_createNewSentWork($arg1, $arg2, $arg3, $arg4, $arg5, $arg6, $arg7); |
|
249 | + } else { |
|
250 | + $this->_createExistingSentWork($arg1); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * private function creating a new SentWork object |
|
256 | + * |
|
257 | + * @param int $uploader_id |
|
258 | + * @param string $title |
|
259 | + * @param string $description |
|
260 | + * @param string $author |
|
261 | + * @param string $filename |
|
262 | + * @param int $filesize |
|
263 | + * @param array $recipient_ids |
|
264 | + */ |
|
265 | + public function _createNewSentWork($uploader_id, $title, $description, $author, $filename, $filesize, $recipient_ids) |
|
266 | 266 | { |
267 | 267 | $dropbox_cnf = getDropboxConf(); |
268 | 268 | $_course = api_get_course_info(); |
269 | 269 | |
270 | - // Call constructor of Dropbox_Work object |
|
270 | + // Call constructor of Dropbox_Work object |
|
271 | 271 | parent::__construct( |
272 | 272 | $uploader_id, |
273 | 273 | $title, |
@@ -277,33 +277,33 @@ discard block |
||
277 | 277 | $filesize |
278 | 278 | ); |
279 | 279 | |
280 | - $course_id = api_get_course_int_id(); |
|
281 | - |
|
282 | - // Do sanity checks on recipient_ids array & property fillin |
|
283 | - // The sanity check for ex-coursemembers is already done in base constructor |
|
284 | - $uploader_id = (int) $uploader_id; |
|
280 | + $course_id = api_get_course_int_id(); |
|
285 | 281 | |
286 | - $justSubmit = false; |
|
287 | - if (is_int($recipient_ids)) { |
|
288 | - $justSubmit = true; |
|
289 | - $recipient_ids = array($recipient_ids + $this->id); |
|
290 | - } elseif (count($recipient_ids) == 0) { |
|
291 | - $justSubmit = true; |
|
292 | - $recipient_ids = array($uploader_id); |
|
293 | - } |
|
282 | + // Do sanity checks on recipient_ids array & property fillin |
|
283 | + // The sanity check for ex-coursemembers is already done in base constructor |
|
284 | + $uploader_id = (int) $uploader_id; |
|
285 | + |
|
286 | + $justSubmit = false; |
|
287 | + if (is_int($recipient_ids)) { |
|
288 | + $justSubmit = true; |
|
289 | + $recipient_ids = array($recipient_ids + $this->id); |
|
290 | + } elseif (count($recipient_ids) == 0) { |
|
291 | + $justSubmit = true; |
|
292 | + $recipient_ids = array($uploader_id); |
|
293 | + } |
|
294 | 294 | |
295 | - if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
296 | - die(get_lang('GeneralError').' (code 209)'); |
|
297 | - } |
|
295 | + if (! is_array($recipient_ids) || count($recipient_ids) == 0) { |
|
296 | + die(get_lang('GeneralError').' (code 209)'); |
|
297 | + } |
|
298 | 298 | |
299 | - foreach ($recipient_ids as $rec) { |
|
300 | - if (empty($rec)) { |
|
301 | - continue; |
|
299 | + foreach ($recipient_ids as $rec) { |
|
300 | + if (empty($rec)) { |
|
301 | + continue; |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | //this check is done when validating submitted data |
305 | - $this->recipients[] = array('id' => $rec); |
|
306 | - } |
|
305 | + $this->recipients[] = array('id' => $rec); |
|
306 | + } |
|
307 | 307 | |
308 | 308 | $table_post = Database::get_course_table(TABLE_DROPBOX_POST); |
309 | 309 | $table_person = Database::get_course_table(TABLE_DROPBOX_PERSON); |
@@ -313,12 +313,12 @@ discard block |
||
313 | 313 | $mailId = get_mail_id_base(); |
314 | 314 | |
315 | 315 | // Insert data in dropbox_post and dropbox_person table for each recipient |
316 | - foreach ($this->recipients as $rec) { |
|
316 | + foreach ($this->recipients as $rec) { |
|
317 | 317 | $file_id = (int)$this->id; |
318 | 318 | $user_id = (int)$rec['id']; |
319 | - $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
319 | + $sql = "INSERT INTO $table_post (c_id, file_id, dest_user_id, session_id, feedback_date, cat_id) |
|
320 | 320 | VALUES ($course_id, $file_id, $user_id, $session_id, '$now', 0)"; |
321 | - Database::query($sql); |
|
321 | + Database::query($sql); |
|
322 | 322 | // If work already exists no error is generated |
323 | 323 | |
324 | 324 | /** |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | - // Update item_property table for each recipient |
|
339 | - if (($ownerid = $this->uploader_id) > $mailId) { |
|
340 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
341 | - } |
|
342 | - if (($recipid = $rec["id"]) > $mailId) { |
|
343 | - $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
344 | - } |
|
338 | + // Update item_property table for each recipient |
|
339 | + if (($ownerid = $this->uploader_id) > $mailId) { |
|
340 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
341 | + } |
|
342 | + if (($recipid = $rec["id"]) > $mailId) { |
|
343 | + $recipid = $ownerid; // mailing file recipient = mailing id, not a person |
|
344 | + } |
|
345 | 345 | api_item_property_update( |
346 | 346 | $_course, |
347 | 347 | TOOL_DROPBOX, |
@@ -351,90 +351,90 @@ discard block |
||
351 | 351 | null, |
352 | 352 | $recipid |
353 | 353 | ); |
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * private function creating existing object by retreiving info from db |
|
359 | - * |
|
360 | - * @param unknown_type $id |
|
361 | - */ |
|
362 | - public function _createExistingSentWork($id) |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * private function creating existing object by retreiving info from db |
|
359 | + * |
|
360 | + * @param unknown_type $id |
|
361 | + */ |
|
362 | + public function _createExistingSentWork($id) |
|
363 | 363 | { |
364 | 364 | $id = intval($id); |
365 | 365 | |
366 | - $course_id = api_get_course_int_id(); |
|
366 | + $course_id = api_get_course_int_id(); |
|
367 | 367 | |
368 | - // Call constructor of Dropbox_Work object |
|
369 | - parent::__construct($id); |
|
368 | + // Call constructor of Dropbox_Work object |
|
369 | + parent::__construct($id); |
|
370 | 370 | |
371 | - // Fill in recipients array |
|
372 | - $this->recipients = array(); |
|
373 | - $sql = "SELECT dest_user_id, feedback_date, feedback |
|
371 | + // Fill in recipients array |
|
372 | + $this->recipients = array(); |
|
373 | + $sql = "SELECT dest_user_id, feedback_date, feedback |
|
374 | 374 | FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
375 | 375 | WHERE c_id = $course_id AND file_id = ".intval($id).""; |
376 | 376 | $result = Database::query($sql); |
377 | - while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
378 | - // Check for deleted users |
|
379 | - $dest_user_id = $res['dest_user_id']; |
|
380 | - $user_info = api_get_user_info($dest_user_id); |
|
381 | - //$this->category = $res['cat_id']; |
|
382 | - if (!$user_info) { |
|
383 | - $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
384 | - } else { |
|
385 | - $this->recipients[] = array( |
|
377 | + while ($res = Database::fetch_array($result, 'ASSOC')) { |
|
378 | + // Check for deleted users |
|
379 | + $dest_user_id = $res['dest_user_id']; |
|
380 | + $user_info = api_get_user_info($dest_user_id); |
|
381 | + //$this->category = $res['cat_id']; |
|
382 | + if (!$user_info) { |
|
383 | + $this->recipients[] = array('id' => -1, 'name' => get_lang('Unknown', '')); |
|
384 | + } else { |
|
385 | + $this->recipients[] = array( |
|
386 | 386 | 'id' => $dest_user_id, |
387 | 387 | 'name' => $user_info['complete_name'], |
388 | 388 | 'user_id' => $dest_user_id, |
389 | - 'feedback_date' => $res['feedback_date'], |
|
389 | + 'feedback_date' => $res['feedback_date'], |
|
390 | 390 | 'feedback' => $res['feedback'] |
391 | 391 | ); |
392 | - } |
|
393 | - } |
|
394 | - } |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | class Dropbox_Person |
398 | 398 | { |
399 | - // The receivedWork and the sentWork arrays are sorted. |
|
400 | - public $receivedWork; // an array of Dropbox_Work objects |
|
401 | - public $sentWork; // an array of Dropbox_SentWork objects |
|
402 | - |
|
403 | - public $userId = 0; |
|
404 | - public $isCourseAdmin = false; |
|
405 | - public $isCourseTutor = false; |
|
406 | - public $_orderBy = ''; // private property that determines by which field |
|
407 | - |
|
408 | - /** |
|
409 | - * Constructor for recreating the Dropbox_Person object |
|
410 | - * |
|
411 | - * @param int $userId |
|
412 | - * @param bool $isCourseAdmin |
|
413 | - * @param bool $isCourseTutor |
|
414 | - * @return Dropbox_Person |
|
415 | - */ |
|
416 | - public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
399 | + // The receivedWork and the sentWork arrays are sorted. |
|
400 | + public $receivedWork; // an array of Dropbox_Work objects |
|
401 | + public $sentWork; // an array of Dropbox_SentWork objects |
|
402 | + |
|
403 | + public $userId = 0; |
|
404 | + public $isCourseAdmin = false; |
|
405 | + public $isCourseTutor = false; |
|
406 | + public $_orderBy = ''; // private property that determines by which field |
|
407 | + |
|
408 | + /** |
|
409 | + * Constructor for recreating the Dropbox_Person object |
|
410 | + * |
|
411 | + * @param int $userId |
|
412 | + * @param bool $isCourseAdmin |
|
413 | + * @param bool $isCourseTutor |
|
414 | + * @return Dropbox_Person |
|
415 | + */ |
|
416 | + public function __construct($userId, $isCourseAdmin, $isCourseTutor) |
|
417 | 417 | { |
418 | - $course_id = api_get_course_int_id(); |
|
418 | + $course_id = api_get_course_int_id(); |
|
419 | 419 | |
420 | - // Fill in properties |
|
420 | + // Fill in properties |
|
421 | 421 | $this->userId = $userId; |
422 | 422 | $this->isCourseAdmin = $isCourseAdmin; |
423 | 423 | $this->isCourseTutor = $isCourseTutor; |
424 | 424 | $this->receivedWork = array(); |
425 | 425 | $this->sentWork = array(); |
426 | 426 | |
427 | - // Note: perhaps include an ex coursemember check to delete old files |
|
427 | + // Note: perhaps include an ex coursemember check to delete old files |
|
428 | 428 | |
429 | - $session_id = api_get_session_id(); |
|
430 | - $condition_session = api_get_session_condition($session_id); |
|
429 | + $session_id = api_get_session_id(); |
|
430 | + $condition_session = api_get_session_condition($session_id); |
|
431 | 431 | |
432 | - $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
433 | - $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
434 | - $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
432 | + $post_tbl = Database::get_course_table(TABLE_DROPBOX_POST); |
|
433 | + $person_tbl = Database::get_course_table(TABLE_DROPBOX_PERSON); |
|
434 | + $file_tbl = Database::get_course_table(TABLE_DROPBOX_FILE); |
|
435 | 435 | |
436 | 436 | // Find all entries where this person is the recipient |
437 | - $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
437 | + $sql = "SELECT DISTINCT r.file_id, r.cat_id |
|
438 | 438 | FROM $post_tbl r |
439 | 439 | INNER JOIN $person_tbl p |
440 | 440 | ON (r.file_id = p.file_id AND r.c_id = $course_id AND p.c_id = $course_id ) |
@@ -443,12 +443,12 @@ discard block |
||
443 | 443 | r.dest_user_id = ".intval($this->userId)." $condition_session "; |
444 | 444 | |
445 | 445 | $result = Database::query($sql); |
446 | - while ($res = Database::fetch_array($result)) { |
|
447 | - $temp = new Dropbox_Work($res['file_id']); |
|
448 | - $temp->category = $res['cat_id']; |
|
449 | - $this->receivedWork[] = $temp; |
|
450 | - } |
|
451 | - // Find all entries where this person is the sender/uploader |
|
446 | + while ($res = Database::fetch_array($result)) { |
|
447 | + $temp = new Dropbox_Work($res['file_id']); |
|
448 | + $temp->category = $res['cat_id']; |
|
449 | + $this->receivedWork[] = $temp; |
|
450 | + } |
|
451 | + // Find all entries where this person is the sender/uploader |
|
452 | 452 | $sql = "SELECT DISTINCT f.id |
453 | 453 | FROM $file_tbl f |
454 | 454 | INNER JOIN $person_tbl p |
@@ -459,160 +459,160 @@ discard block |
||
459 | 459 | $condition_session |
460 | 460 | "; |
461 | 461 | $result = Database::query($sql); |
462 | - while ($res = Database::fetch_array($result)) { |
|
463 | - $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Deletes all the received work of this person |
|
469 | - */ |
|
470 | - public function deleteAllReceivedWork() |
|
462 | + while ($res = Database::fetch_array($result)) { |
|
463 | + $this->sentWork[] = new Dropbox_SentWork($res['id']); |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Deletes all the received work of this person |
|
469 | + */ |
|
470 | + public function deleteAllReceivedWork() |
|
471 | 471 | { |
472 | - $course_id = api_get_course_int_id(); |
|
473 | - // Delete entries in person table concerning received works |
|
474 | - foreach ($this->receivedWork as $w) { |
|
472 | + $course_id = api_get_course_int_id(); |
|
473 | + // Delete entries in person table concerning received works |
|
474 | + foreach ($this->receivedWork as $w) { |
|
475 | 475 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
476 | 476 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
477 | - Database::query($sql); |
|
478 | - } |
|
477 | + Database::query($sql); |
|
478 | + } |
|
479 | 479 | // Check for unused files |
480 | - removeUnusedFiles(); |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Deletes all the received categories and work of this person |
|
485 | - * @param integer $id |
|
486 | - */ |
|
487 | - public function deleteReceivedWorkFolder($id) |
|
480 | + removeUnusedFiles(); |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Deletes all the received categories and work of this person |
|
485 | + * @param integer $id |
|
486 | + */ |
|
487 | + public function deleteReceivedWorkFolder($id) |
|
488 | 488 | { |
489 | 489 | $course_id = api_get_course_int_id(); |
490 | 490 | |
491 | - $id = intval($id); |
|
492 | - $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
491 | + $id = intval($id); |
|
492 | + $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_FILE) ." |
|
493 | 493 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
494 | - if (!Database::query($sql)) return false; |
|
495 | - $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_CATEGORY) ." |
|
494 | + if (!Database::query($sql)) return false; |
|
495 | + $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_CATEGORY) ." |
|
496 | 496 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
497 | - if (!Database::query($sql)) return false; |
|
498 | - $sql = "DELETE FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
|
497 | + if (!Database::query($sql)) return false; |
|
498 | + $sql = "DELETE FROM ".Database::get_course_table(TABLE_DROPBOX_POST)." |
|
499 | 499 | WHERE c_id = $course_id AND cat_id = '".$id."' "; |
500 | - if (!Database::query($sql)) return false; |
|
501 | - return true; |
|
502 | - } |
|
503 | - |
|
504 | - /** |
|
505 | - * Deletes a received dropbox file of this person with id=$id |
|
506 | - * |
|
507 | - * @param integer $id |
|
508 | - */ |
|
509 | - public function deleteReceivedWork($id) |
|
500 | + if (!Database::query($sql)) return false; |
|
501 | + return true; |
|
502 | + } |
|
503 | + |
|
504 | + /** |
|
505 | + * Deletes a received dropbox file of this person with id=$id |
|
506 | + * |
|
507 | + * @param integer $id |
|
508 | + */ |
|
509 | + public function deleteReceivedWork($id) |
|
510 | 510 | { |
511 | - $course_id = api_get_course_int_id(); |
|
512 | - $id = intval($id); |
|
513 | - |
|
514 | - // index check |
|
515 | - $found = false; |
|
516 | - foreach ($this->receivedWork as $w) { |
|
517 | - if ($w->id == $id) { |
|
518 | - $found = true; |
|
519 | - break; |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - if (!$found) { |
|
524 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
525 | - die(get_lang('GeneralError').' (code 216)'); |
|
526 | - } |
|
527 | - } |
|
528 | - // Delete entries in person table concerning received works |
|
511 | + $course_id = api_get_course_int_id(); |
|
512 | + $id = intval($id); |
|
513 | + |
|
514 | + // index check |
|
515 | + $found = false; |
|
516 | + foreach ($this->receivedWork as $w) { |
|
517 | + if ($w->id == $id) { |
|
518 | + $found = true; |
|
519 | + break; |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + if (!$found) { |
|
524 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
525 | + die(get_lang('GeneralError').' (code 216)'); |
|
526 | + } |
|
527 | + } |
|
528 | + // Delete entries in person table concerning received works |
|
529 | 529 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
530 | 530 | WHERE c_id = $course_id AND user_id = '".$this->userId."' AND file_id ='".$id."'"; |
531 | - Database::query($sql); |
|
532 | - removeUnusedFiles(); // Check for unused files |
|
533 | - } |
|
534 | - |
|
535 | - /** |
|
536 | - * Deletes all the sent dropbox files of this person |
|
537 | - */ |
|
538 | - public function deleteAllSentWork() |
|
531 | + Database::query($sql); |
|
532 | + removeUnusedFiles(); // Check for unused files |
|
533 | + } |
|
534 | + |
|
535 | + /** |
|
536 | + * Deletes all the sent dropbox files of this person |
|
537 | + */ |
|
538 | + public function deleteAllSentWork() |
|
539 | 539 | { |
540 | - $course_id = api_get_course_int_id(); |
|
541 | - //delete entries in person table concerning sent works |
|
542 | - foreach ($this->sentWork as $w) { |
|
540 | + $course_id = api_get_course_int_id(); |
|
541 | + //delete entries in person table concerning sent works |
|
542 | + foreach ($this->sentWork as $w) { |
|
543 | 543 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
544 | 544 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$w->id."'"; |
545 | - Database::query($sql); |
|
546 | - removeMoreIfMailing($w->id); |
|
547 | - } |
|
548 | - removeUnusedFiles(); // Check for unused files |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Deletes a sent dropbox file of this person with id=$id |
|
553 | - * |
|
554 | - * @param unknown_type $id |
|
555 | - */ |
|
556 | - public function deleteSentWork($id) |
|
545 | + Database::query($sql); |
|
546 | + removeMoreIfMailing($w->id); |
|
547 | + } |
|
548 | + removeUnusedFiles(); // Check for unused files |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Deletes a sent dropbox file of this person with id=$id |
|
553 | + * |
|
554 | + * @param unknown_type $id |
|
555 | + */ |
|
556 | + public function deleteSentWork($id) |
|
557 | 557 | { |
558 | - $course_id = api_get_course_int_id(); |
|
559 | - |
|
560 | - $id = intval($id); |
|
561 | - |
|
562 | - // index check |
|
563 | - $found = false; |
|
564 | - foreach ($this->sentWork as $w) { |
|
565 | - if ($w->id == $id) { |
|
566 | - $found = true; |
|
567 | - break; |
|
568 | - } |
|
569 | - } |
|
570 | - if (!$found) { |
|
571 | - if (!$this->deleteReceivedWorkFolder($id)) { |
|
572 | - die(get_lang('GeneralError').' (code 219)'); |
|
573 | - } |
|
574 | - } |
|
575 | - //$file_id = $this->sentWork[$index]->id; |
|
576 | - // Delete entries in person table concerning sent works |
|
558 | + $course_id = api_get_course_int_id(); |
|
559 | + |
|
560 | + $id = intval($id); |
|
561 | + |
|
562 | + // index check |
|
563 | + $found = false; |
|
564 | + foreach ($this->sentWork as $w) { |
|
565 | + if ($w->id == $id) { |
|
566 | + $found = true; |
|
567 | + break; |
|
568 | + } |
|
569 | + } |
|
570 | + if (!$found) { |
|
571 | + if (!$this->deleteReceivedWorkFolder($id)) { |
|
572 | + die(get_lang('GeneralError').' (code 219)'); |
|
573 | + } |
|
574 | + } |
|
575 | + //$file_id = $this->sentWork[$index]->id; |
|
576 | + // Delete entries in person table concerning sent works |
|
577 | 577 | $sql = "DELETE FROM ". Database::get_course_table(TABLE_DROPBOX_PERSON) ." |
578 | 578 | WHERE c_id = $course_id AND user_id='".$this->userId."' AND file_id='".$id."'"; |
579 | - Database::query($sql); |
|
580 | - removeMoreIfMailing($id); |
|
581 | - removeUnusedFiles(); // Check for unused files |
|
582 | - } |
|
583 | - |
|
584 | - /** |
|
585 | - * Updates feedback for received work of this person with id=$id |
|
586 | - * |
|
587 | - * @param string $id |
|
588 | - * @param string $text |
|
589 | - */ |
|
590 | - public function updateFeedback($id, $text) |
|
579 | + Database::query($sql); |
|
580 | + removeMoreIfMailing($id); |
|
581 | + removeUnusedFiles(); // Check for unused files |
|
582 | + } |
|
583 | + |
|
584 | + /** |
|
585 | + * Updates feedback for received work of this person with id=$id |
|
586 | + * |
|
587 | + * @param string $id |
|
588 | + * @param string $text |
|
589 | + */ |
|
590 | + public function updateFeedback($id, $text) |
|
591 | 591 | { |
592 | - $course_id = api_get_course_int_id(); |
|
592 | + $course_id = api_get_course_int_id(); |
|
593 | 593 | $_course = api_get_course_info(); |
594 | 594 | $dropbox_cnf = getDropboxConf(); |
595 | 595 | |
596 | - $id = intval($id); |
|
596 | + $id = intval($id); |
|
597 | 597 | |
598 | - // index check |
|
599 | - $found = false; |
|
600 | - $wi = -1; |
|
601 | - foreach ($this->receivedWork as $w) { |
|
602 | - $wi++; |
|
603 | - if ($w->id == $id){ |
|
604 | - $found = true; |
|
605 | - break; |
|
606 | - } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
607 | - } |
|
598 | + // index check |
|
599 | + $found = false; |
|
600 | + $wi = -1; |
|
601 | + foreach ($this->receivedWork as $w) { |
|
602 | + $wi++; |
|
603 | + if ($w->id == $id){ |
|
604 | + $found = true; |
|
605 | + break; |
|
606 | + } // foreach (... as $wi -> $w) gives error 221! (no idea why...) |
|
607 | + } |
|
608 | 608 | |
609 | - if (!$found) { |
|
610 | - return false; |
|
611 | - } |
|
609 | + if (!$found) { |
|
610 | + return false; |
|
611 | + } |
|
612 | 612 | |
613 | - $feedback_date = api_get_utc_datetime(); |
|
614 | - $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
615 | - $this->receivedWork[$wi]->feedback = $text; |
|
613 | + $feedback_date = api_get_utc_datetime(); |
|
614 | + $this->receivedWork[$wi]->feedback_date = $feedback_date; |
|
615 | + $this->receivedWork[$wi]->feedback = $text; |
|
616 | 616 | |
617 | 617 | $params = [ |
618 | 618 | 'feedback_date' => $feedback_date, |
@@ -630,11 +630,11 @@ discard block |
||
630 | 630 | ] |
631 | 631 | ); |
632 | 632 | |
633 | - // Update item_property table |
|
633 | + // Update item_property table |
|
634 | 634 | $mailId = get_mail_id_base(); |
635 | - if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $mailId) { |
|
636 | - $ownerid = getUserOwningThisMailing($ownerid); |
|
637 | - } |
|
635 | + if (($ownerid = $this->receivedWork[$wi]->uploader_id) > $mailId) { |
|
636 | + $ownerid = getUserOwningThisMailing($ownerid); |
|
637 | + } |
|
638 | 638 | |
639 | 639 | api_item_property_update( |
640 | 640 | $_course, |
@@ -646,33 +646,33 @@ discard block |
||
646 | 646 | $ownerid |
647 | 647 | ); |
648 | 648 | |
649 | - } |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
652 | - * Filter the received work |
|
653 | - * @param string $type |
|
654 | - * @param string $value |
|
655 | - */ |
|
656 | - public function filter_received_work($type, $value) |
|
651 | + /** |
|
652 | + * Filter the received work |
|
653 | + * @param string $type |
|
654 | + * @param string $value |
|
655 | + */ |
|
656 | + public function filter_received_work($type, $value) |
|
657 | 657 | { |
658 | 658 | $dropbox_cnf = getDropboxConf(); |
659 | - $new_received_work = array(); |
|
659 | + $new_received_work = array(); |
|
660 | 660 | $mailId = get_mail_id_base(); |
661 | 661 | foreach ($this->receivedWork as $work) { |
662 | - switch ($type) { |
|
663 | - case 'uploader_id': |
|
664 | - if ($work->uploader_id == $value || |
|
665 | - ($work->uploader_id > $mailId && |
|
662 | + switch ($type) { |
|
663 | + case 'uploader_id': |
|
664 | + if ($work->uploader_id == $value || |
|
665 | + ($work->uploader_id > $mailId && |
|
666 | 666 | getUserOwningThisMailing($work->uploader_id) == $value) |
667 | 667 | ) { |
668 | - $new_received_work[] = $work; |
|
669 | - } |
|
670 | - break; |
|
671 | - default: |
|
672 | - $new_received_work[] = $work; |
|
668 | + $new_received_work[] = $work; |
|
669 | + } |
|
670 | + break; |
|
671 | + default: |
|
672 | + $new_received_work[] = $work; |
|
673 | 673 | break; |
674 | - } |
|
675 | - } |
|
676 | - $this->receivedWork = $new_received_work; |
|
677 | - } |
|
674 | + } |
|
675 | + } |
|
676 | + $this->receivedWork = $new_received_work; |
|
677 | + } |
|
678 | 678 | } |
@@ -10,46 +10,46 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify |
|
53 | 53 | FROM '.$this->get_forum_thread_table().' |
54 | 54 | forum_thread WHERE thread_id NOT IN |
55 | 55 | ( |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ) |
61 | 61 | AND forum_thread.session_id='.api_get_session_id(); |
62 | 62 | |
63 | - $result = Database::query($sql); |
|
63 | + $result = Database::query($sql); |
|
64 | 64 | |
65 | 65 | $cats = array(); |
66 | 66 | while ($data = Database::fetch_array($result)) { |
@@ -75,29 +75,29 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | return $cats; |
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Generate an array of all exercises available. |
|
82 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
83 | - */ |
|
84 | - public function get_all_links() |
|
85 | - { |
|
86 | - if (empty($this->course_code)) { |
|
87 | - die('Error in get_not_created_links() : course code not set'); |
|
88 | - } |
|
89 | - |
|
90 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
91 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
92 | - $session_id = api_get_session_id(); |
|
93 | - |
|
94 | - if ($session_id) { |
|
95 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
96 | - } else { |
|
97 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
98 | - } |
|
99 | - |
|
100 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Generate an array of all exercises available. |
|
82 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
83 | + */ |
|
84 | + public function get_all_links() |
|
85 | + { |
|
86 | + if (empty($this->course_code)) { |
|
87 | + die('Error in get_not_created_links() : course code not set'); |
|
88 | + } |
|
89 | + |
|
90 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
91 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
92 | + $session_id = api_get_session_id(); |
|
93 | + |
|
94 | + if ($session_id) { |
|
95 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
96 | + } else { |
|
97 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
98 | + } |
|
99 | + |
|
100 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
101 | 101 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
102 | 102 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id) |
103 | 103 | WHERE |
@@ -108,23 +108,23 @@ discard block |
||
108 | 108 | '.$session_condition.' |
109 | 109 | '; |
110 | 110 | |
111 | - $result = Database::query($sql); |
|
112 | - while ($data = Database::fetch_array($result)) { |
|
113 | - if ( isset($data['thread_title_qualify']) && $data['thread_title_qualify'] != "") { |
|
114 | - $cats[] = array($data['thread_id'], $data['thread_title_qualify']); |
|
115 | - } else { |
|
116 | - $cats[] = array($data['thread_id'], $data['thread_title']); |
|
117 | - } |
|
118 | - } |
|
119 | - $my_cats = isset($cats) ? $cats : null; |
|
111 | + $result = Database::query($sql); |
|
112 | + while ($data = Database::fetch_array($result)) { |
|
113 | + if ( isset($data['thread_title_qualify']) && $data['thread_title_qualify'] != "") { |
|
114 | + $cats[] = array($data['thread_id'], $data['thread_title_qualify']); |
|
115 | + } else { |
|
116 | + $cats[] = array($data['thread_id'], $data['thread_title']); |
|
117 | + } |
|
118 | + } |
|
119 | + $my_cats = isset($cats) ? $cats : null; |
|
120 | 120 | |
121 | - return $my_cats; |
|
122 | - } |
|
121 | + return $my_cats; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | /** |
125 | - * Has anyone done this exercise yet ? |
|
126 | - * @return boolean |
|
127 | - */ |
|
125 | + * Has anyone done this exercise yet ? |
|
126 | + * @return boolean |
|
127 | + */ |
|
128 | 128 | public function has_results() |
129 | 129 | { |
130 | 130 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -138,50 +138,50 @@ discard block |
||
138 | 138 | $number = Database::fetch_row($result); |
139 | 139 | |
140 | 140 | return $number[0] != 0; |
141 | - } |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * @param int $stud_id |
|
143 | + /** |
|
144 | + * @param int $stud_id |
|
145 | 145 | * @param string $type |
146 | 146 | * |
147 | - * @return array|null |
|
148 | - */ |
|
149 | - public function calc_score($stud_id = null, $type = null) |
|
150 | - { |
|
147 | + * @return array|null |
|
148 | + */ |
|
149 | + public function calc_score($stud_id = null, $type = null) |
|
150 | + { |
|
151 | 151 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
152 | 152 | $threadInfo = get_thread_information('', $this->get_ref_id()); |
153 | 153 | |
154 | - $thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
154 | + $thread_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
155 | 155 | |
156 | 156 | $sessionId = $this->get_session_id(); |
157 | 157 | $sessionCondition = api_get_session_condition($sessionId, true, false, 'session_id'); |
158 | 158 | |
159 | - $sql = 'SELECT thread_qualify_max |
|
159 | + $sql = 'SELECT thread_qualify_max |
|
160 | 160 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
161 | 161 | WHERE |
162 | 162 | c_id = ".$this->course_id." AND |
163 | 163 | thread_id = '".$this->get_ref_id()."' |
164 | 164 | $sessionCondition |
165 | 165 | "; |
166 | - $query = Database::query($sql); |
|
167 | - $assignment = Database::fetch_array($query); |
|
166 | + $query = Database::query($sql); |
|
167 | + $assignment = Database::fetch_array($query); |
|
168 | 168 | |
169 | - $sql = "SELECT * FROM $thread_qualify |
|
169 | + $sql = "SELECT * FROM $thread_qualify |
|
170 | 170 | WHERE |
171 | 171 | c_id = ".$this->course_id." AND |
172 | 172 | thread_id = ".$this->get_ref_id()." |
173 | 173 | $sessionCondition |
174 | 174 | "; |
175 | - if (isset($stud_id)) { |
|
176 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
177 | - } |
|
175 | + if (isset($stud_id)) { |
|
176 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
177 | + } |
|
178 | 178 | |
179 | - // order by id, that way the student's first attempt is accessed first |
|
180 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
181 | - $scores = Database::query($sql); |
|
179 | + // order by id, that way the student's first attempt is accessed first |
|
180 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
181 | + $scores = Database::query($sql); |
|
182 | 182 | |
183 | - // for 1 student |
|
184 | - if (isset($stud_id)) { |
|
183 | + // for 1 student |
|
184 | + if (isset($stud_id)) { |
|
185 | 185 | if ($threadInfo['thread_peer_qualify'] == 0) { |
186 | 186 | // Classic way of calculate score |
187 | 187 | if ($data = Database::fetch_array($scores)) { |
@@ -209,175 +209,175 @@ discard block |
||
209 | 209 | } |
210 | 210 | return [$score/$counter, $assignment['thread_qualify_max']]; |
211 | 211 | } |
212 | - } else { |
|
213 | - // All students -> get average |
|
214 | - $students = array(); // user list, needed to make sure we only |
|
215 | - // take first attempts into account |
|
216 | - $counter = 0; |
|
217 | - $sum = 0; |
|
218 | - $bestResult = 0; |
|
219 | - $weight = 0; |
|
220 | - $sumResult = 0; |
|
221 | - |
|
222 | - while ($data = Database::fetch_array($scores)) { |
|
223 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
224 | - if ($assignment['thread_qualify_max'] != 0) { |
|
225 | - $students[$data['user_id']] = $data['qualify']; |
|
226 | - $counter++; |
|
227 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
228 | - $sumResult += $data['qualify']; |
|
229 | - if ($data['qualify'] > $bestResult) { |
|
230 | - $bestResult = $data['qualify']; |
|
231 | - } |
|
232 | - $weight = $assignment['thread_qualify_max']; |
|
233 | - } |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - if ($counter == 0) { |
|
238 | - return null; |
|
239 | - } else { |
|
240 | - switch ($type) { |
|
241 | - case 'best': |
|
242 | - return array($bestResult, $weight); |
|
243 | - break; |
|
244 | - case 'average': |
|
245 | - return array($sumResult/$counter, $weight); |
|
246 | - break; |
|
247 | - case 'ranking': |
|
248 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
249 | - break; |
|
250 | - default: |
|
251 | - return array($sum, $counter); |
|
252 | - break; |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Lazy load function to get the database table of the student publications |
|
260 | - */ |
|
261 | - private function get_forum_thread_table() |
|
262 | - { |
|
263 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
264 | - } |
|
265 | - |
|
266 | - public function needs_name_and_description() |
|
267 | - { |
|
268 | - return false; |
|
269 | - } |
|
270 | - |
|
271 | - public function needs_max() |
|
272 | - { |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - public function needs_results() |
|
277 | - { |
|
278 | - return false; |
|
279 | - } |
|
212 | + } else { |
|
213 | + // All students -> get average |
|
214 | + $students = array(); // user list, needed to make sure we only |
|
215 | + // take first attempts into account |
|
216 | + $counter = 0; |
|
217 | + $sum = 0; |
|
218 | + $bestResult = 0; |
|
219 | + $weight = 0; |
|
220 | + $sumResult = 0; |
|
221 | + |
|
222 | + while ($data = Database::fetch_array($scores)) { |
|
223 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
224 | + if ($assignment['thread_qualify_max'] != 0) { |
|
225 | + $students[$data['user_id']] = $data['qualify']; |
|
226 | + $counter++; |
|
227 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
228 | + $sumResult += $data['qualify']; |
|
229 | + if ($data['qualify'] > $bestResult) { |
|
230 | + $bestResult = $data['qualify']; |
|
231 | + } |
|
232 | + $weight = $assignment['thread_qualify_max']; |
|
233 | + } |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + if ($counter == 0) { |
|
238 | + return null; |
|
239 | + } else { |
|
240 | + switch ($type) { |
|
241 | + case 'best': |
|
242 | + return array($bestResult, $weight); |
|
243 | + break; |
|
244 | + case 'average': |
|
245 | + return array($sumResult/$counter, $weight); |
|
246 | + break; |
|
247 | + case 'ranking': |
|
248 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
249 | + break; |
|
250 | + default: |
|
251 | + return array($sum, $counter); |
|
252 | + break; |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Lazy load function to get the database table of the student publications |
|
260 | + */ |
|
261 | + private function get_forum_thread_table() |
|
262 | + { |
|
263 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
264 | + } |
|
265 | + |
|
266 | + public function needs_name_and_description() |
|
267 | + { |
|
268 | + return false; |
|
269 | + } |
|
270 | + |
|
271 | + public function needs_max() |
|
272 | + { |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + public function needs_results() |
|
277 | + { |
|
278 | + return false; |
|
279 | + } |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * @return string |
283 | 283 | */ |
284 | - public function get_name() |
|
285 | - { |
|
286 | - $this->get_exercise_data(); |
|
287 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
288 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
289 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
290 | - return $this->exercise_data['thread_title_qualify']; |
|
291 | - } else { |
|
292 | - return $thread_title; |
|
293 | - } |
|
294 | - } |
|
284 | + public function get_name() |
|
285 | + { |
|
286 | + $this->get_exercise_data(); |
|
287 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
288 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
289 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
290 | + return $this->exercise_data['thread_title_qualify']; |
|
291 | + } else { |
|
292 | + return $thread_title; |
|
293 | + } |
|
294 | + } |
|
295 | 295 | |
296 | 296 | /** |
297 | 297 | * @return string |
298 | 298 | */ |
299 | - public function get_description() |
|
300 | - { |
|
301 | - return '';//$this->exercise_data['description']; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Check if this still links to an exercise |
|
306 | - */ |
|
307 | - public function is_valid_link() |
|
308 | - { |
|
309 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
299 | + public function get_description() |
|
300 | + { |
|
301 | + return '';//$this->exercise_data['description']; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Check if this still links to an exercise |
|
306 | + */ |
|
307 | + public function is_valid_link() |
|
308 | + { |
|
309 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
310 | 310 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
311 | - $result = Database::query($sql); |
|
312 | - $number = Database::fetch_row($result); |
|
313 | - return ($number[0] != 0); |
|
314 | - } |
|
315 | - |
|
316 | - public function get_test_id() |
|
317 | - { |
|
318 | - return 'DEBUG:ID'; |
|
319 | - } |
|
320 | - |
|
321 | - public function get_link() |
|
322 | - { |
|
323 | - $sessionId = api_get_session_id(); |
|
324 | - //it was extracts the forum id |
|
325 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | + $result = Database::query($sql); |
|
312 | + $number = Database::fetch_row($result); |
|
313 | + return ($number[0] != 0); |
|
314 | + } |
|
315 | + |
|
316 | + public function get_test_id() |
|
317 | + { |
|
318 | + return 'DEBUG:ID'; |
|
319 | + } |
|
320 | + |
|
321 | + public function get_link() |
|
322 | + { |
|
323 | + $sessionId = api_get_session_id(); |
|
324 | + //it was extracts the forum id |
|
325 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
326 | 326 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".$sessionId.""; |
327 | - $result = Database::query($sql); |
|
328 | - $row = Database::fetch_array($result,'ASSOC'); |
|
329 | - $forum_id=$row['forum_id']; |
|
330 | - |
|
331 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
332 | - return $url; |
|
333 | - } |
|
334 | - |
|
335 | - private function get_exercise_data() |
|
336 | - { |
|
337 | - $session_id = api_get_session_id(); |
|
338 | - if ($session_id) { |
|
339 | - $session_condition = 'session_id='.api_get_session_id(); |
|
340 | - } else { |
|
341 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
342 | - } |
|
343 | - |
|
344 | - if (!isset($this->exercise_data)) { |
|
345 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
327 | + $result = Database::query($sql); |
|
328 | + $row = Database::fetch_array($result,'ASSOC'); |
|
329 | + $forum_id=$row['forum_id']; |
|
330 | + |
|
331 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?'.api_get_cidreq_params($this->get_course_code(), $sessionId).'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
332 | + return $url; |
|
333 | + } |
|
334 | + |
|
335 | + private function get_exercise_data() |
|
336 | + { |
|
337 | + $session_id = api_get_session_id(); |
|
338 | + if ($session_id) { |
|
339 | + $session_condition = 'session_id='.api_get_session_id(); |
|
340 | + } else { |
|
341 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
342 | + } |
|
343 | + |
|
344 | + if (!isset($this->exercise_data)) { |
|
345 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
346 | 346 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
347 | - $query = Database::query($sql); |
|
348 | - $this->exercise_data = Database::fetch_array($query); |
|
349 | - } |
|
350 | - return $this->exercise_data; |
|
351 | - } |
|
352 | - |
|
353 | - public function get_icon_name() |
|
354 | - { |
|
355 | - return 'forum'; |
|
356 | - } |
|
357 | - |
|
358 | - function save_linked_data() |
|
359 | - { |
|
360 | - $weight = (float)$this->get_weight(); |
|
361 | - $ref_id = $this->get_ref_id(); |
|
362 | - |
|
363 | - if (!empty($ref_id)) { |
|
364 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
347 | + $query = Database::query($sql); |
|
348 | + $this->exercise_data = Database::fetch_array($query); |
|
349 | + } |
|
350 | + return $this->exercise_data; |
|
351 | + } |
|
352 | + |
|
353 | + public function get_icon_name() |
|
354 | + { |
|
355 | + return 'forum'; |
|
356 | + } |
|
357 | + |
|
358 | + function save_linked_data() |
|
359 | + { |
|
360 | + $weight = (float)$this->get_weight(); |
|
361 | + $ref_id = $this->get_ref_id(); |
|
362 | + |
|
363 | + if (!empty($ref_id)) { |
|
364 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
365 | 365 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
366 | - Database::query($sql); |
|
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - function delete_linked_data() |
|
371 | - { |
|
372 | - $ref_id = $this->get_ref_id(); |
|
373 | - if (!empty($ref_id)) { |
|
374 | - //Cleans forum |
|
375 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
366 | + Database::query($sql); |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + function delete_linked_data() |
|
371 | + { |
|
372 | + $ref_id = $this->get_ref_id(); |
|
373 | + if (!empty($ref_id)) { |
|
374 | + //Cleans forum |
|
375 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
376 | 376 | thread_qualify_max = 0, |
377 | 377 | thread_weight = 0, |
378 | 378 | thread_title_qualify = "" |
379 | 379 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
380 | - Database::query($sql); |
|
381 | - } |
|
382 | - } |
|
380 | + Database::query($sql); |
|
381 | + } |
|
382 | + } |
|
383 | 383 | } |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | //Event::event_download($doc_url); |
24 | 24 | if (isset($_course['path'])) { |
25 | 25 | $course_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
26 | - $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
26 | + $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
27 | 27 | } else { |
28 | 28 | $course_path = api_get_path(SYS_COURSE_PATH).$cid.'/document'; |
29 | - $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
29 | + $full_file_name = $course_path.Security::remove_XSS($doc_url); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | if(!is_file($full_file_name)) { |
33 | - exit; |
|
33 | + exit; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | if (!Security::check_abs_path($full_file_name, $course_path.'/')) { |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | $extension=strtolower($extension[sizeof($extension)-1]); |
42 | 42 | |
43 | 43 | switch($extension) { |
44 | - case 'gz': $content_type='application/x-gzip'; break; |
|
45 | - case 'zip': $content_type='application/zip'; break; |
|
46 | - case 'pdf': $content_type='application/pdf'; break; |
|
47 | - case 'png': $content_type='image/png'; break; |
|
48 | - case 'gif': $content_type='image/gif'; break; |
|
49 | - case 'jpg': $content_type='image/jpeg'; break; |
|
50 | - case 'txt': $content_type='text/plain'; break; |
|
51 | - case 'htm': $content_type='text/html'; break; |
|
52 | - case 'html': $content_type='text/html'; break; |
|
53 | - default: $content_type='application/octet-stream'; break; |
|
44 | + case 'gz': $content_type='application/x-gzip'; break; |
|
45 | + case 'zip': $content_type='application/zip'; break; |
|
46 | + case 'pdf': $content_type='application/pdf'; break; |
|
47 | + case 'png': $content_type='image/png'; break; |
|
48 | + case 'gif': $content_type='image/gif'; break; |
|
49 | + case 'jpg': $content_type='image/jpeg'; break; |
|
50 | + case 'txt': $content_type='text/plain'; break; |
|
51 | + case 'htm': $content_type='text/html'; break; |
|
52 | + case 'html': $content_type='text/html'; break; |
|
53 | + default: $content_type='application/octet-stream'; break; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | header('Content-disposition: filename='.$filename); |
@@ -68,30 +68,30 @@ discard block |
||
68 | 68 | */ |
69 | 69 | |
70 | 70 | if ($content_type == 'text/html') { |
71 | - $directory_name = dirname($full_file_name); |
|
71 | + $directory_name = dirname($full_file_name); |
|
72 | 72 | |
73 | - $dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name); |
|
73 | + $dir=str_replace(array('\\',$_configuration['root_sys']."courses/".$_course['path'].'/document'),array('/',''),$directory_name); |
|
74 | 74 | |
75 | - if($dir[strlen($dir)-1] != '/') { |
|
76 | - $dir.='/'; |
|
77 | - } |
|
75 | + if($dir[strlen($dir)-1] != '/') { |
|
76 | + $dir.='/'; |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | - //Parse whole file at one |
|
81 | - $fp = fopen($full_file_name, "r"); |
|
82 | - $file_content = fread ($fp, filesize ($full_file_name)); |
|
83 | - fclose($fp); |
|
80 | + //Parse whole file at one |
|
81 | + $fp = fopen($full_file_name, "r"); |
|
82 | + $file_content = fread ($fp, filesize ($full_file_name)); |
|
83 | + fclose($fp); |
|
84 | 84 | $exercisePath = api_get_self(); |
85 | - $exfile = explode('/',$exercisePath); |
|
86 | - $exfile = $exfile[sizeof($exfile)-1]; |
|
87 | - $exercisePath = substr($exercisePath,0,strpos($exercisePath,$exfile)); |
|
88 | - $exercisePath = $exercisePath; |
|
85 | + $exfile = explode('/',$exercisePath); |
|
86 | + $exfile = $exfile[sizeof($exfile)-1]; |
|
87 | + $exercisePath = substr($exercisePath,0,strpos($exercisePath,$exfile)); |
|
88 | + $exercisePath = $exercisePath; |
|
89 | 89 | |
90 | - $content = $file_content; |
|
91 | - $mit = "function Finish(){"; |
|
90 | + $content = $file_content; |
|
91 | + $mit = "function Finish(){"; |
|
92 | 92 | |
93 | - $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n". |
|
94 | - "function mySaveScore() // This function included by Dokeos System\n". |
|
93 | + $js_content = "var SaveScoreVariable = 0; // This variable included by Dokeos System\n". |
|
94 | + "function mySaveScore() // This function included by Dokeos System\n". |
|
95 | 95 | "{\n". |
96 | 96 | " if (SaveScoreVariable==0)\n". |
97 | 97 | " {\n". |
@@ -109,23 +109,23 @@ discard block |
||
109 | 109 | "// Must be included \n". |
110 | 110 | "function Finish(){\n". |
111 | 111 | " mySaveScore();"; |
112 | - $newcontent = str_replace($mit,$js_content,$content); |
|
112 | + $newcontent = str_replace($mit,$js_content,$content); |
|
113 | 113 | |
114 | - $prehref="javascript:void(0);"; |
|
115 | - $posthref = api_get_path(WEB_CODE_PATH) . "main/exercise/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid; |
|
116 | - $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
114 | + $prehref="javascript:void(0);"; |
|
115 | + $posthref = api_get_path(WEB_CODE_PATH) . "main/exercise/Hpdownload.php?doc_url=".$doc_url."&cid=".$cid."&uid=".$uid; |
|
116 | + $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
117 | 117 | |
118 | 118 | |
119 | - $prehref="class=\"GridNum\" onclick="; |
|
120 | - $posthref="class=\"GridNum\" onMouseover="; |
|
121 | - $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
119 | + $prehref="class=\"GridNum\" onclick="; |
|
120 | + $posthref="class=\"GridNum\" onMouseover="; |
|
121 | + $newcontent = str_replace($prehref,$posthref,$newcontent); |
|
122 | 122 | |
123 | 123 | |
124 | - header('Content-length: '.strlen($newcontent)); |
|
125 | - // Dipsp. |
|
126 | - echo $newcontent; |
|
124 | + header('Content-length: '.strlen($newcontent)); |
|
125 | + // Dipsp. |
|
126 | + echo $newcontent; |
|
127 | 127 | |
128 | - exit(); |
|
128 | + exit(); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | //normal case, all non-html files |
@@ -82,12 +82,12 @@ discard block |
||
82 | 82 | */ |
83 | 83 | interface WSCMErrorHandler |
84 | 84 | { |
85 | - /** |
|
86 | - * Handle method |
|
87 | - * |
|
88 | - * @param WSError Error |
|
89 | - */ |
|
90 | - public function handle($error); |
|
85 | + /** |
|
86 | + * Handle method |
|
87 | + * |
|
88 | + * @param WSError Error |
|
89 | + */ |
|
90 | + public function handle($error); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -95,57 +95,57 @@ discard block |
||
95 | 95 | */ |
96 | 96 | class WSCM |
97 | 97 | { |
98 | - /** |
|
99 | - * Chamilo configuration |
|
100 | - * |
|
101 | - * @var array |
|
102 | - */ |
|
103 | - protected $_configuration; |
|
98 | + /** |
|
99 | + * Chamilo configuration |
|
100 | + * |
|
101 | + * @var array |
|
102 | + */ |
|
103 | + protected $_configuration; |
|
104 | 104 | |
105 | - /** |
|
106 | - * Constructor |
|
107 | - */ |
|
108 | - public function __construct() |
|
105 | + /** |
|
106 | + * Constructor |
|
107 | + */ |
|
108 | + public function __construct() |
|
109 | 109 | { |
110 | - $this->_configuration = $GLOBALS['_configuration']; |
|
111 | - } |
|
110 | + $this->_configuration = $GLOBALS['_configuration']; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Verifies the API key |
|
115 | - * |
|
116 | - * @param string Secret key |
|
117 | - * @return mixed WSError in case of failure, null in case of success |
|
118 | - */ |
|
119 | - protected function verifyKey($secret_key) |
|
113 | + /** |
|
114 | + * Verifies the API key |
|
115 | + * |
|
116 | + * @param string Secret key |
|
117 | + * @return mixed WSError in case of failure, null in case of success |
|
118 | + */ |
|
119 | + protected function verifyKey($secret_key) |
|
120 | 120 | { |
121 | - $ip = trim($_SERVER['REMOTE_ADDR']); |
|
122 | - // if we are behind a reverse proxy, assume it will send the |
|
123 | - // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
124 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
125 | - list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
126 | - $ip = trim($ip1); |
|
127 | - } |
|
128 | - $security_key = $ip.$this->_configuration['security_key']; |
|
121 | + $ip = trim($_SERVER['REMOTE_ADDR']); |
|
122 | + // if we are behind a reverse proxy, assume it will send the |
|
123 | + // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
124 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
125 | + list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
126 | + $ip = trim($ip1); |
|
127 | + } |
|
128 | + $security_key = $ip.$this->_configuration['security_key']; |
|
129 | 129 | |
130 | - if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
131 | - return new WSCMError(1, "API key is invalid"); |
|
132 | - } else { |
|
133 | - return null; |
|
134 | - } |
|
135 | - } |
|
130 | + if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
131 | + return new WSCMError(1, "API key is invalid"); |
|
132 | + } else { |
|
133 | + return null; |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Verifies if the user is valid |
|
139 | - * |
|
140 | - * @param <String> $username of the user in chamilo |
|
141 | - * @param <String> $pass of the same user (in MD5 of SHA) |
|
142 | - * |
|
143 | - * return "valid" if username e password are correct! Else, return a message error |
|
144 | - */ |
|
145 | - public function verifyUserPass($username, $pass) |
|
137 | + /** |
|
138 | + * Verifies if the user is valid |
|
139 | + * |
|
140 | + * @param <String> $username of the user in chamilo |
|
141 | + * @param <String> $pass of the same user (in MD5 of SHA) |
|
142 | + * |
|
143 | + * return "valid" if username e password are correct! Else, return a message error |
|
144 | + */ |
|
145 | + public function verifyUserPass($username, $pass) |
|
146 | 146 | { |
147 | - $login = $username; |
|
148 | - $password = $pass; |
|
147 | + $login = $username; |
|
148 | + $password = $pass; |
|
149 | 149 | |
150 | 150 | $userRepo = UserManager::getRepository(); |
151 | 151 | /** @var User $uData */ |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | } |
179 | 179 | } |
180 | 180 | return get_lang('InvalidId'); |
181 | - } |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Gets the real user id based on the user id field name and value. |
|
185 | - * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
186 | - * in the system database |
|
187 | - * |
|
188 | - * @param string User id field name |
|
189 | - * @param string User id value |
|
190 | - * @return mixed System user id if the user was found, WSError otherwise |
|
191 | - */ |
|
183 | + /** |
|
184 | + * Gets the real user id based on the user id field name and value. |
|
185 | + * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
186 | + * in the system database |
|
187 | + * |
|
188 | + * @param string User id field name |
|
189 | + * @param string User id value |
|
190 | + * @return mixed System user id if the user was found, WSError otherwise |
|
191 | + */ |
|
192 | 192 | protected function getUserId($user_id_field_name, $user_id_value) |
193 | 193 | { |
194 | 194 | if ($user_id_field_name == "chamilo_user_id") { |
@@ -210,16 +210,16 @@ discard block |
||
210 | 210 | } |
211 | 211 | } |
212 | 212 | |
213 | - /** |
|
214 | - * Gets the real course id based on the course id field name and value. |
|
215 | - * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
216 | - * in the system database |
|
217 | - * |
|
218 | - * @param string Course id field name |
|
219 | - * @param string Course id value |
|
220 | - * @return mixed System course id if the course was found, WSError otherwise |
|
221 | - */ |
|
222 | - protected function getCourseId($course_id_field_name, $course_id_value) |
|
213 | + /** |
|
214 | + * Gets the real course id based on the course id field name and value. |
|
215 | + * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
216 | + * in the system database |
|
217 | + * |
|
218 | + * @param string Course id field name |
|
219 | + * @param string Course id value |
|
220 | + * @return mixed System course id if the course was found, WSError otherwise |
|
221 | + */ |
|
222 | + protected function getCourseId($course_id_field_name, $course_id_value) |
|
223 | 223 | { |
224 | 224 | if ($course_id_field_name == "chamilo_course_id") { |
225 | 225 | if (CourseManager::get_course_code_from_course_id($course_id_value) != null) { |
@@ -238,78 +238,78 @@ discard block |
||
238 | 238 | return $courseId; |
239 | 239 | } |
240 | 240 | } |
241 | - } |
|
241 | + } |
|
242 | 242 | |
243 | - /** |
|
244 | - * Gets the real session id based on the session id field name and value. |
|
245 | - * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
246 | - * in the system database |
|
247 | - * |
|
248 | - * @param string Session id field name |
|
249 | - * @param string Session id value |
|
250 | - * @return mixed System session id if the session was found, WSError otherwise |
|
251 | - */ |
|
252 | - protected function getSessionId($session_id_field_name, $session_id_value) |
|
253 | - { |
|
254 | - if ($session_id_field_name == "chamilo_session_id") { |
|
255 | - $session = SessionManager::fetch((int)$session_id_value); |
|
256 | - if(!empty($session)) { |
|
257 | - return intval($session_id_value); |
|
258 | - } else { |
|
259 | - return new WSCMError(300, "Session not found"); |
|
260 | - } |
|
261 | - } else { |
|
262 | - $session_id = SessionManager::getSessionIdFromOriginalId( |
|
263 | - $session_id_value, |
|
264 | - $session_id_field_name |
|
265 | - ); |
|
266 | - if($session_id == 0) { |
|
267 | - return new WSCMError(300, "Session not found"); |
|
268 | - } else { |
|
269 | - return $session_id; |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
243 | + /** |
|
244 | + * Gets the real session id based on the session id field name and value. |
|
245 | + * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
246 | + * in the system database |
|
247 | + * |
|
248 | + * @param string Session id field name |
|
249 | + * @param string Session id value |
|
250 | + * @return mixed System session id if the session was found, WSError otherwise |
|
251 | + */ |
|
252 | + protected function getSessionId($session_id_field_name, $session_id_value) |
|
253 | + { |
|
254 | + if ($session_id_field_name == "chamilo_session_id") { |
|
255 | + $session = SessionManager::fetch((int)$session_id_value); |
|
256 | + if(!empty($session)) { |
|
257 | + return intval($session_id_value); |
|
258 | + } else { |
|
259 | + return new WSCMError(300, "Session not found"); |
|
260 | + } |
|
261 | + } else { |
|
262 | + $session_id = SessionManager::getSessionIdFromOriginalId( |
|
263 | + $session_id_value, |
|
264 | + $session_id_field_name |
|
265 | + ); |
|
266 | + if($session_id == 0) { |
|
267 | + return new WSCMError(300, "Session not found"); |
|
268 | + } else { |
|
269 | + return $session_id; |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | 273 | |
274 | - /** |
|
275 | - * Handles an error by calling the WSError error handler |
|
276 | - * |
|
277 | - * @param WSError Error |
|
278 | - */ |
|
279 | - protected function handleError($error) |
|
280 | - { |
|
281 | - $handler = WSCMError::getErrorHandler(); |
|
282 | - $handler->handle($error); |
|
283 | - } |
|
274 | + /** |
|
275 | + * Handles an error by calling the WSError error handler |
|
276 | + * |
|
277 | + * @param WSError Error |
|
278 | + */ |
|
279 | + protected function handleError($error) |
|
280 | + { |
|
281 | + $handler = WSCMError::getErrorHandler(); |
|
282 | + $handler->handle($error); |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Gets a successful result |
|
287 | - * |
|
288 | - * @return array Array with a code of 0 and a message 'Operation was successful' |
|
289 | - */ |
|
290 | - protected function getSuccessfulResult() |
|
291 | - { |
|
292 | - return array('code' => 0, 'message' => 'Operation was successful'); |
|
293 | - } |
|
285 | + /** |
|
286 | + * Gets a successful result |
|
287 | + * |
|
288 | + * @return array Array with a code of 0 and a message 'Operation was successful' |
|
289 | + */ |
|
290 | + protected function getSuccessfulResult() |
|
291 | + { |
|
292 | + return array('code' => 0, 'message' => 'Operation was successful'); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Test function. Returns the string success |
|
297 | - * |
|
298 | - * @return string Success |
|
299 | - */ |
|
300 | - public function test() |
|
301 | - { |
|
302 | - return "success"; |
|
303 | - } |
|
295 | + /** |
|
296 | + * Test function. Returns the string success |
|
297 | + * |
|
298 | + * @return string Success |
|
299 | + */ |
|
300 | + public function test() |
|
301 | + { |
|
302 | + return "success"; |
|
303 | + } |
|
304 | 304 | |
305 | - /** |
|
306 | - * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) |
|
307 | - * @param <type> $string |
|
308 | - * @return <type> $string |
|
309 | - */ |
|
310 | - public function nl2br_revert($string) |
|
305 | + /** |
|
306 | + * *Strictly* reverts PHP's nl2br() effects (whether it was used in XHTML mode or not) |
|
307 | + * @param <type> $string |
|
308 | + * @return <type> $string |
|
309 | + */ |
|
310 | + public function nl2br_revert($string) |
|
311 | 311 | { |
312 | - return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); |
|
313 | - } |
|
312 | + return preg_replace('`<br(?: /)?>([\\n\\r])`', '$1', $string); |
|
313 | + } |
|
314 | 314 | } |
315 | 315 |