Completed
Push — 1.11.x ( 5cb77e...c87450 )
by José
367:19 queued 327:00
created
main/inc/lib/nusoap/class.nusoap_base.php 1 patch
Indentation   +845 added lines, -845 removed lines patch added patch discarded remove patch
@@ -83,809 +83,809 @@  discard block
 block discarded – undo
83 83
 * @access   public
84 84
 */
85 85
 class nusoap_base {
86
-	/**
87
-	 * Identification for HTTP headers.
88
-	 *
89
-	 * @var string
90
-	 * @access private
91
-	 */
92
-	var $title = 'NuSOAP';
93
-	/**
94
-	 * Version for HTTP headers.
95
-	 *
96
-	 * @var string
97
-	 * @access private
98
-	 */
99
-	var $version = '0.9.5';
100
-	/**
101
-	 * CVS revision for HTTP headers.
102
-	 *
103
-	 * @var string
104
-	 * @access private
105
-	 */
106
-	var $revision = '$Revision: 1.56 $';
86
+    /**
87
+     * Identification for HTTP headers.
88
+     *
89
+     * @var string
90
+     * @access private
91
+     */
92
+    var $title = 'NuSOAP';
93
+    /**
94
+     * Version for HTTP headers.
95
+     *
96
+     * @var string
97
+     * @access private
98
+     */
99
+    var $version = '0.9.5';
100
+    /**
101
+     * CVS revision for HTTP headers.
102
+     *
103
+     * @var string
104
+     * @access private
105
+     */
106
+    var $revision = '$Revision: 1.56 $';
107 107
     /**
108 108
      * Current error string (manipulated by getError/setError)
109
-	 *
110
-	 * @var string
111
-	 * @access private
112
-	 */
113
-	var $error_str = '';
109
+     *
110
+     * @var string
111
+     * @access private
112
+     */
113
+    var $error_str = '';
114 114
     /**
115 115
      * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment)
116
-	 *
117
-	 * @var string
118
-	 * @access private
119
-	 */
116
+     *
117
+     * @var string
118
+     * @access private
119
+     */
120 120
     var $debug_str = '';
121 121
     /**
122
-	 * toggles automatic encoding of special characters as entities
123
-	 * (should always be true, I think)
124
-	 *
125
-	 * @var boolean
126
-	 * @access private
127
-	 */
128
-	var $charencoding = true;
129
-	/**
130
-	 * the debug level for this instance
131
-	 *
132
-	 * @var	integer
133
-	 * @access private
134
-	 */
135
-	var $debugLevel;
136
-
137
-    /**
138
-	* set schema version
139
-	*
140
-	* @var      string
141
-	* @access   public
142
-	*/
143
-	var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
144
-
145
-    /**
146
-	* charset encoding for outgoing messages
147
-	*
148
-	* @var      string
149
-	* @access   public
150
-	*/
122
+     * toggles automatic encoding of special characters as entities
123
+     * (should always be true, I think)
124
+     *
125
+     * @var boolean
126
+     * @access private
127
+     */
128
+    var $charencoding = true;
129
+    /**
130
+     * the debug level for this instance
131
+     *
132
+     * @var	integer
133
+     * @access private
134
+     */
135
+    var $debugLevel;
136
+
137
+    /**
138
+     * set schema version
139
+     *
140
+     * @var      string
141
+     * @access   public
142
+     */
143
+    var $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema';
144
+
145
+    /**
146
+     * charset encoding for outgoing messages
147
+     *
148
+     * @var      string
149
+     * @access   public
150
+     */
151 151
     var $soap_defencoding = 'ISO-8859-1';
152
-	//var $soap_defencoding = 'UTF-8';
153
-
154
-	/**
155
-	* namespaces in an array of prefix => uri
156
-	*
157
-	* this is "seeded" by a set of constants, but it may be altered by code
158
-	*
159
-	* @var      array
160
-	* @access   public
161
-	*/
162
-	var $namespaces = array(
163
-		'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
164
-		'xsd' => 'http://www.w3.org/2001/XMLSchema',
165
-		'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
166
-		'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
167
-		);
168
-
169
-	/**
170
-	* namespaces used in the current context, e.g. during serialization
171
-	*
172
-	* @var      array
173
-	* @access   private
174
-	*/
175
-	var $usedNamespaces = array();
176
-
177
-	/**
178
-	* XML Schema types in an array of uri => (array of xml type => php type)
179
-	* is this legacy yet?
180
-	* no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
181
-	* @var      array
182
-	* @access   public
183
-	*/
184
-	var $typemap = array(
185
-	'http://www.w3.org/2001/XMLSchema' => array(
186
-		'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
187
-		'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
188
-		'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
189
-		// abstract "any" types
190
-		'anyType'=>'string','anySimpleType'=>'string',
191
-		// derived datatypes
192
-		'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
193
-		'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
194
-		'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
195
-		'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
196
-	'http://www.w3.org/2000/10/XMLSchema' => array(
197
-		'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
198
-		'float'=>'double','dateTime'=>'string',
199
-		'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
200
-	'http://www.w3.org/1999/XMLSchema' => array(
201
-		'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
202
-		'float'=>'double','dateTime'=>'string',
203
-		'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
204
-	'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
205
-	'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
152
+    //var $soap_defencoding = 'UTF-8';
153
+
154
+    /**
155
+     * namespaces in an array of prefix => uri
156
+     *
157
+     * this is "seeded" by a set of constants, but it may be altered by code
158
+     *
159
+     * @var      array
160
+     * @access   public
161
+     */
162
+    var $namespaces = array(
163
+        'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/',
164
+        'xsd' => 'http://www.w3.org/2001/XMLSchema',
165
+        'xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
166
+        'SOAP-ENC' => 'http://schemas.xmlsoap.org/soap/encoding/'
167
+        );
168
+
169
+    /**
170
+     * namespaces used in the current context, e.g. during serialization
171
+     *
172
+     * @var      array
173
+     * @access   private
174
+     */
175
+    var $usedNamespaces = array();
176
+
177
+    /**
178
+     * XML Schema types in an array of uri => (array of xml type => php type)
179
+     * is this legacy yet?
180
+     * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings.
181
+     * @var      array
182
+     * @access   public
183
+     */
184
+    var $typemap = array(
185
+    'http://www.w3.org/2001/XMLSchema' => array(
186
+        'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double',
187
+        'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'',
188
+        'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string',
189
+        // abstract "any" types
190
+        'anyType'=>'string','anySimpleType'=>'string',
191
+        // derived datatypes
192
+        'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'',
193
+        'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer',
194
+        'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer',
195
+        'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''),
196
+    'http://www.w3.org/2000/10/XMLSchema' => array(
197
+        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
198
+        'float'=>'double','dateTime'=>'string',
199
+        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
200
+    'http://www.w3.org/1999/XMLSchema' => array(
201
+        'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double',
202
+        'float'=>'double','dateTime'=>'string',
203
+        'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'),
204
+    'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'),
205
+    'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'),
206 206
     'http://xml.apache.org/xml-soap' => array('Map')
207
-	);
208
-
209
-	/**
210
-	* XML entities to convert
211
-	*
212
-	* @var      array
213
-	* @access   public
214
-	* @deprecated
215
-	* @see	expandEntities
216
-	*/
217
-	var $xmlEntities = array('quot' => '"','amp' => '&',
218
-		'lt' => '<','gt' => '>','apos' => "'");
219
-
220
-	/**
221
-	* constructor
222
-	*
223
-	* @access	public
224
-	*/
225
-	function __construct() {
226
-		$this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
227
-	}
228
-
229
-	/**
230
-	* gets the global debug level, which applies to future instances
231
-	*
232
-	* @return	integer	Debug level 0-9, where 0 turns off
233
-	* @access	public
234
-	*/
235
-	function getGlobalDebugLevel() {
236
-		return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
237
-	}
238
-
239
-	/**
240
-	* sets the global debug level, which applies to future instances
241
-	*
242
-	* @param	int	$level	Debug level 0-9, where 0 turns off
243
-	* @access	public
244
-	*/
245
-	function setGlobalDebugLevel($level) {
246
-		$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
247
-	}
248
-
249
-	/**
250
-	* gets the debug level for this instance
251
-	*
252
-	* @return	int	Debug level 0-9, where 0 turns off
253
-	* @access	public
254
-	*/
255
-	function getDebugLevel() {
256
-		return $this->debugLevel;
257
-	}
258
-
259
-	/**
260
-	* sets the debug level for this instance
261
-	*
262
-	* @param	int	$level	Debug level 0-9, where 0 turns off
263
-	* @access	public
264
-	*/
265
-	function setDebugLevel($level) {
266
-		$this->debugLevel = $level;
267
-	}
268
-
269
-	/**
270
-	* adds debug data to the instance debug string with formatting
271
-	*
272
-	* @param    string $string debug data
273
-	* @access   private
274
-	*/
275
-	function debug($string){
276
-		if ($this->debugLevel > 0) {
277
-			$this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
278
-		}
279
-	}
280
-
281
-	/**
282
-	* adds debug data to the instance debug string without formatting
283
-	*
284
-	* @param    string $string debug data
285
-	* @access   public
286
-	*/
287
-	function appendDebug($string){
288
-		if ($this->debugLevel > 0) {
289
-			// it would be nice to use a memory stream here to use
290
-			// memory more efficiently
291
-			$this->debug_str .= $string;
292
-		}
293
-	}
294
-
295
-	/**
296
-	* clears the current debug data for this instance
297
-	*
298
-	* @access   public
299
-	*/
300
-	function clearDebug() {
301
-		// it would be nice to use a memory stream here to use
302
-		// memory more efficiently
303
-		$this->debug_str = '';
304
-	}
305
-
306
-	/**
307
-	* gets the current debug data for this instance
308
-	*
309
-	* @return   debug data
310
-	* @access   public
311
-	*/
312
-	function &getDebug() {
313
-		// it would be nice to use a memory stream here to use
314
-		// memory more efficiently
315
-		return $this->debug_str;
316
-	}
317
-
318
-	/**
319
-	* gets the current debug data for this instance as an XML comment
320
-	* this may change the contents of the debug data
321
-	*
322
-	* @return   debug data as an XML comment
323
-	* @access   public
324
-	*/
325
-	function &getDebugAsXMLComment() {
326
-		// it would be nice to use a memory stream here to use
327
-		// memory more efficiently
328
-		while (strpos($this->debug_str, '--')) {
329
-			$this->debug_str = str_replace('--', '- -', $this->debug_str);
330
-		}
331
-		$ret = "<!--\n" . $this->debug_str . "\n-->";
332
-    	return $ret;
333
-	}
334
-
335
-	/**
336
-	* expands entities, e.g. changes '<' to '&lt;'.
337
-	*
338
-	* @param	string	$val	The string in which to expand entities.
339
-	* @access	private
340
-	*/
341
-	function expandEntities($val) {
342
-		if ($this->charencoding) {
343
-	    	$val = str_replace('&', '&amp;', $val);
344
-	    	$val = str_replace("'", '&apos;', $val);
345
-	    	$val = str_replace('"', '&quot;', $val);
346
-	    	$val = str_replace('<', '&lt;', $val);
347
-	    	$val = str_replace('>', '&gt;', $val);
348
-	    }
349
-	    return $val;
350
-	}
351
-
352
-	/**
353
-	* returns error string if present
354
-	*
355
-	* @return   mixed error string or false
356
-	* @access   public
357
-	*/
358
-	function getError(){
359
-		if($this->error_str != ''){
360
-			return $this->error_str;
361
-		}
362
-		return false;
363
-	}
364
-
365
-	/**
366
-	* sets error string
367
-	*
368
-	* @return   boolean $string error string
369
-	* @access   private
370
-	*/
371
-	function setError($str){
372
-		$this->error_str = $str;
373
-	}
374
-
375
-	/**
376
-	* detect if array is a simple array or a struct (associative array)
377
-	*
378
-	* @param	mixed	$val	The PHP array
379
-	* @return	string	(arraySimple|arrayStruct)
380
-	* @access	private
381
-	*/
382
-	function isArraySimpleOrStruct($val) {
207
+    );
208
+
209
+    /**
210
+     * XML entities to convert
211
+     *
212
+     * @var      array
213
+     * @access   public
214
+     * @deprecated
215
+     * @see	expandEntities
216
+     */
217
+    var $xmlEntities = array('quot' => '"','amp' => '&',
218
+        'lt' => '<','gt' => '>','apos' => "'");
219
+
220
+    /**
221
+     * constructor
222
+     *
223
+     * @access	public
224
+     */
225
+    function __construct() {
226
+        $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
227
+    }
228
+
229
+    /**
230
+     * gets the global debug level, which applies to future instances
231
+     *
232
+     * @return	integer	Debug level 0-9, where 0 turns off
233
+     * @access	public
234
+     */
235
+    function getGlobalDebugLevel() {
236
+        return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'];
237
+    }
238
+
239
+    /**
240
+     * sets the global debug level, which applies to future instances
241
+     *
242
+     * @param	int	$level	Debug level 0-9, where 0 turns off
243
+     * @access	public
244
+     */
245
+    function setGlobalDebugLevel($level) {
246
+        $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level;
247
+    }
248
+
249
+    /**
250
+     * gets the debug level for this instance
251
+     *
252
+     * @return	int	Debug level 0-9, where 0 turns off
253
+     * @access	public
254
+     */
255
+    function getDebugLevel() {
256
+        return $this->debugLevel;
257
+    }
258
+
259
+    /**
260
+     * sets the debug level for this instance
261
+     *
262
+     * @param	int	$level	Debug level 0-9, where 0 turns off
263
+     * @access	public
264
+     */
265
+    function setDebugLevel($level) {
266
+        $this->debugLevel = $level;
267
+    }
268
+
269
+    /**
270
+     * adds debug data to the instance debug string with formatting
271
+     *
272
+     * @param    string $string debug data
273
+     * @access   private
274
+     */
275
+    function debug($string){
276
+        if ($this->debugLevel > 0) {
277
+            $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n");
278
+        }
279
+    }
280
+
281
+    /**
282
+     * adds debug data to the instance debug string without formatting
283
+     *
284
+     * @param    string $string debug data
285
+     * @access   public
286
+     */
287
+    function appendDebug($string){
288
+        if ($this->debugLevel > 0) {
289
+            // it would be nice to use a memory stream here to use
290
+            // memory more efficiently
291
+            $this->debug_str .= $string;
292
+        }
293
+    }
294
+
295
+    /**
296
+     * clears the current debug data for this instance
297
+     *
298
+     * @access   public
299
+     */
300
+    function clearDebug() {
301
+        // it would be nice to use a memory stream here to use
302
+        // memory more efficiently
303
+        $this->debug_str = '';
304
+    }
305
+
306
+    /**
307
+     * gets the current debug data for this instance
308
+     *
309
+     * @return   debug data
310
+     * @access   public
311
+     */
312
+    function &getDebug() {
313
+        // it would be nice to use a memory stream here to use
314
+        // memory more efficiently
315
+        return $this->debug_str;
316
+    }
317
+
318
+    /**
319
+     * gets the current debug data for this instance as an XML comment
320
+     * this may change the contents of the debug data
321
+     *
322
+     * @return   debug data as an XML comment
323
+     * @access   public
324
+     */
325
+    function &getDebugAsXMLComment() {
326
+        // it would be nice to use a memory stream here to use
327
+        // memory more efficiently
328
+        while (strpos($this->debug_str, '--')) {
329
+            $this->debug_str = str_replace('--', '- -', $this->debug_str);
330
+        }
331
+        $ret = "<!--\n" . $this->debug_str . "\n-->";
332
+        return $ret;
333
+    }
334
+
335
+    /**
336
+     * expands entities, e.g. changes '<' to '&lt;'.
337
+     *
338
+     * @param	string	$val	The string in which to expand entities.
339
+     * @access	private
340
+     */
341
+    function expandEntities($val) {
342
+        if ($this->charencoding) {
343
+            $val = str_replace('&', '&amp;', $val);
344
+            $val = str_replace("'", '&apos;', $val);
345
+            $val = str_replace('"', '&quot;', $val);
346
+            $val = str_replace('<', '&lt;', $val);
347
+            $val = str_replace('>', '&gt;', $val);
348
+        }
349
+        return $val;
350
+    }
351
+
352
+    /**
353
+     * returns error string if present
354
+     *
355
+     * @return   mixed error string or false
356
+     * @access   public
357
+     */
358
+    function getError(){
359
+        if($this->error_str != ''){
360
+            return $this->error_str;
361
+        }
362
+        return false;
363
+    }
364
+
365
+    /**
366
+     * sets error string
367
+     *
368
+     * @return   boolean $string error string
369
+     * @access   private
370
+     */
371
+    function setError($str){
372
+        $this->error_str = $str;
373
+    }
374
+
375
+    /**
376
+     * detect if array is a simple array or a struct (associative array)
377
+     *
378
+     * @param	mixed	$val	The PHP array
379
+     * @return	string	(arraySimple|arrayStruct)
380
+     * @access	private
381
+     */
382
+    function isArraySimpleOrStruct($val) {
383 383
         $keyList = array_keys($val);
384
-		foreach ($keyList as $keyListValue) {
385
-			if (!is_int($keyListValue)) {
386
-				return 'arrayStruct';
387
-			}
388
-		}
389
-		return 'arraySimple';
390
-	}
391
-
392
-	/**
393
-	* serializes PHP values in accordance w/ section 5. Type information is
394
-	* not serialized if $use == 'literal'.
395
-	*
396
-	* @param	mixed	$val	The value to serialize
397
-	* @param	string	$name	The name (local part) of the XML element
398
-	* @param	string	$type	The XML schema type (local part) for the element
399
-	* @param	string	$name_ns	The namespace for the name of the XML element
400
-	* @param	string	$type_ns	The namespace for the type of the element
401
-	* @param	array	$attributes	The attributes to serialize as name=>value pairs
402
-	* @param	string	$use	The WSDL "use" (encoded|literal)
403
-	* @param	boolean	$soapval	Whether this is called from soapval.
404
-	* @return	string	The serialized element, possibly with child elements
405
-    * @access	public
406
-	*/
407
-	function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
408
-		$this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
409
-		$this->appendDebug('value=' . $this->varDump($val));
410
-		$this->appendDebug('attributes=' . $this->varDump($attributes));
411
-
412
-    	if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
413
-    		$this->debug("serialize_val: serialize soapval");
414
-        	$xml = $val->serialize($use);
415
-			$this->appendDebug($val->getDebug());
416
-			$val->clearDebug();
417
-			$this->debug("serialize_val of soapval returning $xml");
418
-			return $xml;
384
+        foreach ($keyList as $keyListValue) {
385
+            if (!is_int($keyListValue)) {
386
+                return 'arrayStruct';
387
+            }
419 388
         }
420
-		// force valid name if necessary
421
-		if (is_numeric($name)) {
422
-			$name = '__numeric_' . $name;
423
-		} elseif (! $name) {
424
-			$name = 'noname';
425
-		}
426
-		// if name has ns, add ns prefix to name
427
-		$xmlns = '';
389
+        return 'arraySimple';
390
+    }
391
+
392
+    /**
393
+     * serializes PHP values in accordance w/ section 5. Type information is
394
+     * not serialized if $use == 'literal'.
395
+     *
396
+     * @param	mixed	$val	The value to serialize
397
+     * @param	string	$name	The name (local part) of the XML element
398
+     * @param	string	$type	The XML schema type (local part) for the element
399
+     * @param	string	$name_ns	The namespace for the name of the XML element
400
+     * @param	string	$type_ns	The namespace for the type of the element
401
+     * @param	array	$attributes	The attributes to serialize as name=>value pairs
402
+     * @param	string	$use	The WSDL "use" (encoded|literal)
403
+     * @param	boolean	$soapval	Whether this is called from soapval.
404
+     * @return	string	The serialized element, possibly with child elements
405
+     * @access	public
406
+     */
407
+    function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) {
408
+        $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval");
409
+        $this->appendDebug('value=' . $this->varDump($val));
410
+        $this->appendDebug('attributes=' . $this->varDump($attributes));
411
+
412
+        if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) {
413
+            $this->debug("serialize_val: serialize soapval");
414
+            $xml = $val->serialize($use);
415
+            $this->appendDebug($val->getDebug());
416
+            $val->clearDebug();
417
+            $this->debug("serialize_val of soapval returning $xml");
418
+            return $xml;
419
+        }
420
+        // force valid name if necessary
421
+        if (is_numeric($name)) {
422
+            $name = '__numeric_' . $name;
423
+        } elseif (! $name) {
424
+            $name = 'noname';
425
+        }
426
+        // if name has ns, add ns prefix to name
427
+        $xmlns = '';
428 428
         if($name_ns){
429
-			$prefix = 'nu'.rand(1000,9999);
430
-			$name = $prefix.':'.$name;
431
-			$xmlns .= " xmlns:$prefix=\"$name_ns\"";
432
-		}
433
-		// if type is prefixed, create type prefix
434
-		if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
435
-			// need to fix this. shouldn't default to xsd if no ns specified
436
-		    // w/o checking against typemap
437
-			$type_prefix = 'xsd';
438
-		} elseif($type_ns){
439
-			$type_prefix = 'ns'.rand(1000,9999);
440
-			$xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
441
-		}
442
-		// serialize attributes if present
443
-		$atts = '';
444
-		if($attributes){
445
-			foreach($attributes as $k => $v){
446
-				$atts .= " $k=\"".$this->expandEntities($v).'"';
447
-			}
448
-		}
449
-		// serialize null value
450
-		if (is_null($val)) {
451
-    		$this->debug("serialize_val: serialize null");
452
-			if ($use == 'literal') {
453
-				// TODO: depends on minOccurs
454
-				$xml = "<$name$xmlns$atts/>";
455
-				$this->debug("serialize_val returning $xml");
456
-	        	return $xml;
457
-        	} else {
458
-				if (isset($type) && isset($type_prefix)) {
459
-					$type_str = " xsi:type=\"$type_prefix:$type\"";
460
-				} else {
461
-					$type_str = '';
462
-				}
463
-				$xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
464
-				$this->debug("serialize_val returning $xml");
465
-	        	return $xml;
466
-        	}
467
-		}
429
+            $prefix = 'nu'.rand(1000,9999);
430
+            $name = $prefix.':'.$name;
431
+            $xmlns .= " xmlns:$prefix=\"$name_ns\"";
432
+        }
433
+        // if type is prefixed, create type prefix
434
+        if($type_ns != '' && $type_ns == $this->namespaces['xsd']){
435
+            // need to fix this. shouldn't default to xsd if no ns specified
436
+            // w/o checking against typemap
437
+            $type_prefix = 'xsd';
438
+        } elseif($type_ns){
439
+            $type_prefix = 'ns'.rand(1000,9999);
440
+            $xmlns .= " xmlns:$type_prefix=\"$type_ns\"";
441
+        }
442
+        // serialize attributes if present
443
+        $atts = '';
444
+        if($attributes){
445
+            foreach($attributes as $k => $v){
446
+                $atts .= " $k=\"".$this->expandEntities($v).'"';
447
+            }
448
+        }
449
+        // serialize null value
450
+        if (is_null($val)) {
451
+            $this->debug("serialize_val: serialize null");
452
+            if ($use == 'literal') {
453
+                // TODO: depends on minOccurs
454
+                $xml = "<$name$xmlns$atts/>";
455
+                $this->debug("serialize_val returning $xml");
456
+                return $xml;
457
+            } else {
458
+                if (isset($type) && isset($type_prefix)) {
459
+                    $type_str = " xsi:type=\"$type_prefix:$type\"";
460
+                } else {
461
+                    $type_str = '';
462
+                }
463
+                $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>";
464
+                $this->debug("serialize_val returning $xml");
465
+                return $xml;
466
+            }
467
+        }
468 468
         // serialize if an xsd built-in primitive type
469 469
         if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){
470
-    		$this->debug("serialize_val: serialize xsd built-in primitive type");
471
-        	if (is_bool($val)) {
472
-        		if ($type == 'boolean') {
473
-	        		$val = $val ? 'true' : 'false';
474
-	        	} elseif (! $val) {
475
-	        		$val = 0;
476
-	        	}
477
-			} else if (is_string($val)) {
478
-				$val = $this->expandEntities($val);
479
-			}
480
-			if ($use == 'literal') {
481
-				$xml = "<$name$xmlns$atts>$val</$name>";
482
-				$this->debug("serialize_val returning $xml");
483
-	        	return $xml;
484
-        	} else {
485
-				$xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
486
-				$this->debug("serialize_val returning $xml");
487
-	        	return $xml;
488
-        	}
470
+            $this->debug("serialize_val: serialize xsd built-in primitive type");
471
+            if (is_bool($val)) {
472
+                if ($type == 'boolean') {
473
+                    $val = $val ? 'true' : 'false';
474
+                } elseif (! $val) {
475
+                    $val = 0;
476
+                }
477
+            } else if (is_string($val)) {
478
+                $val = $this->expandEntities($val);
479
+            }
480
+            if ($use == 'literal') {
481
+                $xml = "<$name$xmlns$atts>$val</$name>";
482
+                $this->debug("serialize_val returning $xml");
483
+                return $xml;
484
+            } else {
485
+                $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>";
486
+                $this->debug("serialize_val returning $xml");
487
+                return $xml;
488
+            }
489 489
         }
490
-		// detect type and serialize
491
-		$xml = '';
492
-		switch(true) {
493
-			case (is_bool($val) || $type == 'boolean'):
494
-		   		$this->debug("serialize_val: serialize boolean");
495
-        		if ($type == 'boolean') {
496
-	        		$val = $val ? 'true' : 'false';
497
-	        	} elseif (! $val) {
498
-	        		$val = 0;
499
-	        	}
500
-				if ($use == 'literal') {
501
-					$xml .= "<$name$xmlns$atts>$val</$name>";
502
-				} else {
503
-					$xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
504
-				}
505
-				break;
506
-			case (is_int($val) || is_long($val) || $type == 'int'):
507
-		   		$this->debug("serialize_val: serialize int");
508
-				if ($use == 'literal') {
509
-					$xml .= "<$name$xmlns$atts>$val</$name>";
510
-				} else {
511
-					$xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
512
-				}
513
-				break;
514
-			case (is_float($val)|| is_double($val) || $type == 'float'):
515
-		   		$this->debug("serialize_val: serialize float");
516
-				if ($use == 'literal') {
517
-					$xml .= "<$name$xmlns$atts>$val</$name>";
518
-				} else {
519
-					$xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
520
-				}
521
-				break;
522
-			case (is_string($val) || $type == 'string'):
523
-		   		$this->debug("serialize_val: serialize string");
524
-				$val = $this->expandEntities($val);
525
-				if ($use == 'literal') {
526
-					$xml .= "<$name$xmlns$atts>$val</$name>";
527
-				} else {
528
-					$xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
529
-				}
530
-				break;
531
-			case is_object($val):
532
-		   		$this->debug("serialize_val: serialize object");
533
-		    	if (get_class($val) == 'soapval') {
534
-		    		$this->debug("serialize_val: serialize soapval object");
535
-		        	$pXml = $val->serialize($use);
536
-					$this->appendDebug($val->getDebug());
537
-					$val->clearDebug();
538
-		        } else {
539
-					if (! $name) {
540
-						$name = get_class($val);
541
-						$this->debug("In serialize_val, used class name $name as element name");
542
-					} else {
543
-						$this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
544
-					}
545
-					foreach(get_object_vars($val) as $k => $v){
546
-						$pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
547
-					}
548
-				}
549
-				if(isset($type) && isset($type_prefix)){
550
-					$type_str = " xsi:type=\"$type_prefix:$type\"";
551
-				} else {
552
-					$type_str = '';
553
-				}
554
-				if ($use == 'literal') {
555
-					$xml .= "<$name$xmlns$atts>$pXml</$name>";
556
-				} else {
557
-					$xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
558
-				}
559
-				break;
560
-			case (is_array($val) || $type):
561
-				// detect if struct or array
562
-				$valueType = $this->isArraySimpleOrStruct($val);
490
+        // detect type and serialize
491
+        $xml = '';
492
+        switch(true) {
493
+            case (is_bool($val) || $type == 'boolean'):
494
+                   $this->debug("serialize_val: serialize boolean");
495
+                if ($type == 'boolean') {
496
+                    $val = $val ? 'true' : 'false';
497
+                } elseif (! $val) {
498
+                    $val = 0;
499
+                }
500
+                if ($use == 'literal') {
501
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
502
+                } else {
503
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:boolean\"$atts>$val</$name>";
504
+                }
505
+                break;
506
+            case (is_int($val) || is_long($val) || $type == 'int'):
507
+                   $this->debug("serialize_val: serialize int");
508
+                if ($use == 'literal') {
509
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
510
+                } else {
511
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>";
512
+                }
513
+                break;
514
+            case (is_float($val)|| is_double($val) || $type == 'float'):
515
+                   $this->debug("serialize_val: serialize float");
516
+                if ($use == 'literal') {
517
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
518
+                } else {
519
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:float\"$atts>$val</$name>";
520
+                }
521
+                break;
522
+            case (is_string($val) || $type == 'string'):
523
+                   $this->debug("serialize_val: serialize string");
524
+                $val = $this->expandEntities($val);
525
+                if ($use == 'literal') {
526
+                    $xml .= "<$name$xmlns$atts>$val</$name>";
527
+                } else {
528
+                    $xml .= "<$name$xmlns xsi:type=\"xsd:string\"$atts>$val</$name>";
529
+                }
530
+                break;
531
+            case is_object($val):
532
+                   $this->debug("serialize_val: serialize object");
533
+                if (get_class($val) == 'soapval') {
534
+                    $this->debug("serialize_val: serialize soapval object");
535
+                    $pXml = $val->serialize($use);
536
+                    $this->appendDebug($val->getDebug());
537
+                    $val->clearDebug();
538
+                } else {
539
+                    if (! $name) {
540
+                        $name = get_class($val);
541
+                        $this->debug("In serialize_val, used class name $name as element name");
542
+                    } else {
543
+                        $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val));
544
+                    }
545
+                    foreach(get_object_vars($val) as $k => $v){
546
+                        $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use);
547
+                    }
548
+                }
549
+                if(isset($type) && isset($type_prefix)){
550
+                    $type_str = " xsi:type=\"$type_prefix:$type\"";
551
+                } else {
552
+                    $type_str = '';
553
+                }
554
+                if ($use == 'literal') {
555
+                    $xml .= "<$name$xmlns$atts>$pXml</$name>";
556
+                } else {
557
+                    $xml .= "<$name$xmlns$type_str$atts>$pXml</$name>";
558
+                }
559
+                break;
560
+            case (is_array($val) || $type):
561
+                // detect if struct or array
562
+                $valueType = $this->isArraySimpleOrStruct($val);
563 563
                 if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){
564
-			   		$this->debug("serialize_val: serialize array");
565
-					$i = 0;
566
-					if(is_array($val) && count($val)> 0){
567
-						foreach($val as $v){
568
-	                    	if(is_object($v) && get_class($v) ==  'soapval'){
569
-								$tt_ns = $v->type_ns;
570
-								$tt = $v->type;
571
-							} elseif (is_array($v)) {
572
-								$tt = $this->isArraySimpleOrStruct($v);
573
-							} else {
574
-								$tt = gettype($v);
575
-	                        }
576
-							$array_types[$tt] = 1;
577
-							// TODO: for literal, the name should be $name
578
-							$xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
579
-							++$i;
580
-						}
581
-						if(count($array_types) > 1){
582
-							$array_typename = 'xsd:anyType';
583
-						} elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
584
-							if ($tt == 'integer') {
585
-								$tt = 'int';
586
-							}
587
-							$array_typename = 'xsd:'.$tt;
588
-						} elseif(isset($tt) && $tt == 'arraySimple'){
589
-							$array_typename = 'SOAP-ENC:Array';
590
-						} elseif(isset($tt) && $tt == 'arrayStruct'){
591
-							$array_typename = 'unnamed_struct_use_soapval';
592
-						} else {
593
-							// if type is prefixed, create type prefix
594
-							if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
595
-								 $array_typename = 'xsd:' . $tt;
596
-							} elseif ($tt_ns) {
597
-								$tt_prefix = 'ns' . rand(1000, 9999);
598
-								$array_typename = "$tt_prefix:$tt";
599
-								$xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
600
-							} else {
601
-								$array_typename = $tt;
602
-							}
603
-						}
604
-						$array_type = $i;
605
-						if ($use == 'literal') {
606
-							$type_str = '';
607
-						} else if (isset($type) && isset($type_prefix)) {
608
-							$type_str = " xsi:type=\"$type_prefix:$type\"";
609
-						} else {
610
-							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
611
-						}
612
-					// empty array
613
-					} else {
614
-						if ($use == 'literal') {
615
-							$type_str = '';
616
-						} else if (isset($type) && isset($type_prefix)) {
617
-							$type_str = " xsi:type=\"$type_prefix:$type\"";
618
-						} else {
619
-							$type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
620
-						}
621
-					}
622
-					// TODO: for array in literal, there is no wrapper here
623
-					$xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
624
-				} else {
625
-					// got a struct
626
-			   		$this->debug("serialize_val: serialize struct");
627
-					if(isset($type) && isset($type_prefix)){
628
-						$type_str = " xsi:type=\"$type_prefix:$type\"";
629
-					} else {
630
-						$type_str = '';
631
-					}
632
-					if ($use == 'literal') {
633
-						$xml .= "<$name$xmlns$atts>";
634
-					} else {
635
-						$xml .= "<$name$xmlns$type_str$atts>";
636
-					}
637
-					foreach($val as $k => $v){
638
-						// Apache Map
639
-						if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
640
-							$xml .= '<item>';
641
-							$xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
642
-							$xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
643
-							$xml .= '</item>';
644
-						} else {
645
-							$xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
646
-						}
647
-					}
648
-					$xml .= "</$name>";
649
-				}
650
-				break;
651
-			default:
652
-		   		$this->debug("serialize_val: serialize unknown");
653
-				$xml .= 'not detected, got '.gettype($val).' for '.$val;
654
-				break;
655
-		}
656
-		$this->debug("serialize_val returning $xml");
657
-		return $xml;
658
-	}
659
-
660
-    /**
661
-    * serializes a message
662
-    *
663
-    * @param string $body the XML of the SOAP body
664
-    * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
665
-    * @param array $namespaces optional the namespaces used in generating the body and headers
666
-    * @param string $style optional (rpc|document)
667
-    * @param string $use optional (encoded|literal)
668
-    * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
669
-    * @return string the message
670
-    * @access public
671
-    */
564
+                        $this->debug("serialize_val: serialize array");
565
+                    $i = 0;
566
+                    if(is_array($val) && count($val)> 0){
567
+                        foreach($val as $v){
568
+                            if(is_object($v) && get_class($v) ==  'soapval'){
569
+                                $tt_ns = $v->type_ns;
570
+                                $tt = $v->type;
571
+                            } elseif (is_array($v)) {
572
+                                $tt = $this->isArraySimpleOrStruct($v);
573
+                            } else {
574
+                                $tt = gettype($v);
575
+                            }
576
+                            $array_types[$tt] = 1;
577
+                            // TODO: for literal, the name should be $name
578
+                            $xml .= $this->serialize_val($v,'item',false,false,false,false,$use);
579
+                            ++$i;
580
+                        }
581
+                        if(count($array_types) > 1){
582
+                            $array_typename = 'xsd:anyType';
583
+                        } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) {
584
+                            if ($tt == 'integer') {
585
+                                $tt = 'int';
586
+                            }
587
+                            $array_typename = 'xsd:'.$tt;
588
+                        } elseif(isset($tt) && $tt == 'arraySimple'){
589
+                            $array_typename = 'SOAP-ENC:Array';
590
+                        } elseif(isset($tt) && $tt == 'arrayStruct'){
591
+                            $array_typename = 'unnamed_struct_use_soapval';
592
+                        } else {
593
+                            // if type is prefixed, create type prefix
594
+                            if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){
595
+                                    $array_typename = 'xsd:' . $tt;
596
+                            } elseif ($tt_ns) {
597
+                                $tt_prefix = 'ns' . rand(1000, 9999);
598
+                                $array_typename = "$tt_prefix:$tt";
599
+                                $xmlns .= " xmlns:$tt_prefix=\"$tt_ns\"";
600
+                            } else {
601
+                                $array_typename = $tt;
602
+                            }
603
+                        }
604
+                        $array_type = $i;
605
+                        if ($use == 'literal') {
606
+                            $type_str = '';
607
+                        } else if (isset($type) && isset($type_prefix)) {
608
+                            $type_str = " xsi:type=\"$type_prefix:$type\"";
609
+                        } else {
610
+                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\"";
611
+                        }
612
+                    // empty array
613
+                    } else {
614
+                        if ($use == 'literal') {
615
+                            $type_str = '';
616
+                        } else if (isset($type) && isset($type_prefix)) {
617
+                            $type_str = " xsi:type=\"$type_prefix:$type\"";
618
+                        } else {
619
+                            $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\"";
620
+                        }
621
+                    }
622
+                    // TODO: for array in literal, there is no wrapper here
623
+                    $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>";
624
+                } else {
625
+                    // got a struct
626
+                        $this->debug("serialize_val: serialize struct");
627
+                    if(isset($type) && isset($type_prefix)){
628
+                        $type_str = " xsi:type=\"$type_prefix:$type\"";
629
+                    } else {
630
+                        $type_str = '';
631
+                    }
632
+                    if ($use == 'literal') {
633
+                        $xml .= "<$name$xmlns$atts>";
634
+                    } else {
635
+                        $xml .= "<$name$xmlns$type_str$atts>";
636
+                    }
637
+                    foreach($val as $k => $v){
638
+                        // Apache Map
639
+                        if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') {
640
+                            $xml .= '<item>';
641
+                            $xml .= $this->serialize_val($k,'key',false,false,false,false,$use);
642
+                            $xml .= $this->serialize_val($v,'value',false,false,false,false,$use);
643
+                            $xml .= '</item>';
644
+                        } else {
645
+                            $xml .= $this->serialize_val($v,$k,false,false,false,false,$use);
646
+                        }
647
+                    }
648
+                    $xml .= "</$name>";
649
+                }
650
+                break;
651
+            default:
652
+                   $this->debug("serialize_val: serialize unknown");
653
+                $xml .= 'not detected, got '.gettype($val).' for '.$val;
654
+                break;
655
+        }
656
+        $this->debug("serialize_val returning $xml");
657
+        return $xml;
658
+    }
659
+
660
+    /**
661
+     * serializes a message
662
+     *
663
+     * @param string $body the XML of the SOAP body
664
+     * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array
665
+     * @param array $namespaces optional the namespaces used in generating the body and headers
666
+     * @param string $style optional (rpc|document)
667
+     * @param string $use optional (encoded|literal)
668
+     * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded)
669
+     * @return string the message
670
+     * @access public
671
+     */
672 672
     function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){
673 673
     // TODO: add an option to automatically run utf8_encode on $body and $headers
674 674
     // if $this->soap_defencoding is UTF-8.  Not doing this automatically allows
675 675
     // one to send arbitrary UTF-8 characters, not just characters that map to ISO-8859-1
676 676
 
677
-	$this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
678
-	$this->debug("headers:");
679
-	$this->appendDebug($this->varDump($headers));
680
-	$this->debug("namespaces:");
681
-	$this->appendDebug($this->varDump($namespaces));
677
+    $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle");
678
+    $this->debug("headers:");
679
+    $this->appendDebug($this->varDump($headers));
680
+    $this->debug("namespaces:");
681
+    $this->appendDebug($this->varDump($namespaces));
682 682
 
683
-	// serialize namespaces
683
+    // serialize namespaces
684 684
     $ns_string = '';
685
-	foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
686
-		$ns_string .= " xmlns:$k=\"$v\"";
687
-	}
688
-	if($encodingStyle) {
689
-		$ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
690
-	}
691
-
692
-	// serialize headers
693
-	if($headers){
694
-		if (is_array($headers)) {
695
-			$xml = '';
696
-			foreach ($headers as $k => $v) {
697
-				if (is_object($v) && get_class($v) == 'soapval') {
698
-					$xml .= $this->serialize_val($v, false, false, false, false, false, $use);
699
-				} else {
700
-					$xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
701
-				}
702
-			}
703
-			$headers = $xml;
704
-			$this->debug("In serializeEnvelope, serialized array of headers to $headers");
705
-		}
706
-		$headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
707
-	}
708
-	// serialize envelope
709
-	return
710
-	'<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
711
-	'<SOAP-ENV:Envelope'.$ns_string.">".
712
-	$headers.
713
-	"<SOAP-ENV:Body>".
714
-		$body.
715
-	"</SOAP-ENV:Body>".
716
-	"</SOAP-ENV:Envelope>";
717
-    }
718
-
719
-	/**
720
-	 * formats a string to be inserted into an HTML stream
721
-	 *
722
-	 * @param string $str The string to format
723
-	 * @return string The formatted string
724
-	 * @access public
725
-	 * @deprecated
726
-	 */
685
+    foreach(array_merge($this->namespaces,$namespaces) as $k => $v){
686
+        $ns_string .= " xmlns:$k=\"$v\"";
687
+    }
688
+    if($encodingStyle) {
689
+        $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string";
690
+    }
691
+
692
+    // serialize headers
693
+    if($headers){
694
+        if (is_array($headers)) {
695
+            $xml = '';
696
+            foreach ($headers as $k => $v) {
697
+                if (is_object($v) && get_class($v) == 'soapval') {
698
+                    $xml .= $this->serialize_val($v, false, false, false, false, false, $use);
699
+                } else {
700
+                    $xml .= $this->serialize_val($v, $k, false, false, false, false, $use);
701
+                }
702
+            }
703
+            $headers = $xml;
704
+            $this->debug("In serializeEnvelope, serialized array of headers to $headers");
705
+        }
706
+        $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>";
707
+    }
708
+    // serialize envelope
709
+    return
710
+    '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">".
711
+    '<SOAP-ENV:Envelope'.$ns_string.">".
712
+    $headers.
713
+    "<SOAP-ENV:Body>".
714
+        $body.
715
+    "</SOAP-ENV:Body>".
716
+    "</SOAP-ENV:Envelope>";
717
+    }
718
+
719
+    /**
720
+     * formats a string to be inserted into an HTML stream
721
+     *
722
+     * @param string $str The string to format
723
+     * @return string The formatted string
724
+     * @access public
725
+     * @deprecated
726
+     */
727 727
     function formatDump($str){
728
-		$str = htmlspecialchars($str);
729
-		return nl2br($str);
730
-    }
731
-
732
-	/**
733
-	* contracts (changes namespace to prefix) a qualified name
734
-	*
735
-	* @param    string $qname qname
736
-	* @return	string contracted qname
737
-	* @access   private
738
-	*/
739
-	function contractQname($qname){
740
-		// get element namespace
741
-		//$this->xdebug("Contract $qname");
742
-		if (strrpos($qname, ':')) {
743
-			// get unqualified name
744
-			$name = substr($qname, strrpos($qname, ':') + 1);
745
-			// get ns
746
-			$ns = substr($qname, 0, strrpos($qname, ':'));
747
-			$p = $this->getPrefixFromNamespace($ns);
748
-			if ($p) {
749
-				return $p . ':' . $name;
750
-			}
751
-			return $qname;
752
-		} else {
753
-			return $qname;
754
-		}
755
-	}
756
-
757
-	/**
758
-	* expands (changes prefix to namespace) a qualified name
759
-	*
760
-	* @param    string $qname qname
761
-	* @return	string expanded qname
762
-	* @access   private
763
-	*/
764
-	function expandQname($qname){
765
-		// get element prefix
766
-		if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){
767
-			// get unqualified name
768
-			$name = substr(strstr($qname,':'),1);
769
-			// get ns prefix
770
-			$prefix = substr($qname,0,strpos($qname,':'));
771
-			if(isset($this->namespaces[$prefix])){
772
-				return $this->namespaces[$prefix].':'.$name;
773
-			} else {
774
-				return $qname;
775
-			}
776
-		} else {
777
-			return $qname;
778
-		}
779
-	}
780
-
781
-    /**
782
-    * returns the local part of a prefixed string
783
-    * returns the original string, if not prefixed
784
-    *
785
-    * @param string $str The prefixed string
786
-    * @return string The local part
787
-    * @access public
788
-    */
789
-	function getLocalPart($str){
790
-		if($sstr = strrchr($str,':')){
791
-			// get unqualified name
792
-			return substr( $sstr, 1 );
793
-		} else {
794
-			return $str;
795
-		}
796
-	}
797
-
798
-	/**
799
-    * returns the prefix part of a prefixed string
800
-    * returns false, if not prefixed
801
-    *
802
-    * @param string $str The prefixed string
803
-    * @return mixed The prefix or false if there is no prefix
804
-    * @access public
805
-    */
806
-	function getPrefix($str){
807
-		if($pos = strrpos($str,':')){
808
-			// get prefix
809
-			return substr($str,0,$pos);
810
-		}
811
-		return false;
812
-	}
813
-
814
-	/**
815
-    * pass it a prefix, it returns a namespace
816
-    *
817
-    * @param string $prefix The prefix
818
-    * @return mixed The namespace, false if no namespace has the specified prefix
819
-    * @access public
820
-    */
821
-	function getNamespaceFromPrefix($prefix){
822
-		if (isset($this->namespaces[$prefix])) {
823
-			return $this->namespaces[$prefix];
824
-		}
825
-		//$this->setError("No namespace registered for prefix '$prefix'");
826
-		return false;
827
-	}
828
-
829
-	/**
830
-    * returns the prefix for a given namespace (or prefix)
831
-    * or false if no prefixes registered for the given namespace
832
-    *
833
-    * @param string $ns The namespace
834
-    * @return mixed The prefix, false if the namespace has no prefixes
835
-    * @access public
836
-    */
837
-	function getPrefixFromNamespace($ns) {
838
-		foreach ($this->namespaces as $p => $n) {
839
-			if ($ns == $n || $ns == $p) {
840
-			    $this->usedNamespaces[$p] = $n;
841
-				return $p;
842
-			}
843
-		}
844
-		return false;
845
-	}
846
-
847
-	/**
848
-    * returns the time in ODBC canonical form with microseconds
849
-    *
850
-    * @return string The time in ODBC canonical form with microseconds
851
-    * @access public
852
-    */
853
-	function getmicrotime() {
854
-		if (function_exists('gettimeofday')) {
855
-			$tod = gettimeofday();
856
-			$sec = $tod['sec'];
857
-			$usec = $tod['usec'];
858
-		} else {
859
-			$sec = time();
860
-			$usec = 0;
861
-		}
862
-		return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
863
-	}
864
-
865
-	/**
866
-	 * Returns a string with the output of var_dump
867
-	 *
868
-	 * @param mixed $data The variable to var_dump
869
-	 * @return string The output of var_dump
870
-	 * @access public
871
-	 */
728
+        $str = htmlspecialchars($str);
729
+        return nl2br($str);
730
+    }
731
+
732
+    /**
733
+     * contracts (changes namespace to prefix) a qualified name
734
+     *
735
+     * @param    string $qname qname
736
+     * @return	string contracted qname
737
+     * @access   private
738
+     */
739
+    function contractQname($qname){
740
+        // get element namespace
741
+        //$this->xdebug("Contract $qname");
742
+        if (strrpos($qname, ':')) {
743
+            // get unqualified name
744
+            $name = substr($qname, strrpos($qname, ':') + 1);
745
+            // get ns
746
+            $ns = substr($qname, 0, strrpos($qname, ':'));
747
+            $p = $this->getPrefixFromNamespace($ns);
748
+            if ($p) {
749
+                return $p . ':' . $name;
750
+            }
751
+            return $qname;
752
+        } else {
753
+            return $qname;
754
+        }
755
+    }
756
+
757
+    /**
758
+     * expands (changes prefix to namespace) a qualified name
759
+     *
760
+     * @param    string $qname qname
761
+     * @return	string expanded qname
762
+     * @access   private
763
+     */
764
+    function expandQname($qname){
765
+        // get element prefix
766
+        if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){
767
+            // get unqualified name
768
+            $name = substr(strstr($qname,':'),1);
769
+            // get ns prefix
770
+            $prefix = substr($qname,0,strpos($qname,':'));
771
+            if(isset($this->namespaces[$prefix])){
772
+                return $this->namespaces[$prefix].':'.$name;
773
+            } else {
774
+                return $qname;
775
+            }
776
+        } else {
777
+            return $qname;
778
+        }
779
+    }
780
+
781
+    /**
782
+     * returns the local part of a prefixed string
783
+     * returns the original string, if not prefixed
784
+     *
785
+     * @param string $str The prefixed string
786
+     * @return string The local part
787
+     * @access public
788
+     */
789
+    function getLocalPart($str){
790
+        if($sstr = strrchr($str,':')){
791
+            // get unqualified name
792
+            return substr( $sstr, 1 );
793
+        } else {
794
+            return $str;
795
+        }
796
+    }
797
+
798
+    /**
799
+     * returns the prefix part of a prefixed string
800
+     * returns false, if not prefixed
801
+     *
802
+     * @param string $str The prefixed string
803
+     * @return mixed The prefix or false if there is no prefix
804
+     * @access public
805
+     */
806
+    function getPrefix($str){
807
+        if($pos = strrpos($str,':')){
808
+            // get prefix
809
+            return substr($str,0,$pos);
810
+        }
811
+        return false;
812
+    }
813
+
814
+    /**
815
+     * pass it a prefix, it returns a namespace
816
+     *
817
+     * @param string $prefix The prefix
818
+     * @return mixed The namespace, false if no namespace has the specified prefix
819
+     * @access public
820
+     */
821
+    function getNamespaceFromPrefix($prefix){
822
+        if (isset($this->namespaces[$prefix])) {
823
+            return $this->namespaces[$prefix];
824
+        }
825
+        //$this->setError("No namespace registered for prefix '$prefix'");
826
+        return false;
827
+    }
828
+
829
+    /**
830
+     * returns the prefix for a given namespace (or prefix)
831
+     * or false if no prefixes registered for the given namespace
832
+     *
833
+     * @param string $ns The namespace
834
+     * @return mixed The prefix, false if the namespace has no prefixes
835
+     * @access public
836
+     */
837
+    function getPrefixFromNamespace($ns) {
838
+        foreach ($this->namespaces as $p => $n) {
839
+            if ($ns == $n || $ns == $p) {
840
+                $this->usedNamespaces[$p] = $n;
841
+                return $p;
842
+            }
843
+        }
844
+        return false;
845
+    }
846
+
847
+    /**
848
+     * returns the time in ODBC canonical form with microseconds
849
+     *
850
+     * @return string The time in ODBC canonical form with microseconds
851
+     * @access public
852
+     */
853
+    function getmicrotime() {
854
+        if (function_exists('gettimeofday')) {
855
+            $tod = gettimeofday();
856
+            $sec = $tod['sec'];
857
+            $usec = $tod['usec'];
858
+        } else {
859
+            $sec = time();
860
+            $usec = 0;
861
+        }
862
+        return strftime('%Y-%m-%d %H:%M:%S', $sec) . '.' . sprintf('%06d', $usec);
863
+    }
864
+
865
+    /**
866
+     * Returns a string with the output of var_dump
867
+     *
868
+     * @param mixed $data The variable to var_dump
869
+     * @return string The output of var_dump
870
+     * @access public
871
+     */
872 872
     function varDump($data) {
873
-		ob_start();
874
-		var_dump($data);
875
-		$ret_val = ob_get_contents();
876
-		ob_end_clean();
877
-		return $ret_val;
878
-	}
879
-
880
-	/**
881
-	* represents the object as a string
882
-	*
883
-	* @return	string
884
-	* @access   public
885
-	*/
886
-	function __toString() {
887
-		return $this->varDump($this);
888
-	}
873
+        ob_start();
874
+        var_dump($data);
875
+        $ret_val = ob_get_contents();
876
+        ob_end_clean();
877
+        return $ret_val;
878
+    }
879
+
880
+    /**
881
+     * represents the object as a string
882
+     *
883
+     * @return	string
884
+     * @access   public
885
+     */
886
+    function __toString() {
887
+        return $this->varDump($this);
888
+    }
889 889
 }
890 890
 
891 891
 // XML Schema Datatype Helper Functions
@@ -901,35 +901,35 @@  discard block
 block discarded – undo
901 901
 * @access   public
902 902
 */
903 903
 function timestamp_to_iso8601($timestamp,$utc=true){
904
-	$datestr = date('Y-m-d\TH:i:sO',$timestamp);
905
-	$pos = strrpos($datestr, "+");
906
-	if ($pos === FALSE) {
907
-		$pos = strrpos($datestr, "-");
908
-	}
909
-	if ($pos !== FALSE) {
910
-		if (strlen($datestr) == $pos + 5) {
911
-			$datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
912
-		}
913
-	}
914
-	if($utc){
915
-		$pattern = '/'.
916
-		'([0-9]{4})-'.	// centuries & years CCYY-
917
-		'([0-9]{2})-'.	// months MM-
918
-		'([0-9]{2})'.	// days DD
919
-		'T'.			// separator T
920
-		'([0-9]{2}):'.	// hours hh:
921
-		'([0-9]{2}):'.	// minutes mm:
922
-		'([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
923
-		'(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
924
-		'/';
925
-
926
-		if(preg_match($pattern,$datestr,$regs)){
927
-			return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
928
-		}
929
-		return false;
930
-	} else {
931
-		return $datestr;
932
-	}
904
+    $datestr = date('Y-m-d\TH:i:sO',$timestamp);
905
+    $pos = strrpos($datestr, "+");
906
+    if ($pos === FALSE) {
907
+        $pos = strrpos($datestr, "-");
908
+    }
909
+    if ($pos !== FALSE) {
910
+        if (strlen($datestr) == $pos + 5) {
911
+            $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2);
912
+        }
913
+    }
914
+    if($utc){
915
+        $pattern = '/'.
916
+        '([0-9]{4})-'.	// centuries & years CCYY-
917
+        '([0-9]{2})-'.	// months MM-
918
+        '([0-9]{2})'.	// days DD
919
+        'T'.			// separator T
920
+        '([0-9]{2}):'.	// hours hh:
921
+        '([0-9]{2}):'.	// minutes mm:
922
+        '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss...
923
+        '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
924
+        '/';
925
+
926
+        if(preg_match($pattern,$datestr,$regs)){
927
+            return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]);
928
+        }
929
+        return false;
930
+    } else {
931
+        return $datestr;
932
+    }
933 933
 }
934 934
 
935 935
 /**
@@ -940,35 +940,35 @@  discard block
 block discarded – undo
940 940
 * @access   public
941 941
 */
942 942
 function iso8601_to_timestamp($datestr){
943
-	$pattern = '/'.
944
-	'([0-9]{4})-'.	// centuries & years CCYY-
945
-	'([0-9]{2})-'.	// months MM-
946
-	'([0-9]{2})'.	// days DD
947
-	'T'.			// separator T
948
-	'([0-9]{2}):'.	// hours hh:
949
-	'([0-9]{2}):'.	// minutes mm:
950
-	'([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
951
-	'(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
952
-	'/';
953
-	if(preg_match($pattern,$datestr,$regs)){
954
-		// not utc
955
-		if($regs[8] != 'Z'){
956
-			$op = substr($regs[8],0,1);
957
-			$h = substr($regs[8],1,2);
958
-			$m = substr($regs[8],strlen($regs[8])-2,2);
959
-			if($op == '-'){
960
-				$regs[4] = $regs[4] + $h;
961
-				$regs[5] = $regs[5] + $m;
962
-			} elseif($op == '+'){
963
-				$regs[4] = $regs[4] - $h;
964
-				$regs[5] = $regs[5] - $m;
965
-			}
966
-		}
967
-		return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
943
+    $pattern = '/'.
944
+    '([0-9]{4})-'.	// centuries & years CCYY-
945
+    '([0-9]{2})-'.	// months MM-
946
+    '([0-9]{2})'.	// days DD
947
+    'T'.			// separator T
948
+    '([0-9]{2}):'.	// hours hh:
949
+    '([0-9]{2}):'.	// minutes mm:
950
+    '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss...
951
+    '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's
952
+    '/';
953
+    if(preg_match($pattern,$datestr,$regs)){
954
+        // not utc
955
+        if($regs[8] != 'Z'){
956
+            $op = substr($regs[8],0,1);
957
+            $h = substr($regs[8],1,2);
958
+            $m = substr($regs[8],strlen($regs[8])-2,2);
959
+            if($op == '-'){
960
+                $regs[4] = $regs[4] + $h;
961
+                $regs[5] = $regs[5] + $m;
962
+            } elseif($op == '+'){
963
+                $regs[4] = $regs[4] - $h;
964
+                $regs[5] = $regs[5] - $m;
965
+            }
966
+        }
967
+        return gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
968 968
 //		return strtotime("$regs[1]-$regs[2]-$regs[3] $regs[4]:$regs[5]:$regs[6]Z");
969
-	} else {
970
-		return false;
971
-	}
969
+    } else {
970
+        return false;
971
+    }
972 972
 }
973 973
 
974 974
 /**
@@ -980,13 +980,13 @@  discard block
 block discarded – undo
980 980
 */
981 981
 function usleepWindows($usec)
982 982
 {
983
-	$start = gettimeofday();
984
-
985
-	do
986
-	{
987
-		$stop = gettimeofday();
988
-		$timePassed = 1000000 * ($stop['sec'] - $start['sec'])
989
-		+ $stop['usec'] - $start['usec'];
990
-	}
991
-	while ($timePassed < $usec);
983
+    $start = gettimeofday();
984
+
985
+    do
986
+    {
987
+        $stop = gettimeofday();
988
+        $timePassed = 1000000 * ($stop['sec'] - $start['sec'])
989
+        + $stop['usec'] - $start['usec'];
990
+    }
991
+    while ($timePassed < $usec);
992 992
 }
Please login to merge, or discard this patch.
main/admin/user_edit.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
 unset($user_data['password']);
148 148
 
149 149
 if ($userGeolocalization) {
150
-	$htmlHeadXtra[] = '<script>
150
+    $htmlHeadXtra[] = '<script>
151 151
     $(document).ready(function() {
152 152
 
153 153
         var address = "' . $user_data['address'] . '";
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 $form->addElement('hidden', 'user_id', $user_id);
258 258
 
259 259
 if (api_is_western_name_order()) {
260
-	// Firstname
261
-	$form->addElement('text', 'firstname', get_lang('FirstName'));
262
-	$form->applyFilter('firstname', 'html_filter');
263
-	$form->applyFilter('firstname', 'trim');
264
-	$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
265
-	// Lastname
266
-	$form->addElement('text', 'lastname', get_lang('LastName'));
267
-	$form->applyFilter('lastname', 'html_filter');
268
-	$form->applyFilter('lastname', 'trim');
269
-	$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
260
+    // Firstname
261
+    $form->addElement('text', 'firstname', get_lang('FirstName'));
262
+    $form->applyFilter('firstname', 'html_filter');
263
+    $form->applyFilter('firstname', 'trim');
264
+    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
265
+    // Lastname
266
+    $form->addElement('text', 'lastname', get_lang('LastName'));
267
+    $form->applyFilter('lastname', 'html_filter');
268
+    $form->applyFilter('lastname', 'trim');
269
+    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
270 270
 } else {
271
-	// Lastname
272
-	$form->addElement('text', 'lastname', get_lang('LastName'));
273
-	$form->applyFilter('lastname', 'html_filter');
274
-	$form->applyFilter('lastname', 'trim');
275
-	$form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
276
-	// Firstname
277
-	$form->addElement('text', 'firstname', get_lang('FirstName'));
278
-	$form->applyFilter('firstname', 'html_filter');
279
-	$form->applyFilter('firstname', 'trim');
280
-	$form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
271
+    // Lastname
272
+    $form->addElement('text', 'lastname', get_lang('LastName'));
273
+    $form->applyFilter('lastname', 'html_filter');
274
+    $form->applyFilter('lastname', 'trim');
275
+    $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
276
+    // Firstname
277
+    $form->addElement('text', 'firstname', get_lang('FirstName'));
278
+    $form->applyFilter('firstname', 'html_filter');
279
+    $form->applyFilter('firstname', 'trim');
280
+    $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
281 281
 }
282 282
 
283 283
 // Official code
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 
300 300
 // OpenID
301 301
 if (api_get_setting('openid_authentication') == 'true') {
302
-	$form->addElement('text', 'openid', get_lang('OpenIDURL'));
302
+    $form->addElement('text', 'openid', get_lang('OpenIDURL'));
303 303
 }
304 304
 
305 305
 // Phone
306 306
 $form->addElement('text', 'phone', get_lang('PhoneNumber'));
307 307
 
308 308
 if ($userGeolocalization) {
309
-	// Geolocation
310
-	$form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
311
-	$form->addHtml('
309
+    // Geolocation
310
+    $form->addElement('text', 'address', get_lang('AddressField'), ['id' => 'address']);
311
+    $form->addHtml('
312 312
         <div class="form-group">
313 313
             <label for="geolocalization" class="col-sm-2 control-label"></label>
314 314
             <div class="col-sm-8">
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
         </div>
319 319
     ');
320 320
 
321
-	$form->addHtml('
321
+    $form->addHtml('
322 322
         <div class="form-group">
323 323
             <label for="map" class="col-sm-2 control-label">
324 324
                 '.get_lang('Map').'
@@ -351,18 +351,18 @@  discard block
 block discarded – undo
351 351
 $form->addHidden('cropResult', '');
352 352
 
353 353
 $form->addRule(
354
-	'picture',
355
-	get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
356
-	'filetype',
357
-	$allowed_picture_types
354
+    'picture',
355
+    get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
356
+    'filetype',
357
+    $allowed_picture_types
358 358
 );
359 359
 if (strlen($user_data['picture_uri']) > 0) {
360
-	$form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
360
+    $form->addElement('checkbox', 'delete_picture', '', get_lang('DelImage'));
361 361
 }
362 362
 
363 363
 // Username
364 364
 if (api_get_setting('login_is_email') != 'true') {
365
-	$form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
365
+    $form->addElement('text', 'username', get_lang('LoginName'), array('maxlength' => USERNAME_MAX_LENGTH));
366 366
     $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
367 367
     $form->addRule('username', sprintf(get_lang('UsernameMaxXCharacters'), (string)USERNAME_MAX_LENGTH), 'maxlength', USERNAME_MAX_LENGTH);
368 368
     $form->addRule('username', get_lang('OnlyLettersAndNumbersAllowed'), 'username');
@@ -434,15 +434,15 @@  discard block
 block discarded – undo
434 434
 
435 435
 // Platform admin
436 436
 if (api_is_platform_admin()) {
437
-	$group = array();
438
-	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
439
-	$group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
437
+    $group = array();
438
+    $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('Yes'), 1);
439
+    $group[] =$form->createElement('radio', 'platform_admin', null, get_lang('No'), 0);
440 440
 
441
-	$user_data['status'] == 1 ? $display = 'block':$display = 'none';
441
+    $user_data['status'] == 1 ? $display = 'block':$display = 'none';
442 442
 
443
-	$form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
444
-	$form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
445
-	$form->addElement('html', '</div>');
443
+    $form->addElement('html', '<div id="id_platform_admin" style="display:'.$display.'">');
444
+    $form->addGroup($group, 'admin', get_lang('PlatformAdmin'), null, false);
445
+    $form->addElement('html', '</div>');
446 446
 }
447 447
 
448 448
 //Language
@@ -460,16 +460,16 @@  discard block
 block discarded – undo
460 460
 $form->addElement('label', get_lang('RegistrationDate'), $date);
461 461
 
462 462
 if (!$user_data['platform_admin']) {
463
-	// Expiration Date
464
-	$form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
465
-	$group = array ();
466
-	$group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('Enabled'), 1);
467
-	$group[] = $form->createElement('DateTimePicker', 'expiration_date', null, array('onchange' => 'javascript: enable_expiration_date();'));
468
-	$form->addGroup($group, 'max_member_group', null, '', false);
469
-
470
-	// Active account or inactive account
471
-	$form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
472
-	$form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
463
+    // Expiration Date
464
+    $form->addElement('radio', 'radio_expiration_date', get_lang('ExpirationDate'), get_lang('NeverExpires'), 0);
465
+    $group = array ();
466
+    $group[] = $form->createElement('radio', 'radio_expiration_date', null, get_lang('Enabled'), 1);
467
+    $group[] = $form->createElement('DateTimePicker', 'expiration_date', null, array('onchange' => 'javascript: enable_expiration_date();'));
468
+    $form->addGroup($group, 'max_member_group', null, '', false);
469
+
470
+    // Active account or inactive account
471
+    $form->addElement('radio', 'active', get_lang('ActiveAccount'), get_lang('Active'), 1);
472
+    $form->addElement('radio', 'active', '', get_lang('Inactive'), 0);
473 473
 }
474 474
 $studentBossList = UserManager::getStudentBossList($user_data['user_id']);
475 475
 
@@ -511,18 +511,18 @@  discard block
 block discarded – undo
511 511
 $expiration_date = $user_data['expiration_date'];
512 512
 
513 513
 if (empty($expiration_date)) {
514
-	$user_data['radio_expiration_date'] = 0;
515
-	$user_data['expiration_date'] = api_get_local_time();
514
+    $user_data['radio_expiration_date'] = 0;
515
+    $user_data['expiration_date'] = api_get_local_time();
516 516
 } else {
517
-	$user_data['radio_expiration_date'] = 1;
518
-	$user_data['expiration_date'] = api_get_local_time($expiration_date);
517
+    $user_data['radio_expiration_date'] = 1;
518
+    $user_data['expiration_date'] = api_get_local_time($expiration_date);
519 519
 }
520 520
 $form->setDefaults($user_data);
521 521
 
522 522
 $error_drh = false;
523 523
 // Validate form
524 524
 if ($form->validate()) {
525
-	$user = $form->getSubmitValues(1);
525
+    $user = $form->getSubmitValues(1);
526 526
     $reset_password = intval($user['reset_password']);
527 527
     if ($reset_password == 2 && empty($user['password'])) {
528 528
         Display::addFlash(Display::return_message(get_lang('PasswordIsTooShort')));
@@ -530,18 +530,18 @@  discard block
 block discarded – undo
530 530
         exit();
531 531
     }
532 532
 
533
-	$is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
533
+    $is_user_subscribed_in_course = CourseManager::is_user_subscribed_in_course($user['user_id']);
534 534
 
535
-	if ($user['status'] == DRH && $is_user_subscribed_in_course) {
536
-		$error_drh = true;
537
-	} else {
538
-		$picture_element = $form->getElement('picture');
539
-		$picture = $picture_element->getValue();
535
+    if ($user['status'] == DRH && $is_user_subscribed_in_course) {
536
+        $error_drh = true;
537
+    } else {
538
+        $picture_element = $form->getElement('picture');
539
+        $picture = $picture_element->getValue();
540 540
 
541
-		$picture_uri = $user_data['picture_uri'];
542
-		if (isset($user['delete_picture']) && $user['delete_picture']) {
543
-			$picture_uri = UserManager::delete_user_picture($user_id);
544
-		} elseif (!empty($picture['name'])) {
541
+        $picture_uri = $user_data['picture_uri'];
542
+        if (isset($user['delete_picture']) && $user['delete_picture']) {
543
+            $picture_uri = UserManager::delete_user_picture($user_id);
544
+        } elseif (!empty($picture['name'])) {
545 545
             $picture_uri = UserManager::update_user_picture(
546 546
                 $user_id,
547 547
                 $_FILES['picture']['name'],
@@ -549,30 +549,30 @@  discard block
 block discarded – undo
549 549
                 $user['cropResult']
550 550
 
551 551
             );
552
-		}
552
+        }
553 553
 
554
-		$lastname = $user['lastname'];
555
-		$firstname = $user['firstname'];
554
+        $lastname = $user['lastname'];
555
+        $firstname = $user['firstname'];
556 556
         $password = $user['password'];
557 557
         $auth_source = isset($user['auth_source']) ? $user['auth_source'] : $userInfo['auth_source'];
558
-		$official_code = $user['official_code'];
559
-		$email = $user['email'];
560
-		$phone = $user['phone'];
561
-		$username = isset($user['username']) ? $user['username'] : $userInfo['username'];
562
-		$status = intval($user['status']);
563
-		$platform_admin = intval($user['platform_admin']);
564
-		$send_mail = intval($user['send_mail']);
565
-		$reset_password = intval($user['reset_password']);
566
-		$hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : null;
567
-		$language = $user['language'];
568
-
569
-		if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
558
+        $official_code = $user['official_code'];
559
+        $email = $user['email'];
560
+        $phone = $user['phone'];
561
+        $username = isset($user['username']) ? $user['username'] : $userInfo['username'];
562
+        $status = intval($user['status']);
563
+        $platform_admin = intval($user['platform_admin']);
564
+        $send_mail = intval($user['send_mail']);
565
+        $reset_password = intval($user['reset_password']);
566
+        $hr_dept_id = isset($user['hr_dept_id']) ? intval($user['hr_dept_id']) : null;
567
+        $language = $user['language'];
568
+
569
+        if ($user['radio_expiration_date'] == '1' && !$user_data['platform_admin']) {
570 570
             $expiration_date = $user['expiration_date'];
571
-		} else {
572
-			$expiration_date = null;
573
-		}
571
+        } else {
572
+            $expiration_date = null;
573
+        }
574 574
 
575
-		$active = $user_data['platform_admin'] ? 1 : intval($user['active']);
575
+        $active = $user_data['platform_admin'] ? 1 : intval($user['active']);
576 576
 
577 577
         //If the user is set to admin the status will be overwrite by COURSEMANAGER = 1
578 578
         if ($platform_admin == 1) {
@@ -604,44 +604,44 @@  discard block
 block discarded – undo
604 604
             null,
605 605
             $send_mail,
606 606
             $reset_password,
607
-			$user['address']
607
+            $user['address']
608 608
         );
609 609
 
610 610
         if (isset($user['student_boss'])) {
611 611
             UserManager::subscribeUserToBossList($user_id, $user['student_boss']);
612 612
         }
613 613
 
614
-		if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
615
-			$up = UserManager::update_openid($user_id, $user['openid']);
616
-		}
614
+        if (api_get_setting('openid_authentication') == 'true' && !empty($user['openid'])) {
615
+            $up = UserManager::update_openid($user_id, $user['openid']);
616
+        }
617 617
         $currentUserId = api_get_user_id();
618 618
 
619 619
         $userObj = api_get_user_entity($user_id);
620 620
 		
621 621
         UserManager::add_user_as_admin($userObj);
622 622
 
623
-		if ($user_id != $currentUserId) {
624
-			if ($platform_admin == 1) {
625
-				$userObj = api_get_user_entity($user_id);
623
+        if ($user_id != $currentUserId) {
624
+            if ($platform_admin == 1) {
625
+                $userObj = api_get_user_entity($user_id);
626 626
                 UserManager::add_user_as_admin($userObj);
627
-			} else {
627
+            } else {
628 628
                 UserManager::remove_user_admin($user_id);
629
-			}
630
-		}
629
+            }
630
+        }
631 631
 
632 632
         $extraFieldValue = new ExtraFieldValue('user');
633 633
         $extraFieldValue->saveFieldValues($user);
634 634
 
635
-		$tok = Security::get_token();
636
-		header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
637
-		exit();
638
-	}
635
+        $tok = Security::get_token();
636
+        header('Location: user_list.php?action=show_message&message='.urlencode(get_lang('UserUpdated')).'&sec_token='.$tok);
637
+        exit();
638
+    }
639 639
 }
640 640
 
641 641
 $message = null;
642 642
 if ($error_drh) {
643
-	$err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
644
-	$message = Display::return_message($err_msg, 'error');
643
+    $err_msg = get_lang('StatusCanNotBeChangedToHumanResourcesManager');
644
+    $message = Display::return_message($err_msg, 'error');
645 645
 }
646 646
 
647 647
 $content = null;
Please login to merge, or discard this patch.
src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php 1 patch
Indentation   +707 added lines, -707 removed lines patch added patch discarded remove patch
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class CourseRestorer
23 23
 {
24
-	/**
25
-	 * The course-object
26
-	 */
24
+    /**
25
+     * The course-object
26
+     */
27 27
     public $course;
28 28
     public $destination_course_info;
29 29
 
30
-	/**
31
-	 * What to do with files with same name (FILE_SKIP, FILE_RENAME or
32
-	 * FILE_OVERWRITE)
33
-	 */
30
+    /**
31
+     * What to do with files with same name (FILE_SKIP, FILE_RENAME or
32
+     * FILE_OVERWRITE)
33
+     */
34 34
     public $file_option;
35 35
     public $set_tools_invisible_by_default;
36 36
     public $skip_content;
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         'events',
43 43
         'forum_category',
44 44
         'forums',
45
-       // 'forum_topics',
45
+        // 'forum_topics',
46 46
         'glossary',
47 47
         'quizzes',
48 48
         'test_category',
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
         $this->tool_copy_settings = $array;
111 111
     }
112 112
 
113
-	/**
114
-	 * Restore a course.
113
+    /**
114
+     * Restore a course.
115 115
      *
116
-	 * @param string    $destination_course_code code of the Chamilo-course in
117
-	 * @param int	    $session_id
118
-	 * @param bool	    $update_course_settings Course settings are going to be restore?
116
+     * @param string    $destination_course_code code of the Chamilo-course in
117
+     * @param int	    $session_id
118
+     * @param bool	    $update_course_settings Course settings are going to be restore?
119 119
      * @param bool      $respect_base_content
120 120
      * @return false|null
121
-	 */
121
+     */
122 122
     public function restore(
123 123
         $destination_course_code = '',
124 124
         $session_id = 0,
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
         }
262 262
     }
263 263
 
264
-	/**
265
-	 * Restore only harmless course settings:
264
+    /**
265
+     * Restore only harmless course settings:
266 266
      * course_language, visibility, department_name,department_url,
267 267
      * subscribe, unsubscribe ,category_code
268
-	 *
269
-	 * @param string $destination_course_code
270
-	 */
268
+     *
269
+     * @param string $destination_course_code
270
+     */
271 271
     public function restore_course_settings($destination_course_code)
272 272
     {
273
-	    $origin_course_info = api_get_course_info($destination_course_code);
274
-	    $course_info = $this->course->info;
273
+        $origin_course_info = api_get_course_info($destination_course_code);
274
+        $course_info = $this->course->info;
275 275
         $params['course_language'] = $course_info['language'];
276 276
         $params['visibility'] = $course_info['visibility'];
277 277
         $params['department_name'] = $course_info['department_name'];
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
         $params['category_code'] = $course_info['categoryCode'];
281 281
         $params['subscribe'] = $course_info['subscribe_allowed'];
282 282
         $params['unsubscribe'] = $course_info['unsubscribe'];
283
-	    CourseManager::update_attributes($origin_course_info['real_id'], $params);
284
-	}
283
+        CourseManager::update_attributes($origin_course_info['real_id'], $params);
284
+    }
285 285
 
286 286
     /**
287 287
      * Restore documents
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
         $course_info = api_get_course_info($destination_course_code);
296 296
 
297 297
         if ($this->course->has_resources(RESOURCE_DOCUMENT)) {
298
-			$table = Database :: get_course_table(TABLE_DOCUMENT);
299
-			$resources = $this->course->resources;
298
+            $table = Database :: get_course_table(TABLE_DOCUMENT);
299
+            $resources = $this->course->resources;
300 300
             $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
301 301
 
302
-			foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
302
+            foreach ($resources[RESOURCE_DOCUMENT] as $id => $document) {
303 303
                 if (empty($document->item_properties[0]['id_session'])) {
304 304
                     $my_session_id = 0;
305 305
                 } else {
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                             }
369 369
                         }
370 370
                     }
371
-		    	} elseif ($document->file_type == DOCUMENT) {
371
+                } elseif ($document->file_type == DOCUMENT) {
372 372
                     //Checking if folder exists in the database otherwise we created it
373 373
                     $dir_to_create = dirname($document->path);
374 374
 
@@ -424,19 +424,19 @@  discard block
 block discarded – undo
424 424
                         }
425 425
                     }
426 426
 
427
-					if (file_exists($path.$document->path)) {
428
-						switch ($this->file_option) {
429
-							case FILE_OVERWRITE:
427
+                    if (file_exists($path.$document->path)) {
428
+                        switch ($this->file_option) {
429
+                            case FILE_OVERWRITE:
430 430
                                 $origin_path = $this->course->backup_path.'/'.$document->path;
431 431
 
432
-								if (file_exists($origin_path)) {
433
-        						    copy($origin_path, $path.$document->path);
432
+                                if (file_exists($origin_path)) {
433
+                                    copy($origin_path, $path.$document->path);
434 434
                                     $sql = "SELECT id FROM $table
435 435
                                             WHERE
436 436
                                                 c_id = ".$this->destination_course_id." AND
437 437
                                                 path = '/".self::DBUTF8escapestring(substr($document->path, 9))."'";
438 438
 
439
-        						    $res = Database::query($sql);
439
+                                    $res = Database::query($sql);
440 440
                                     $count = Database::num_rows($res);
441 441
 
442 442
                                     if ($count == 0) {
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
                                             'readonly' => 0
452 452
                                         ];
453 453
 
454
-    									$document_id = Database::insert($table, $params);
454
+                                        $document_id = Database::insert($table, $params);
455 455
 
456 456
                                         if ($document_id) {
457 457
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -559,83 +559,83 @@  discard block
 block discarded – undo
559 559
                                             ],
560 560
                                         ]
561 561
                                     );
562
-								}
562
+                                }
563 563
 
564
-								break;
565
-							case FILE_SKIP:
566
-								$sql = "SELECT id FROM $table
564
+                                break;
565
+                            case FILE_SKIP:
566
+                                $sql = "SELECT id FROM $table
567 567
 								        WHERE
568 568
 								            c_id = ".$this->destination_course_id." AND
569 569
 								            path='/".self::DBUTF8escapestring(substr($document->path, 9))."'";
570
-								$res = Database::query($sql);
571
-								$obj = Database::fetch_object($res);
572
-								$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
573
-								break;
574
-							case FILE_RENAME:
575
-								$i = 1;
576
-								$ext = explode('.', basename($document->path));
577
-								if (count($ext) > 1) {
578
-									$ext = array_pop($ext);
579
-									$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
580
-									$ext = '.'.$ext;
581
-								} else {
582
-									$ext = '';
583
-									$file_name_no_ext = $document->path;
584
-								}
585
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
586
-								$file_exists = file_exists($path.$new_file_name);
587
-								while ($file_exists) {
588
-									$i ++;
589
-									$new_file_name = $file_name_no_ext.'_'.$i.$ext;
590
-									$file_exists = file_exists($path.$new_file_name);
591
-								}
592
-
593
-								if (!empty($session_id)) {
594
-
595
-									$document_path = explode('/',$document->path,3);
596
-									$course_path = $path;
597
-									$orig_base_folder = $document_path[1];
598
-									$orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
599
-
600
-									if (is_dir($orig_base_path)) {
601
-
602
-										$new_base_foldername = $orig_base_folder;
603
-										$new_base_path = $orig_base_path;
604
-
605
-										if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
606
-											unset($_SESSION['new_base_foldername']);
607
-											unset($_SESSION['orig_base_foldername']);
608
-											unset($_SESSION['new_base_path']);
609
-										}
610
-
611
-										$folder_exists = file_exists($new_base_path);
612
-										if ($folder_exists) {
613
-											$_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
614
-											$x = '';
615
-											while ($folder_exists) {
616
-												$x = $x + 1;
617
-												$new_base_foldername = $document_path[1].'_'.$x;
618
-												$new_base_path = $orig_base_path.'_'.$x;
570
+                                $res = Database::query($sql);
571
+                                $obj = Database::fetch_object($res);
572
+                                $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $obj->id;
573
+                                break;
574
+                            case FILE_RENAME:
575
+                                $i = 1;
576
+                                $ext = explode('.', basename($document->path));
577
+                                if (count($ext) > 1) {
578
+                                    $ext = array_pop($ext);
579
+                                    $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
580
+                                    $ext = '.'.$ext;
581
+                                } else {
582
+                                    $ext = '';
583
+                                    $file_name_no_ext = $document->path;
584
+                                }
585
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
586
+                                $file_exists = file_exists($path.$new_file_name);
587
+                                while ($file_exists) {
588
+                                    $i ++;
589
+                                    $new_file_name = $file_name_no_ext.'_'.$i.$ext;
590
+                                    $file_exists = file_exists($path.$new_file_name);
591
+                                }
592
+
593
+                                if (!empty($session_id)) {
594
+
595
+                                    $document_path = explode('/',$document->path,3);
596
+                                    $course_path = $path;
597
+                                    $orig_base_folder = $document_path[1];
598
+                                    $orig_base_path   = $course_path.$document_path[0].'/'.$document_path[1];
599
+
600
+                                    if (is_dir($orig_base_path)) {
601
+
602
+                                        $new_base_foldername = $orig_base_folder;
603
+                                        $new_base_path = $orig_base_path;
604
+
605
+                                        if ($_SESSION['orig_base_foldername'] != $new_base_foldername) {
606
+                                            unset($_SESSION['new_base_foldername']);
607
+                                            unset($_SESSION['orig_base_foldername']);
608
+                                            unset($_SESSION['new_base_path']);
609
+                                        }
610
+
611
+                                        $folder_exists = file_exists($new_base_path);
612
+                                        if ($folder_exists) {
613
+                                            $_SESSION['orig_base_foldername'] = $new_base_foldername; 		// e.g: carpeta1 in session
614
+                                            $x = '';
615
+                                            while ($folder_exists) {
616
+                                                $x = $x + 1;
617
+                                                $new_base_foldername = $document_path[1].'_'.$x;
618
+                                                $new_base_path = $orig_base_path.'_'.$x;
619 619
                                                 if ($_SESSION['new_base_foldername'] == $new_base_foldername) {
620 620
                                                     break;
621 621
                                                 }
622
-												$folder_exists = file_exists($new_base_path);
623
-											}
624
-											$_SESSION['new_base_foldername'] = $new_base_foldername;
625
-											$_SESSION['new_base_path'] = $new_base_path;
626
-										}
627
-
628
-										if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
629
-											$new_base_foldername = $_SESSION['new_base_foldername'];
630
-											$new_base_path = $_SESSION['new_base_path'];
631
-										}
632
-
633
-										$dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
634
-										$basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
635
-										$base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
636
-										$path_title = '/'.$new_base_foldername.'/'.$document_path[2];
637
-
638
-										copy_folder_course_session(
622
+                                                $folder_exists = file_exists($new_base_path);
623
+                                            }
624
+                                            $_SESSION['new_base_foldername'] = $new_base_foldername;
625
+                                            $_SESSION['new_base_path'] = $new_base_path;
626
+                                        }
627
+
628
+                                        if (isset($_SESSION['new_base_foldername']) && isset($_SESSION['new_base_path'])) {
629
+                                            $new_base_foldername = $_SESSION['new_base_foldername'];
630
+                                            $new_base_path = $_SESSION['new_base_path'];
631
+                                        }
632
+
633
+                                        $dest_document_path = $new_base_path.'/'.$document_path[2];		// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1/collaborative.png"
634
+                                        $basedir_dest_path 	= dirname($dest_document_path);				// e.g: "/var/www/wiener/courses/CURSO4/document/carpeta1_1/subcarpeta1"
635
+                                        $base_path_document = $course_path.$document_path[0];			// e.g: "/var/www/wiener/courses/CURSO4/document"
636
+                                        $path_title = '/'.$new_base_foldername.'/'.$document_path[2];
637
+
638
+                                        copy_folder_course_session(
639 639
                                             $basedir_dest_path,
640 640
                                             $base_path_document,
641 641
                                             $session_id,
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
                                             'session_id' => $my_session_id,
678 678
                                         ];
679 679
 
680
-										$document_id = Database::insert($table, $params);
680
+                                        $document_id = Database::insert($table, $params);
681 681
 
682 682
                                         if ($document_id) {
683 683
                                             $sql = "UPDATE $table SET id = iid WHERE iid = $document_id";
@@ -706,10 +706,10 @@  discard block
 block discarded – undo
706 706
                                             null,
707 707
                                             $my_session_id
708 708
                                         );
709
-									} else {
710
-									    if (file_exists($path.$document->path)) {
709
+                                    } else {
710
+                                        if (file_exists($path.$document->path)) {
711 711
                                             copy($path.$document->path, $path.$new_file_name);
712
-									    }
712
+                                        }
713 713
                                         //Replace old course code with the new destination code see BT#1985
714 714
                                         if (file_exists($path.$new_file_name)) {
715 715
                                             $file_info = pathinfo($path.$new_file_name);
@@ -768,10 +768,10 @@  discard block
 block discarded – undo
768 768
                                                 $my_session_id
769 769
                                             );
770 770
                                         }
771
-									}
772
-								} else {
771
+                                    }
772
+                                } else {
773 773
 
774
-									copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
774
+                                    copy($this->course->backup_path.'/'.$document->path, $path.$new_file_name);
775 775
 
776 776
                                     //Replace old course code with the new destination code see BT#1985
777 777
                                     if (file_exists($path.$new_file_name)) {
@@ -831,20 +831,20 @@  discard block
 block discarded – undo
831 831
                                         null,
832 832
                                         $my_session_id
833 833
                                     );
834
-								}
835
-								break;
836
-
837
-						} // end switch
838
-					} else {
839
-					    // end if file exists
840
-						//make sure the source file actually exists
841
-						if (is_file($this->course->backup_path.'/'.$document->path) &&
834
+                                }
835
+                                break;
836
+
837
+                        } // end switch
838
+                    } else {
839
+                        // end if file exists
840
+                        //make sure the source file actually exists
841
+                        if (is_file($this->course->backup_path.'/'.$document->path) &&
842 842
                             is_readable($this->course->backup_path.'/'.$document->path) &&
843 843
                             is_dir(dirname($path.$document->path)) &&
844 844
                             is_writeable(dirname($path.$document->path))
845 845
                         ) {
846
-						    //echo 'Copying';
847
-							copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
846
+                            //echo 'Copying';
847
+                            copy($this->course->backup_path.'/'.$document->path, $path.$document->path);
848 848
 
849 849
                             //Replace old course code with the new destination code see BT#1985
850 850
                             if (file_exists($path.$document->path)) {
@@ -883,7 +883,7 @@  discard block
 block discarded – undo
883 883
                                 Database::query($sql);
884 884
                             }
885 885
 
886
-							$this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
886
+                            $this->course->resources[RESOURCE_DOCUMENT][$id]->destination_id = $document_id;
887 887
 
888 888
                             $itemProperty = isset($document->item_properties[0]) ? $document->item_properties[0] : '';
889 889
                             $insertUserId = isset($itemProperty['insert_user_id']) ? $itemProperty['insert_user_id'] : api_get_user_id();
@@ -905,78 +905,78 @@  discard block
 block discarded – undo
905 905
                                 null,
906 906
                                 $my_session_id
907 907
                             );
908
-						} else {
909
-							if (is_file($this->course->backup_path.'/'.$document->path) &&
908
+                        } else {
909
+                            if (is_file($this->course->backup_path.'/'.$document->path) &&
910 910
                                 is_readable($this->course->backup_path.'/'.$document->path)
911 911
                             ) {
912
-								error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
913
-							}
914
-							if (!is_dir(dirname($path.$document->path))) {
915
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
916
-							}
917
-							if (!is_writeable(dirname($path.$document->path))) {
918
-								error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
919
-							}
920
-						}
921
-					} // end file doesn't exist
922
-				}
923
-			} // end for each
924
-
925
-    		// Delete sessions for the copy the new folder in session
926
-    		unset($_SESSION['new_base_foldername']);
927
-    		unset($_SESSION['orig_base_foldername']);
928
-    		unset($_SESSION['new_base_path']);
929
-		}
930
-	}
931
-
932
-	/**
933
-	 * Restore scorm documents
934
-	 * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
912
+                                error_log('Course copy generated an ignoreable error while trying to copy '.$this->course->backup_path.'/'.$document->path.': file not found');
913
+                            }
914
+                            if (!is_dir(dirname($path.$document->path))) {
915
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not found');
916
+                            }
917
+                            if (!is_writeable(dirname($path.$document->path))) {
918
+                                error_log('Course copy generated an ignoreable error while trying to copy to '.dirname($path.$document->path).': directory not writeable');
919
+                            }
920
+                        }
921
+                    } // end file doesn't exist
922
+                }
923
+            } // end for each
924
+
925
+            // Delete sessions for the copy the new folder in session
926
+            unset($_SESSION['new_base_foldername']);
927
+            unset($_SESSION['orig_base_foldername']);
928
+            unset($_SESSION['new_base_path']);
929
+        }
930
+    }
931
+
932
+    /**
933
+     * Restore scorm documents
934
+     * TODO @TODO check that the restore function with renaming doesn't break the scorm structure!
935 935
      * see #7029
936
-	 */
937
-	public function restore_scorm_documents()
936
+     */
937
+    public function restore_scorm_documents()
938 938
     {
939
-		$perm = api_get_permissions_for_new_directories();
939
+        $perm = api_get_permissions_for_new_directories();
940 940
 
941
-		if ($this->course->has_resources(RESOURCE_SCORM)) {
942
-			$resources = $this->course->resources;
941
+        if ($this->course->has_resources(RESOURCE_SCORM)) {
942
+            $resources = $this->course->resources;
943 943
 
944
-			foreach ($resources[RESOURCE_SCORM] as $document) {
945
-				$path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
946
-				@mkdir(dirname($path.$document->path), $perm, true);
944
+            foreach ($resources[RESOURCE_SCORM] as $document) {
945
+                $path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/';
946
+                @mkdir(dirname($path.$document->path), $perm, true);
947 947
 
948
-				if (file_exists($path.$document->path)) {
949
-					switch ($this->file_option) {
950
-						case FILE_OVERWRITE:
951
-							rmdirr($path.$document->path);
948
+                if (file_exists($path.$document->path)) {
949
+                    switch ($this->file_option) {
950
+                        case FILE_OVERWRITE:
951
+                            rmdirr($path.$document->path);
952 952
                             copyDirTo(
953 953
                                 $this->course->backup_path . '/' . $document->path,
954 954
                                 $path . dirname($document->path),
955 955
                                 false
956 956
                             );
957
-							break;
958
-						case FILE_SKIP:
959
-							break;
957
+                            break;
958
+                        case FILE_SKIP:
959
+                            break;
960 960
                         case FILE_RENAME:
961
-							$i = 1;
962
-							$ext = explode('.', basename($document->path));
963
-							if (count($ext) > 1) {
964
-								$ext = array_pop($ext);
965
-								$file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
966
-								$ext = '.'.$ext;
967
-							} else {
968
-								$ext = '';
969
-								$file_name_no_ext = $document->path;
970
-							}
971
-
972
-							$new_file_name = $file_name_no_ext.'_'.$i.$ext;
973
-							$file_exists = file_exists($path.$new_file_name);
974
-
975
-							while ($file_exists) {
976
-								$i ++;
977
-								$new_file_name = $file_name_no_ext.'_'.$i.$ext;
978
-								$file_exists = file_exists($path.$new_file_name);
979
-							}
961
+                            $i = 1;
962
+                            $ext = explode('.', basename($document->path));
963
+                            if (count($ext) > 1) {
964
+                                $ext = array_pop($ext);
965
+                                $file_name_no_ext = substr($document->path, 0, - (strlen($ext) + 1));
966
+                                $ext = '.'.$ext;
967
+                            } else {
968
+                                $ext = '';
969
+                                $file_name_no_ext = $document->path;
970
+                            }
971
+
972
+                            $new_file_name = $file_name_no_ext.'_'.$i.$ext;
973
+                            $file_exists = file_exists($path.$new_file_name);
974
+
975
+                            while ($file_exists) {
976
+                                $i ++;
977
+                                $new_file_name = $file_name_no_ext.'_'.$i.$ext;
978
+                                $file_exists = file_exists($path.$new_file_name);
979
+                            }
980 980
 
981 981
                             rename(
982 982
                                 $this->course->backup_path . '/' . $document->path,
@@ -992,30 +992,30 @@  discard block
 block discarded – undo
992 992
                                 $this->course->backup_path . '/' . $document->path
993 993
                             );
994 994
 
995
-							break;
996
-					} // end switch
997
-				} else {
995
+                            break;
996
+                    } // end switch
997
+                } else {
998 998
                     // end if file exists
999 999
                     copyDirTo(
1000 1000
                         $this->course->backup_path . '/' . $document->path,
1001 1001
                         $path . dirname($document->path),
1002 1002
                         false
1003 1003
                     );
1004
-				}
1005
-			} // end for each
1006
-		}
1007
-	}
1008
-
1009
-	/**
1010
-	 * Restore forums
1011
-	 */
1012
-	public function restore_forums($sessionId = 0)
1004
+                }
1005
+            } // end for each
1006
+        }
1007
+    }
1008
+
1009
+    /**
1010
+     * Restore forums
1011
+     */
1012
+    public function restore_forums($sessionId = 0)
1013 1013
     {
1014
-		if ($this->course->has_resources(RESOURCE_FORUM)) {
1014
+        if ($this->course->has_resources(RESOURCE_FORUM)) {
1015 1015
             $sessionId = intval($sessionId);
1016
-			$table_forum = Database::get_course_table(TABLE_FORUM);
1017
-			$resources = $this->course->resources;
1018
-			foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1016
+            $table_forum = Database::get_course_table(TABLE_FORUM);
1017
+            $resources = $this->course->resources;
1018
+            foreach ($resources[RESOURCE_FORUM] as $id => $forum) {
1019 1019
                 $params = (array)$forum->obj;
1020 1020
                 $cat_id = '';
1021 1021
                 if (isset($this->course->resources[RESOURCE_FORUMCATEGORY]) &&
@@ -1062,33 +1062,33 @@  discard block
 block discarded – undo
1062 1062
                     Database::query($sql);
1063 1063
                 }
1064 1064
 
1065
-				$this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1066
-
1067
-				$forum_topics = 0;
1068
-				if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1069
-					foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1070
-						if ($topic->obj->forum_id == $id) {
1071
-							$this->restore_topic($topic_id, $new_id, $sessionId);
1072
-							$forum_topics ++;
1073
-						}
1074
-					}
1075
-				}
1076
-				if ($forum_topics > 0) {
1077
-					$sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1065
+                $this->course->resources[RESOURCE_FORUM][$id]->destination_id = $new_id;
1066
+
1067
+                $forum_topics = 0;
1068
+                if (is_array($this->course->resources[RESOURCE_FORUMTOPIC])) {
1069
+                    foreach ($this->course->resources[RESOURCE_FORUMTOPIC] as $topic_id => $topic) {
1070
+                        if ($topic->obj->forum_id == $id) {
1071
+                            $this->restore_topic($topic_id, $new_id, $sessionId);
1072
+                            $forum_topics ++;
1073
+                        }
1074
+                    }
1075
+                }
1076
+                if ($forum_topics > 0) {
1077
+                    $sql = "UPDATE ".$table_forum." SET forum_threads = ".$forum_topics."
1078 1078
                             WHERE c_id = {$this->destination_course_id} AND forum_id = ".(int)$new_id;
1079
-					Database::query($sql);
1080
-				}
1081
-			}
1082
-		}
1083
-	}
1084
-
1085
-	/**
1086
-	 * Restore forum-categories
1087
-	 */
1079
+                    Database::query($sql);
1080
+                }
1081
+            }
1082
+        }
1083
+    }
1084
+
1085
+    /**
1086
+     * Restore forum-categories
1087
+     */
1088 1088
     public function restore_forum_category($my_id = null, $sessionId = 0)
1089 1089
     {
1090
-		$forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1091
-		$resources = $this->course->resources;
1090
+        $forum_cat_table = Database :: get_course_table(TABLE_FORUM_CATEGORY);
1091
+        $resources = $this->course->resources;
1092 1092
         if (!empty($resources[RESOURCE_FORUMCATEGORY])) {
1093 1093
             foreach ($resources[RESOURCE_FORUMCATEGORY] as $id => $forum_cat) {
1094 1094
                 if (!empty($my_id)) {
@@ -1125,16 +1125,16 @@  discard block
 block discarded – undo
1125 1125
                 }
1126 1126
             }
1127 1127
         }
1128
-	}
1128
+    }
1129 1129
 
1130
-	/**
1131
-	 * Restore a forum-topic
1132
-	 * @param false|string $forum_id
1133
-	 */
1130
+    /**
1131
+     * Restore a forum-topic
1132
+     * @param false|string $forum_id
1133
+     */
1134 1134
     public function restore_topic($thread_id, $forum_id, $sessionId = 0)
1135 1135
     {
1136
-		$table = Database :: get_course_table(TABLE_FORUM_THREAD);
1137
-		$topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1136
+        $table = Database :: get_course_table(TABLE_FORUM_THREAD);
1137
+        $topic = $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id];
1138 1138
 
1139 1139
         $params = (array)$topic->obj;
1140 1140
         $params = self::DBUTF8_array($params);
@@ -1171,27 +1171,27 @@  discard block
 block discarded – undo
1171 1171
             $sessionId
1172 1172
         );
1173 1173
 
1174
-		$this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1175
-		$topic_replies = -1;
1176
-
1177
-		foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1178
-			if ($post->obj->thread_id == $thread_id) {
1179
-				$topic_replies++;
1180
-				$this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1181
-			}
1182
-		}
1183
-		return $new_id;
1184
-	}
1185
-
1186
-	/**
1187
-	 * Restore a forum-post
1188
-	 * @TODO Restore tree-structure of posts. For example: attachments to posts.
1189
-	 * @param false|string $topic_id
1190
-	 */
1174
+        $this->course->resources[RESOURCE_FORUMTOPIC][$thread_id]->destination_id = $new_id;
1175
+        $topic_replies = -1;
1176
+
1177
+        foreach ($this->course->resources[RESOURCE_FORUMPOST] as $post_id => $post) {
1178
+            if ($post->obj->thread_id == $thread_id) {
1179
+                $topic_replies++;
1180
+                $this->restore_post($post_id, $new_id, $forum_id, $sessionId);
1181
+            }
1182
+        }
1183
+        return $new_id;
1184
+    }
1185
+
1186
+    /**
1187
+     * Restore a forum-post
1188
+     * @TODO Restore tree-structure of posts. For example: attachments to posts.
1189
+     * @param false|string $topic_id
1190
+     */
1191 1191
     public function restore_post($id, $topic_id, $forum_id, $sessionId = 0)
1192 1192
     {
1193
-		$table_post = Database :: get_course_table(TABLE_FORUM_POST);
1194
-		$post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1193
+        $table_post = Database :: get_course_table(TABLE_FORUM_POST);
1194
+        $post = $this->course->resources[RESOURCE_FORUMPOST][$id];
1195 1195
         $params = (array) $post->obj;
1196 1196
         $params['c_id'] = $this->destination_course_id;
1197 1197
         $params['forum_id'] = $forum_id;
@@ -1226,37 +1226,37 @@  discard block
 block discarded – undo
1226 1226
             null,
1227 1227
             $sessionId
1228 1228
         );
1229
-		$this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1229
+        $this->course->resources[RESOURCE_FORUMPOST][$id]->destination_id = $new_id;
1230 1230
 
1231
-		return $new_id;
1232
-	}
1231
+        return $new_id;
1232
+    }
1233 1233
 
1234
-	/**
1235
-	 * Restore links
1236
-	 */
1234
+    /**
1235
+     * Restore links
1236
+     */
1237 1237
     public function restore_links($session_id = 0)
1238 1238
     {
1239
-		if ($this->course->has_resources(RESOURCE_LINK)) {
1240
-			$link_table = Database :: get_course_table(TABLE_LINK);
1241
-			$resources = $this->course->resources;
1239
+        if ($this->course->has_resources(RESOURCE_LINK)) {
1240
+            $link_table = Database :: get_course_table(TABLE_LINK);
1241
+            $resources = $this->course->resources;
1242 1242
 
1243
-			foreach ($resources[RESOURCE_LINK] as $id => $link) {
1243
+            foreach ($resources[RESOURCE_LINK] as $id => $link) {
1244 1244
                 $cat_id = $this->restore_link_category(
1245 1245
                     $link->category_id,
1246 1246
                     $session_id
1247 1247
                 );
1248
-				$sql = "SELECT MAX(display_order)
1248
+                $sql = "SELECT MAX(display_order)
1249 1249
 				        FROM $link_table
1250 1250
 				        WHERE
1251 1251
 				            c_id = ".$this->destination_course_id." AND
1252 1252
 				            category_id='" . intval($cat_id). "'";
1253
-				$result = Database::query($sql);
1254
-    			list($max_order) = Database::fetch_array($result);
1253
+                $result = Database::query($sql);
1254
+                list($max_order) = Database::fetch_array($result);
1255 1255
 
1256 1256
                 $params = [];
1257
-    			if (!empty($session_id)) {
1257
+                if (!empty($session_id)) {
1258 1258
                     $params['session_id'] = $session_id;
1259
-    			}
1259
+                }
1260 1260
 
1261 1261
                 $params['c_id'] = $this->destination_course_id;
1262 1262
                 $params['url'] = self::DBUTF8($link->url);
@@ -1285,9 +1285,9 @@  discard block
 block discarded – undo
1285 1285
                     }
1286 1286
                     $this->course->resources[RESOURCE_LINK][$id]->destination_id = $id;
1287 1287
                 }
1288
-			}
1289
-		}
1290
-	}
1288
+            }
1289
+        }
1290
+    }
1291 1291
 
1292 1292
     /**
1293 1293
      * Restore a link-category
@@ -1331,21 +1331,21 @@  discard block
 block discarded – undo
1331 1331
         return $this->course->resources[RESOURCE_LINKCATEGORY][$id]->destination_id;
1332 1332
     }
1333 1333
 
1334
-	/**
1335
-	 * Restore tool intro
1336
-	 */
1334
+    /**
1335
+     * Restore tool intro
1336
+     */
1337 1337
     public function restore_tool_intro($sessionId = 0)
1338 1338
     {
1339
-		if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1339
+        if ($this->course->has_resources(RESOURCE_TOOL_INTRO)) {
1340 1340
             $sessionId = intval($sessionId);
1341
-			$tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1342
-			$resources = $this->course->resources;
1343
-			foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1344
-				$sql = "DELETE FROM ".$tool_intro_table."
1341
+            $tool_intro_table = Database :: get_course_table(TABLE_TOOL_INTRO);
1342
+            $resources = $this->course->resources;
1343
+            foreach ($resources[RESOURCE_TOOL_INTRO] as $id => $tool_intro) {
1344
+                $sql = "DELETE FROM ".$tool_intro_table."
1345 1345
 				        WHERE
1346 1346
 				            c_id = ".$this->destination_course_id." AND
1347 1347
 				            id='".self::DBUTF8escapestring($tool_intro->id)."'";
1348
-				Database::query($sql);
1348
+                Database::query($sql);
1349 1349
 
1350 1350
                 $tool_intro->intro_text = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1351 1351
                     $tool_intro->intro_text,
@@ -1373,21 +1373,21 @@  discard block
 block discarded – undo
1373 1373
 
1374 1374
                     $this->course->resources[RESOURCE_TOOL_INTRO][$id]->destination_id = $id;
1375 1375
                 }
1376
-			}
1377
-		}
1378
-	}
1376
+            }
1377
+        }
1378
+    }
1379 1379
 
1380
-	/**
1381
-	 * Restore events
1382
-	 */
1380
+    /**
1381
+     * Restore events
1382
+     */
1383 1383
     public function restore_events($sessionId = 0)
1384 1384
     {
1385
-		if ($this->course->has_resources(RESOURCE_EVENT)) {
1385
+        if ($this->course->has_resources(RESOURCE_EVENT)) {
1386 1386
             $sessionId = intval($sessionId);
1387
-			$table = Database :: get_course_table(TABLE_AGENDA);
1388
-			$resources = $this->course->resources;
1389
-			foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1390
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1387
+            $table = Database :: get_course_table(TABLE_AGENDA);
1388
+            $resources = $this->course->resources;
1389
+            foreach ($resources[RESOURCE_EVENT] as $id => $event) {
1390
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1391 1391
                 $event->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1392 1392
                     $event->content,
1393 1393
                     $this->course->code,
@@ -1405,7 +1405,7 @@  discard block
 block discarded – undo
1405 1405
                     'end_date' => $event->end_date,
1406 1406
                     'session_id' => $sessionId,
1407 1407
                 ];
1408
-				$new_event_id = Database::insert($table, $params);
1408
+                $new_event_id = Database::insert($table, $params);
1409 1409
 
1410 1410
                 if ($new_event_id) {
1411 1411
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_event_id";
@@ -1418,30 +1418,30 @@  discard block
 block discarded – undo
1418 1418
                     $this->course->resources[RESOURCE_EVENT][$id]->destination_id = $new_event_id;
1419 1419
                 }
1420 1420
 
1421
-				// Copy event attachment
1421
+                // Copy event attachment
1422 1422
 
1423
-				$origin_path = $this->course->backup_path.'/upload/calendar/';
1424
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1423
+                $origin_path = $this->course->backup_path.'/upload/calendar/';
1424
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/calendar/';
1425 1425
 
1426
-				if (!empty($this->course->orig)) {
1426
+                if (!empty($this->course->orig)) {
1427 1427
 
1428
-					$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1429
-					$sql = 'SELECT path, comment, size, filename
1428
+                    $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1429
+                    $sql = 'SELECT path, comment, size, filename
1430 1430
 					        FROM '.$table_attachment.'
1431 1431
 					        WHERE c_id = '.$this->destination_course_id.' AND agenda_id = '.$id;
1432
-					$attachment_event = Database::query($sql);
1433
-					$attachment_event = Database::fetch_object($attachment_event);
1432
+                    $attachment_event = Database::query($sql);
1433
+                    $attachment_event = Database::fetch_object($attachment_event);
1434 1434
 
1435
-					if (file_exists($origin_path.$attachment_event->path) &&
1435
+                    if (file_exists($origin_path.$attachment_event->path) &&
1436 1436
                         !is_dir($origin_path.$attachment_event->path)
1437 1437
                     ) {
1438
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1439
-						$copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1440
-						//$copy_result = true;
1441
-						if ($copy_result) {
1442
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1438
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1439
+                        $copy_result = copy($origin_path.$attachment_event->path, $destination_path.$new_filename);
1440
+                        //$copy_result = true;
1441
+                        if ($copy_result) {
1442
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1443 1443
 
1444
-							$params = [
1444
+                            $params = [
1445 1445
                                 'c_id' => $this->destination_course_id,
1446 1446
                                 'path' => self::DBUTF8($new_filename),
1447 1447
                                 'comment' => self::DBUTF8($attachment_event->comment),
@@ -1455,17 +1455,17 @@  discard block
 block discarded – undo
1455 1455
                                 Database::query($sql);
1456 1456
                             }
1457 1457
                         }
1458
-					}
1459
-				} else {
1460
-					// get the info of the file
1461
-					if (!empty($event->attachment_path) &&
1458
+                    }
1459
+                } else {
1460
+                    // get the info of the file
1461
+                    if (!empty($event->attachment_path) &&
1462 1462
                         is_file($origin_path.$event->attachment_path) &&
1463 1463
                         is_readable($origin_path.$event->attachment_path)
1464 1464
                     ) {
1465
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1466
-						$copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1467
-						if ($copy_result) {
1468
-							$table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1465
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1466
+                        $copy_result = copy($origin_path.$event->attachment_path, $destination_path.$new_filename);
1467
+                        if ($copy_result) {
1468
+                            $table_attachment = Database :: get_course_table(TABLE_AGENDA_ATTACHMENT);
1469 1469
 
1470 1470
                             $params = [
1471 1471
                                 'c_id' => $this->destination_course_id,
@@ -1481,29 +1481,29 @@  discard block
 block discarded – undo
1481 1481
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $id";
1482 1482
                                 Database::query($sql);
1483 1483
                             }
1484
-						}
1485
-					}
1486
-				}
1487
-			}
1488
-		}
1489
-	}
1490
-
1491
-	/**
1492
-	 * Restore course-description
1493
-	 */
1484
+                        }
1485
+                    }
1486
+                }
1487
+            }
1488
+        }
1489
+    }
1490
+
1491
+    /**
1492
+     * Restore course-description
1493
+     */
1494 1494
     public function restore_course_descriptions($session_id = 0)
1495 1495
     {
1496
-		if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1497
-			$table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1498
-			$resources = $this->course->resources;
1499
-			foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1496
+        if ($this->course->has_resources(RESOURCE_COURSEDESCRIPTION)) {
1497
+            $table = Database :: get_course_table(TABLE_COURSE_DESCRIPTION);
1498
+            $resources = $this->course->resources;
1499
+            foreach ($resources[RESOURCE_COURSEDESCRIPTION] as $id => $cd) {
1500 1500
                 $courseDescription = (array) $cd;
1501 1501
 
1502 1502
                 $content = isset($courseDescription['content']) ? $courseDescription['content'] : '';
1503 1503
                 $descriptionType = isset($courseDescription['description_type']) ? $courseDescription['description_type'] : '';
1504 1504
                 $title = isset($courseDescription['title']) ? $courseDescription['title'] : '';
1505 1505
 
1506
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1506
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1507 1507
                 $description_content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1508 1508
                     $content,
1509 1509
                     $this->course->code,
@@ -1532,22 +1532,22 @@  discard block
 block discarded – undo
1532 1532
                     }
1533 1533
                     $this->course->resources[RESOURCE_COURSEDESCRIPTION][$id]->destination_id = $id;
1534 1534
                 }
1535
-			}
1536
-		}
1537
-	}
1535
+            }
1536
+        }
1537
+    }
1538 1538
 
1539
-	/**
1540
-	 * Restore announcements
1541
-	 */
1539
+    /**
1540
+     * Restore announcements
1541
+     */
1542 1542
     public function restore_announcements($sessionId = 0)
1543 1543
     {
1544
-		if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1544
+        if ($this->course->has_resources(RESOURCE_ANNOUNCEMENT)) {
1545 1545
             $sessionId = intval($sessionId);
1546
-			$table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1547
-			$resources = $this->course->resources;
1548
-			foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1546
+            $table = Database :: get_course_table(TABLE_ANNOUNCEMENT);
1547
+            $resources = $this->course->resources;
1548
+            foreach ($resources[RESOURCE_ANNOUNCEMENT] as $id => $announcement) {
1549 1549
 
1550
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
1550
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
1551 1551
                 $announcement->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1552 1552
                     $announcement->content,
1553 1553
                     $this->course->code,
@@ -1566,7 +1566,7 @@  discard block
 block discarded – undo
1566 1566
                     'session_id' => $sessionId,
1567 1567
                 ];
1568 1568
 
1569
-				$new_announcement_id = Database::insert($table, $params);
1569
+                $new_announcement_id = Database::insert($table, $params);
1570 1570
 
1571 1571
                 if ($new_announcement_id) {
1572 1572
                     $sql = "UPDATE $table SET id = iid WHERE iid = $new_announcement_id";
@@ -1578,32 +1578,32 @@  discard block
 block discarded – undo
1578 1578
                     $this->course->resources[RESOURCE_ANNOUNCEMENT][$id]->destination_id = $new_announcement_id;
1579 1579
                 }
1580 1580
 
1581
-				$origin_path = $this->course->backup_path.'/upload/announcements/';
1582
-				$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1581
+                $origin_path = $this->course->backup_path.'/upload/announcements/';
1582
+                $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/announcements/';
1583 1583
 
1584
-				// Copy announcement attachment file
1585
-				if (!empty($this->course->orig)) {
1584
+                // Copy announcement attachment file
1585
+                if (!empty($this->course->orig)) {
1586 1586
 
1587
-					$table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1588
-					$sql = 'SELECT path, comment, size, filename
1587
+                    $table_attachment = Database::get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1588
+                    $sql = 'SELECT path, comment, size, filename
1589 1589
 					        FROM '.$table_attachment.'
1590 1590
 					        WHERE
1591 1591
 					            c_id = '.$this->destination_course_id.' AND
1592 1592
 					            announcement_id = '.$id;
1593
-					$attachment_event = Database::query($sql);
1594
-					$attachment_event = Database::fetch_object($attachment_event);
1593
+                    $attachment_event = Database::query($sql);
1594
+                    $attachment_event = Database::fetch_object($attachment_event);
1595 1595
 
1596
-					if (file_exists($origin_path.$attachment_event->path) &&
1596
+                    if (file_exists($origin_path.$attachment_event->path) &&
1597 1597
                         !is_dir($origin_path.$attachment_event->path)
1598 1598
                     ) {
1599
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1599
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1600 1600
                         $copy_result = copy(
1601 1601
                             $origin_path.$attachment_event->path,
1602 1602
                             $destination_path.$new_filename
1603 1603
                         );
1604 1604
 
1605
-						if ($copy_result) {
1606
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1605
+                        if ($copy_result) {
1606
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1607 1607
 
1608 1608
                             $params = [
1609 1609
                                 'c_id' => $this->destination_course_id,
@@ -1620,19 +1620,19 @@  discard block
 block discarded – undo
1620 1620
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1621 1621
                                 Database::query($sql);
1622 1622
                             }
1623
-						}
1624
-					}
1625
-				} else {
1626
-					// get the info of the file
1627
-					if (!empty($announcement->attachment_path) &&
1623
+                        }
1624
+                    }
1625
+                } else {
1626
+                    // get the info of the file
1627
+                    if (!empty($announcement->attachment_path) &&
1628 1628
                         is_file($origin_path.$announcement->attachment_path) &&
1629 1629
                         is_readable($origin_path.$announcement->attachment_path)
1630 1630
                     ) {
1631
-						$new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1632
-						$copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1631
+                        $new_filename = uniqid(''); //ass seen in the add_agenda_attachment_file() function in agenda.inc.php
1632
+                        $copy_result = copy($origin_path.$announcement->attachment_path, $destination_path.$new_filename);
1633 1633
 
1634
-						if ($copy_result) {
1635
-							$table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1634
+                        if ($copy_result) {
1635
+                            $table_attachment = Database :: get_course_table(TABLE_ANNOUNCEMENT_ATTACHMENT);
1636 1636
 
1637 1637
                             $params = [
1638 1638
                                 'c_id' => $this->destination_course_id,
@@ -1649,12 +1649,12 @@  discard block
 block discarded – undo
1649 1649
                                 $sql = "UPDATE $table_attachment SET id = iid WHERE iid = $attachmentId";
1650 1650
                                 Database::query($sql);
1651 1651
                             }
1652
-						}
1653
-					}
1654
-				}
1655
-			}
1656
-		}
1657
-	}
1652
+                        }
1653
+                    }
1654
+                }
1655
+            }
1656
+        }
1657
+    }
1658 1658
 
1659 1659
     /**
1660 1660
      * Restore Quiz
@@ -1665,13 +1665,13 @@  discard block
 block discarded – undo
1665 1665
         $session_id = 0,
1666 1666
         $respect_base_content = false
1667 1667
     ) {
1668
-		if ($this->course->has_resources(RESOURCE_QUIZ)) {
1669
-			$table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1670
-			$table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1671
-			$table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1672
-			$resources = $this->course->resources;
1668
+        if ($this->course->has_resources(RESOURCE_QUIZ)) {
1669
+            $table_qui = Database :: get_course_table(TABLE_QUIZ_TEST);
1670
+            $table_rel = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
1671
+            $table_doc = Database :: get_course_table(TABLE_DOCUMENT);
1672
+            $resources = $this->course->resources;
1673 1673
 
1674
-			foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1674
+            foreach ($resources[RESOURCE_QUIZ] as $id => $quiz) {
1675 1675
 
1676 1676
                 if (isset($quiz->obj)) {
1677 1677
                     //For new imports
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
                     $quiz->obj = $quiz;
1682 1682
                 }
1683 1683
 
1684
-				$doc = '';
1684
+                $doc = '';
1685 1685
                 if (!empty($quiz->sound)) {
1686 1686
                     if (isset($this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]) &&
1687 1687
                         $this->course->resources[RESOURCE_DOCUMENT][$quiz->sound]->is_restored()) {
@@ -1689,14 +1689,14 @@  discard block
 block discarded – undo
1689 1689
                                 WHERE
1690 1690
                                     c_id = " . $this->destination_course_id . "  AND
1691 1691
                                     id = " . $resources[RESOURCE_DOCUMENT][$quiz->sound]->destination_id;
1692
-						$doc = Database::query($sql);
1693
-						$doc = Database::fetch_object($doc);
1694
-						$doc = str_replace('/audio/', '', $doc->path);
1695
-					}
1696
-				}
1697
-
1698
-				if ($id != -1) {
1699
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1692
+                        $doc = Database::query($sql);
1693
+                        $doc = Database::fetch_object($doc);
1694
+                        $doc = str_replace('/audio/', '', $doc->path);
1695
+                    }
1696
+                }
1697
+
1698
+                if ($id != -1) {
1699
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1700 1700
                     $quiz->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1701 1701
                         $quiz->description,
1702 1702
                         $this->course->code,
@@ -1708,13 +1708,13 @@  discard block
 block discarded – undo
1708 1708
                     $quiz->start_time = $quiz->start_time == '0000-00-00 00:00:00' ? null : $quiz->start_time;
1709 1709
                     $quiz->end_time = $quiz->end_time == '0000-00-00 00:00:00' ? null : $quiz->end_time;
1710 1710
 
1711
-					global $_custom;
1712
-					if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1711
+                    global $_custom;
1712
+                    if (isset($_custom['exercises_clean_dates_when_restoring']) &&
1713 1713
                         $_custom['exercises_clean_dates_when_restoring']
1714 1714
                     ) {
1715
-						$quiz->start_time = null;
1716
-						$quiz->end_time   = null;
1717
-					}
1715
+                        $quiz->start_time = null;
1716
+                        $quiz->end_time   = null;
1717
+                    }
1718 1718
 
1719 1719
                     $params = array(
1720 1720
                         'c_id' => $this->destination_course_id,
@@ -1748,10 +1748,10 @@  discard block
 block discarded – undo
1748 1748
                         }
1749 1749
                         $params['session_id'] = $my_session_id;
1750 1750
                     } else {
1751
-        				if (!empty($session_id)) {
1752
-        					$session_id = intval($session_id);
1751
+                        if (!empty($session_id)) {
1752
+                            $session_id = intval($session_id);
1753 1753
                             $params['session_id'] = $session_id;
1754
-    				    }
1754
+                        }
1755 1755
                     }
1756 1756
                     $new_id = Database::insert($table_qui, $params);
1757 1757
 
@@ -1760,15 +1760,15 @@  discard block
 block discarded – undo
1760 1760
                         Database::query($sql);
1761 1761
                     }
1762 1762
 
1763
-				} else {
1764
-					// $id = -1 identifies the fictionary test for collecting
1765
-					// orphan questions. We do not store it in the database.
1766
-					$new_id = -1;
1767
-				}
1763
+                } else {
1764
+                    // $id = -1 identifies the fictionary test for collecting
1765
+                    // orphan questions. We do not store it in the database.
1766
+                    $new_id = -1;
1767
+                }
1768 1768
 
1769
-				$this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1769
+                $this->course->resources[RESOURCE_QUIZ][$id]->destination_id = $new_id;
1770 1770
 
1771
-				$order = 0;
1771
+                $order = 0;
1772 1772
                 if (!empty($quiz->question_ids)) {
1773 1773
                     foreach ($quiz->question_ids as $index => $question_id) {
1774 1774
                         $qid = $this->restore_quiz_question($question_id);
@@ -1781,30 +1781,30 @@  discard block
 block discarded – undo
1781 1781
                         Database::query($sql);
1782 1782
                     }
1783 1783
                 }
1784
-			}
1785
-		}
1786
-	}
1784
+            }
1785
+        }
1786
+    }
1787 1787
 
1788
-	/**
1789
-	 * Restore quiz-questions
1788
+    /**
1789
+     * Restore quiz-questions
1790 1790
      * @params int question id
1791
-	 */
1791
+     */
1792 1792
     public function restore_quiz_question($id)
1793 1793
     {
1794
-		$resources = $this->course->resources;
1794
+        $resources = $this->course->resources;
1795 1795
         $question = isset($resources[RESOURCE_QUIZQUESTION][$id]) ? $resources[RESOURCE_QUIZQUESTION][$id] : null;
1796 1796
 
1797
-		$new_id = 0;
1797
+        $new_id = 0;
1798 1798
 
1799
-		if (is_object($question)) {
1800
-			if ($question->is_restored()) {
1801
-				return $question->destination_id;
1802
-			}
1803
-			$table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1804
-			$table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1799
+        if (is_object($question)) {
1800
+            if ($question->is_restored()) {
1801
+                return $question->destination_id;
1802
+            }
1803
+            $table_que = Database::get_course_table(TABLE_QUIZ_QUESTION);
1804
+            $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
1805 1805
             $table_options = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
1806 1806
 
1807
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
1807
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
1808 1808
             $question->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1809 1809
                 $question->description,
1810 1810
                 $this->course->code,
@@ -1825,7 +1825,7 @@  discard block
 block discarded – undo
1825 1825
                 'extra' => self::DBUTF8($question->extra),
1826 1826
             ];
1827 1827
 
1828
-			$new_id = Database::insert($table_que, $params);
1828
+            $new_id = Database::insert($table_que, $params);
1829 1829
 
1830 1830
             if ($new_id) {
1831 1831
 
@@ -1866,7 +1866,7 @@  discard block
 block discarded – undo
1866 1866
 
1867 1867
                 foreach ($temp as $index => $answer) {
1868 1868
                     //id = '".$index."',
1869
-					$params = [
1869
+                    $params = [
1870 1870
                         'c_id' => $this->destination_course_id,
1871 1871
                         'question_id' => $new_id,
1872 1872
                         'answer' => self::DBUTF8($answer['answer']),
@@ -1885,12 +1885,12 @@  discard block
 block discarded – undo
1885 1885
                         $sql = "UPDATE $table_ans SET id = iid, id_auto = iid WHERE iid = $answerId";
1886 1886
                         Database::query($sql);
1887 1887
                     }
1888
-				}
1889
-			} else {
1888
+                }
1889
+            } else {
1890 1890
                 $correct_answers = array();
1891
-				foreach ($question->answers as $index => $answer) {
1891
+                foreach ($question->answers as $index => $answer) {
1892 1892
 
1893
-					// check resources inside html from ckeditor tool and copy correct urls into recipient course
1893
+                    // check resources inside html from ckeditor tool and copy correct urls into recipient course
1894 1894
                     $answer['answer'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
1895 1895
                         $answer['answer'],
1896 1896
                         $this->course->code,
@@ -1929,8 +1929,8 @@  discard block
 block discarded – undo
1929 1929
                     }
1930 1930
 
1931 1931
                     $correct_answers[$answerId] = $answer['correct'];
1932
-				}
1933
-			}
1932
+                }
1933
+            }
1934 1934
 
1935 1935
             //Current course id
1936 1936
             $course_id = api_get_course_int_id();
@@ -2027,12 +2027,12 @@  discard block
 block discarded – undo
2027 2027
                     }
2028 2028
                 }
2029 2029
             }
2030
-			$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2031
-		}
2032
-		return $new_id;
2033
-	}
2030
+            $this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;
2031
+        }
2032
+        return $new_id;
2033
+    }
2034 2034
 
2035
-	/**
2035
+    /**
2036 2036
      * @todo : add session id when used for session
2037 2037
      */
2038 2038
     public function restore_test_category($session_id, $respect_base_content, $destination_course_code)
@@ -2112,21 +2112,21 @@  discard block
 block discarded – undo
2112 2112
         $sessionId = intval($sessionId);
2113 2113
 
2114 2114
         if ($this->course->has_resources(RESOURCE_SURVEY)) {
2115
-			$table_sur = Database :: get_course_table(TABLE_SURVEY);
2116
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2117
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2118
-			$resources = $this->course->resources;
2119
-			foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2115
+            $table_sur = Database :: get_course_table(TABLE_SURVEY);
2116
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2117
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2118
+            $resources = $this->course->resources;
2119
+            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
2120 2120
 
2121
-				$sql = 'SELECT survey_id FROM '.$table_sur.'
2121
+                $sql = 'SELECT survey_id FROM '.$table_sur.'
2122 2122
                         WHERE
2123 2123
                             c_id = '.$this->destination_course_id.' AND
2124 2124
                             code = "'.self::DBUTF8escapestring($survey->code).'" AND
2125 2125
                             lang = "'.self::DBUTF8escapestring($survey->lang).'" ';
2126 2126
 
2127
-				$result_check = Database::query($sql);
2127
+                $result_check = Database::query($sql);
2128 2128
 
2129
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2129
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2130 2130
                 $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2131 2131
                     $survey->title,
2132 2132
                     $this->course->code,
@@ -2180,20 +2180,20 @@  discard block
 block discarded – undo
2180 2180
                     'session_id' => $sessionId,
2181 2181
                 ];
2182 2182
 
2183
-				//An existing survey exists with the same code and the same language
2184
-				if (Database::num_rows($result_check) == 1) {
2185
-					switch ($this->file_option) {
2186
-						case FILE_SKIP:
2187
-							//Do nothing
2188
-							break;
2189
-						case FILE_RENAME:
2190
-							$survey_code = $survey->code.'_';
2191
-							$i=1;
2192
-							$temp_survey_code = $survey_code.$i;
2193
-							while (!$this->is_survey_code_available($temp_survey_code)) {
2194
-								$temp_survey_code = $survey_code.++$i;
2195
-							}
2196
-							$survey_code = $temp_survey_code;
2183
+                //An existing survey exists with the same code and the same language
2184
+                if (Database::num_rows($result_check) == 1) {
2185
+                    switch ($this->file_option) {
2186
+                        case FILE_SKIP:
2187
+                            //Do nothing
2188
+                            break;
2189
+                        case FILE_RENAME:
2190
+                            $survey_code = $survey->code.'_';
2191
+                            $i=1;
2192
+                            $temp_survey_code = $survey_code.$i;
2193
+                            while (!$this->is_survey_code_available($temp_survey_code)) {
2194
+                                $temp_survey_code = $survey_code.++$i;
2195
+                            }
2196
+                            $survey_code = $temp_survey_code;
2197 2197
 
2198 2198
                             $params['code'] = $survey_code;
2199 2199
                             $new_id = Database::insert($table_sur, $params);
@@ -2212,25 +2212,25 @@  discard block
 block discarded – undo
2212 2212
                                     Database::query($sql);
2213 2213
                                 }
2214 2214
                             }
2215
-							break;
2216
-						case FILE_OVERWRITE:
2217
-							// Delete the existing survey with the same code and language and import the one of the source course
2218
-							// getting the information of the survey (used for when the survey is shared)
2215
+                            break;
2216
+                        case FILE_OVERWRITE:
2217
+                            // Delete the existing survey with the same code and language and import the one of the source course
2218
+                            // getting the information of the survey (used for when the survey is shared)
2219 2219
 
2220
-							$sql = "SELECT * FROM $table_sur
2220
+                            $sql = "SELECT * FROM $table_sur
2221 2221
 							        WHERE
2222 2222
 							            c_id = ".$this->destination_course_id." AND
2223 2223
 							            survey_id='".self::DBUTF8escapestring(Database::result($result_check,0,0))."'";
2224
-							$result = Database::query($sql);
2225
-							$survey_data = Database::fetch_array($result,'ASSOC');
2224
+                            $result = Database::query($sql);
2225
+                            $survey_data = Database::fetch_array($result,'ASSOC');
2226 2226
 
2227
-							// if the survey is shared => also delete the shared content
2228
-							if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2227
+                            // if the survey is shared => also delete the shared content
2228
+                            if (isset($survey_data['survey_share']) && is_numeric($survey_data['survey_share'])) {
2229 2229
                                 SurveyManager::delete_survey($survey_data['survey_share'], true,$this->destination_course_id);
2230
-							}
2231
-							SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2230
+                            }
2231
+                            SurveyManager :: delete_survey($survey_data['survey_id'],false,$this->destination_course_id);
2232 2232
 
2233
-							// Insert the new source survey
2233
+                            // Insert the new source survey
2234 2234
                             $new_id = Database::insert($table_sur, $params);
2235 2235
 
2236 2236
                             if ($new_id) {
@@ -2251,11 +2251,11 @@  discard block
 block discarded – undo
2251 2251
                                     Database::query($sql);
2252 2252
                                 }
2253 2253
                             }
2254
-							break;
2255
-						default:
2256
-							break;
2257
-					}
2258
-				} else {
2254
+                            break;
2255
+                        default:
2256
+                            break;
2257
+                    }
2258
+                } else {
2259 2259
                     // No existing survey with the same language and the same code, we just copy the survey
2260 2260
                     $new_id = Database::insert($table_sur, $params);
2261 2261
 
@@ -2277,48 +2277,48 @@  discard block
 block discarded – undo
2277 2277
                             Database::query($sql);
2278 2278
                         }
2279 2279
                     }
2280
-				}
2281
-			}
2282
-		}
2283
-	}
2284
-
2285
-	/**
2286
-	 * Check availability of a survey code
2287
-	 * @param string $survey_code
2288
-	 */
2280
+                }
2281
+            }
2282
+        }
2283
+    }
2284
+
2285
+    /**
2286
+     * Check availability of a survey code
2287
+     * @param string $survey_code
2288
+     */
2289 2289
     public function is_survey_code_available($survey_code)
2290 2290
     {
2291
-		$table_sur = Database :: get_course_table(TABLE_SURVEY);
2292
-		$sql = "SELECT * FROM $table_sur
2291
+        $table_sur = Database :: get_course_table(TABLE_SURVEY);
2292
+        $sql = "SELECT * FROM $table_sur
2293 2293
 		        WHERE
2294 2294
 		            c_id = ".$this->destination_course_id." AND
2295 2295
 		            code='".self::DBUTF8escapestring($survey_code)."'";
2296
-		$result = Database::query($sql);
2296
+        $result = Database::query($sql);
2297 2297
         if (Database::num_rows($result) > 0) {
2298 2298
             return false;
2299 2299
         } else {
2300 2300
             return true;
2301 2301
         }
2302
-	}
2302
+    }
2303 2303
 
2304
-	/**
2305
-	 * Restore survey-questions
2306
-	 * @param string $survey_id
2307
-	 */
2304
+    /**
2305
+     * Restore survey-questions
2306
+     * @param string $survey_id
2307
+     */
2308 2308
     public function restore_survey_question($id, $survey_id)
2309 2309
     {
2310
-		$resources = $this->course->resources;
2311
-		$question = $resources[RESOURCE_SURVEYQUESTION][$id];
2310
+        $resources = $this->course->resources;
2311
+        $question = $resources[RESOURCE_SURVEYQUESTION][$id];
2312 2312
         $new_id = 0;
2313 2313
 
2314
-		if (is_object($question)) {
2315
-			if ($question->is_restored()) {
2316
-				return $question->destination_id;
2317
-			}
2318
-			$table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2319
-			$table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2314
+        if (is_object($question)) {
2315
+            if ($question->is_restored()) {
2316
+                return $question->destination_id;
2317
+            }
2318
+            $table_que = Database :: get_course_table(TABLE_SURVEY_QUESTION);
2319
+            $table_ans = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
2320 2320
 
2321
-			// check resources inside html from ckeditor tool and copy correct urls into recipient course
2321
+            // check resources inside html from ckeditor tool and copy correct urls into recipient course
2322 2322
             $question->survey_question = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2323 2323
                 $question->survey_question,
2324 2324
                 $this->course->code,
@@ -2372,10 +2372,10 @@  discard block
 block discarded – undo
2372 2372
                 }
2373 2373
                 $this->course->resources[RESOURCE_SURVEYQUESTION][$id]->destination_id = $new_id;
2374 2374
             }
2375
-		}
2375
+        }
2376 2376
 
2377
-		return $new_id;
2378
-	}
2377
+        return $new_id;
2378
+    }
2379 2379
 
2380 2380
     /**
2381 2381
      * Restoring learning paths
@@ -2386,19 +2386,19 @@  discard block
 block discarded – undo
2386 2386
     {
2387 2387
         $session_id = intval($session_id);
2388 2388
 
2389
-		if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2389
+        if ($this->course->has_resources(RESOURCE_LEARNPATH)) {
2390 2390
             $table_main = Database::get_course_table(TABLE_LP_MAIN);
2391 2391
             $table_item = Database::get_course_table(TABLE_LP_ITEM);
2392 2392
             $table_tool = Database::get_course_table(TABLE_TOOL_LIST);
2393 2393
 
2394
-			$resources = $this->course->resources;
2394
+            $resources = $this->course->resources;
2395 2395
 
2396
-			$origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2397
-			$destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2396
+            $origin_path = $this->course->backup_path.'/upload/learning_path/images/';
2397
+            $destination_path = api_get_path(SYS_COURSE_PATH).$this->course->destination_path.'/upload/learning_path/images/';
2398 2398
 
2399
-			foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2400
-				$condition_session = '';
2401
-				if (!empty($session_id)) {
2399
+            foreach ($resources[RESOURCE_LEARNPATH] as $id => $lp) {
2400
+                $condition_session = '';
2401
+                if (!empty($session_id)) {
2402 2402
                     if ($respect_base_content) {
2403 2403
                         $my_session_id = $lp->session_id;
2404 2404
                         if (!empty($lp->session_id)) {
@@ -2409,20 +2409,20 @@  discard block
 block discarded – undo
2409 2409
                         $session_id = intval($session_id);
2410 2410
                         $condition_session = $session_id;
2411 2411
                     }
2412
-				}
2413
-
2414
-				// Adding the author's image
2415
-				if (!empty($lp->preview_image)) {
2416
-					$new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2417
-					if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2418
-						$copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2419
-						if ($copy_result) {
2420
-							$lp->preview_image = $new_filename;
2421
-						} else {
2422
-							$lp->preview_image ='';
2423
-						}
2424
-					}
2425
-				}
2412
+                }
2413
+
2414
+                // Adding the author's image
2415
+                if (!empty($lp->preview_image)) {
2416
+                    $new_filename = uniqid('').substr($lp->preview_image,strlen($lp->preview_image)-7, strlen($lp->preview_image));
2417
+                    if (file_exists($origin_path.$lp->preview_image) && !is_dir($origin_path.$lp->preview_image)) {
2418
+                        $copy_result = copy($origin_path.$lp->preview_image, $destination_path.$new_filename);
2419
+                        if ($copy_result) {
2420
+                            $lp->preview_image = $new_filename;
2421
+                        } else {
2422
+                            $lp->preview_image ='';
2423
+                        }
2424
+                    }
2425
+                }
2426 2426
 
2427 2427
                 if ($this->add_text_in_items) {
2428 2428
                     $lp->name = $lp->name.' '.get_lang('CopyLabelSuffix');
@@ -2480,7 +2480,7 @@  discard block
 block discarded – undo
2480 2480
                     $params['session_id'] = $condition_session;
2481 2481
                 }
2482 2482
 
2483
-				$new_lp_id = Database::insert($table_main, $params);
2483
+                $new_lp_id = Database::insert($table_main, $params);
2484 2484
 
2485 2485
                 if ($new_lp_id) {
2486 2486
 
@@ -2541,13 +2541,13 @@  discard block
 block discarded – undo
2541 2541
                 $old_refs = array();
2542 2542
                 $prerequisite_ids = array();
2543 2543
 
2544
-				foreach ($lp->get_items() as $index => $item) {
2545
-					// we set the ref code here and then we update in a for loop
2546
-					$ref = $item['ref'];
2544
+                foreach ($lp->get_items() as $index => $item) {
2545
+                    // we set the ref code here and then we update in a for loop
2546
+                    $ref = $item['ref'];
2547 2547
 
2548
-					// Dealing with path the same way as ref as some data has
2548
+                    // Dealing with path the same way as ref as some data has
2549 2549
                     // been put into path when it's a local resource
2550
-					// Only fix the path for no scos
2550
+                    // Only fix the path for no scos
2551 2551
                     if ($item['item_type'] == 'sco') {
2552 2552
                         $path = $item['path'];
2553 2553
                     } else {
@@ -2576,128 +2576,128 @@  discard block
 block discarded – undo
2576 2576
                         'launch_data' => self::DBUTF8($item['launch_data']),
2577 2577
                     ];
2578 2578
 
2579
-					$new_item_id = Database::insert($table_item, $params);
2579
+                    $new_item_id = Database::insert($table_item, $params);
2580 2580
 
2581 2581
                     $sql = "UPDATE $table_item SET id = iid WHERE iid = $new_item_id";
2582 2582
                     Database::query($sql);
2583 2583
 
2584
-					//save a link between old and new item IDs
2585
-					$new_item_ids[$item['id']] = $new_item_id;
2586
-					//save a reference of items that need a parent_item_id refresh
2587
-					$parent_item_ids[$new_item_id] = $item['parent_item_id'];
2588
-					//save a reference of items that need a previous_item_id refresh
2589
-					$previous_item_ids[$new_item_id] = $item['previous_item_id'];
2590
-					//save a reference of items that need a next_item_id refresh
2591
-					$next_item_ids[$new_item_id] = $item['next_item_id'];
2592
-
2593
-					if (!empty($item['prerequisite'])) {
2594
-						if ($lp->lp_type =='2') {
2595
-							// if is an sco
2596
-							$old_prerequisite[$new_item_id]= $item['prerequisite'];
2597
-						} else {
2598
-							$old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2599
-						}
2600
-					}
2601
-
2602
-					if (!empty($ref)) {
2603
-						if ($lp->lp_type =='2') {
2604
-							// if is an sco
2605
-							$old_refs[$new_item_id]= $ref;
2606
-						} else {
2584
+                    //save a link between old and new item IDs
2585
+                    $new_item_ids[$item['id']] = $new_item_id;
2586
+                    //save a reference of items that need a parent_item_id refresh
2587
+                    $parent_item_ids[$new_item_id] = $item['parent_item_id'];
2588
+                    //save a reference of items that need a previous_item_id refresh
2589
+                    $previous_item_ids[$new_item_id] = $item['previous_item_id'];
2590
+                    //save a reference of items that need a next_item_id refresh
2591
+                    $next_item_ids[$new_item_id] = $item['next_item_id'];
2592
+
2593
+                    if (!empty($item['prerequisite'])) {
2594
+                        if ($lp->lp_type =='2') {
2595
+                            // if is an sco
2596
+                            $old_prerequisite[$new_item_id]= $item['prerequisite'];
2597
+                        } else {
2598
+                            $old_prerequisite[$new_item_id]= $new_item_ids[$item['prerequisite']];
2599
+                        }
2600
+                    }
2601
+
2602
+                    if (!empty($ref)) {
2603
+                        if ($lp->lp_type =='2') {
2604
+                            // if is an sco
2605
+                            $old_refs[$new_item_id]= $ref;
2606
+                        } else {
2607 2607
                             $old_refs[$new_item_id]= $new_item_ids[$ref];
2608
-						}
2609
-					}
2608
+                        }
2609
+                    }
2610 2610
 
2611
-					$prerequisite_ids[$new_item_id] = $item['prerequisite'];
2612
-				}
2611
+                    $prerequisite_ids[$new_item_id] = $item['prerequisite'];
2612
+                }
2613 2613
 
2614
-				// Updating prerequisites
2615
-				foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2616
-					if ($my_old_prerequisite != ''){
2617
-						$sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2614
+                // Updating prerequisites
2615
+                foreach ($old_prerequisite  as $key=>$my_old_prerequisite) {
2616
+                    if ($my_old_prerequisite != ''){
2617
+                        $sql = "UPDATE ".$table_item." SET prerequisite = '".$my_old_prerequisite."'
2618 2618
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2619
-						Database::query($sql);
2620
-					}
2621
-				}
2622
-
2623
-				// Updating refs
2624
-				foreach ($old_refs  as $key=>$my_old_ref) {
2625
-					if ($my_old_ref != '') {
2626
-						$sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2619
+                        Database::query($sql);
2620
+                    }
2621
+                }
2622
+
2623
+                // Updating refs
2624
+                foreach ($old_refs  as $key=>$my_old_ref) {
2625
+                    if ($my_old_ref != '') {
2626
+                        $sql = "UPDATE ".$table_item." SET ref = '".$my_old_ref."'
2627 2627
 						        WHERE c_id = ".$this->destination_course_id." AND id = '".$key."'  ";
2628
-						Database::query($sql);
2629
-					}
2630
-				}
2631
-
2632
-				foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2633
-					$parent_new_id = 0;
2634
-					if($parent_item_old_id != 0){
2635
-						$parent_new_id = $new_item_ids[$parent_item_old_id];
2636
-					}
2637
-					$sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2628
+                        Database::query($sql);
2629
+                    }
2630
+                }
2631
+
2632
+                foreach ($parent_item_ids as $new_item_id => $parent_item_old_id) {
2633
+                    $parent_new_id = 0;
2634
+                    if($parent_item_old_id != 0){
2635
+                        $parent_new_id = $new_item_ids[$parent_item_old_id];
2636
+                    }
2637
+                    $sql = "UPDATE ".$table_item." SET parent_item_id = '".$parent_new_id."'
2638 2638
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2639
-					Database::query($sql);
2640
-				}
2641
-				foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2642
-					$previous_new_id = 0;
2643
-					if ($previous_item_old_id != 0){
2644
-						$previous_new_id = $new_item_ids[$previous_item_old_id];
2645
-					}
2646
-					$sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2639
+                    Database::query($sql);
2640
+                }
2641
+                foreach ($previous_item_ids as $new_item_id => $previous_item_old_id) {
2642
+                    $previous_new_id = 0;
2643
+                    if ($previous_item_old_id != 0){
2644
+                        $previous_new_id = $new_item_ids[$previous_item_old_id];
2645
+                    }
2646
+                    $sql = "UPDATE ".$table_item." SET previous_item_id = '".$previous_new_id."'
2647 2647
 					        WHERE  c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2648
-					Database::query($sql);
2649
-				}
2650
-
2651
-				foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2652
-					$next_new_id = 0;
2653
-					if ($next_item_old_id != 0){
2654
-						$next_new_id = $new_item_ids[$next_item_old_id];
2655
-					}
2656
-					$sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2648
+                    Database::query($sql);
2649
+                }
2650
+
2651
+                foreach ($next_item_ids as $new_item_id => $next_item_old_id) {
2652
+                    $next_new_id = 0;
2653
+                    if ($next_item_old_id != 0){
2654
+                        $next_new_id = $new_item_ids[$next_item_old_id];
2655
+                    }
2656
+                    $sql = "UPDATE ".$table_item." SET next_item_id = '".$next_new_id."'
2657 2657
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2658
-					Database::query($sql);
2659
-				}
2660
-
2661
-				foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2662
-					$prerequisite_new_id = 0;
2663
-					if ($prerequisite_old_id != 0){
2664
-						$prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2665
-					}
2666
-					$sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2658
+                    Database::query($sql);
2659
+                }
2660
+
2661
+                foreach ($prerequisite_ids as $new_item_id => $prerequisite_old_id) {
2662
+                    $prerequisite_new_id = 0;
2663
+                    if ($prerequisite_old_id != 0){
2664
+                        $prerequisite_new_id = $new_item_ids[$prerequisite_old_id];
2665
+                    }
2666
+                    $sql = "UPDATE ".$table_item." SET prerequisite = '".$prerequisite_new_id."'
2667 2667
 					        WHERE c_id = ".$this->destination_course_id." AND id = '".$new_item_id."'";
2668
-					Database::query($sql);
2669
-				}
2670
-				$this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2671
-			}
2672
-		}
2673
-	}
2674
-
2675
-	/**
2676
-	 * Restore works
2668
+                    Database::query($sql);
2669
+                }
2670
+                $this->course->resources[RESOURCE_LEARNPATH][$id]->destination_id = $new_lp_id;
2671
+            }
2672
+        }
2673
+    }
2674
+
2675
+    /**
2676
+     * Restore works
2677 2677
      * @deprecated use restore_works
2678 2678
      *
2679
-	 */
2680
-	public function restore_student_publication($sessionId = 0)
2679
+     */
2680
+    public function restore_student_publication($sessionId = 0)
2681 2681
     {
2682 2682
         $sessionId = intval($sessionId);
2683 2683
         $work_assignment_table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT);
2684 2684
         $work_table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION);
2685 2685
         $item_property_table = Database:: get_course_table(TABLE_ITEM_PROPERTY);
2686 2686
 
2687
-		// Query in student publication
2688
-		$sql = 'SELECT * FROM '.$work_table.'
2687
+        // Query in student publication
2688
+        $sql = 'SELECT * FROM '.$work_table.'
2689 2689
 		        WHERE c_id = '.$this->course_origin_id.' AND filetype = "folder" AND active IN (0, 1) ';
2690 2690
 
2691
-		$result = Database::query($sql);
2692
-		$folders = Database::store_result($result, 'ASSOC');
2691
+        $result = Database::query($sql);
2692
+        $folders = Database::store_result($result, 'ASSOC');
2693 2693
 
2694
-		foreach ($folders  as $folder) {
2695
-		    $old_id = $folder['id'];
2694
+        foreach ($folders  as $folder) {
2695
+            $old_id = $folder['id'];
2696 2696
             unset($folder['id']);
2697
-			$folder['c_id'] = $this->destination_course_id;
2697
+            $folder['c_id'] = $this->destination_course_id;
2698 2698
             $folder['parent_id'] = 0;
2699 2699
             $folder['session_id'] = $sessionId;
2700
-			$new_id = Database::insert($work_table, $folder);
2700
+            $new_id = Database::insert($work_table, $folder);
2701 2701
 
2702 2702
             if ($new_id) {
2703 2703
                 // query in item property
@@ -2756,23 +2756,23 @@  discard block
 block discarded – undo
2756 2756
                     }
2757 2757
                 }
2758 2758
             }
2759
-		}
2759
+        }
2760 2760
 
2761 2761
         $destination = '../..'.api_get_path(REL_COURSE_PATH).$this->course->destination_path.'/work/';
2762 2762
         $origin = '../..'.api_get_path(REL_COURSE_PATH).$this->course->info['path'].'/work/';
2763 2763
         self::allow_create_all_directory($origin, $destination, false);
2764
-	}
2764
+    }
2765 2765
 
2766 2766
     /**
2767
-    * copy all directory and sub directory
2768
-    * @param string The path origin
2769
-    * @param string The path destination
2770
-    * @param boolean Option Overwrite
2771
-    * @param string $source
2772
-    * @param string $dest
2773
-    * @return void()
2774
-    * @deprecated
2775
-    */
2767
+     * copy all directory and sub directory
2768
+     * @param string The path origin
2769
+     * @param string The path destination
2770
+     * @param boolean Option Overwrite
2771
+     * @param string $source
2772
+     * @param string $dest
2773
+     * @return void()
2774
+     * @deprecated
2775
+     */
2776 2776
     public function allow_create_all_directory($source, $dest, $overwrite = false)
2777 2777
     {
2778 2778
         if (!is_dir($dest)) {
@@ -2783,7 +2783,7 @@  discard block
 block discarded – undo
2783 2783
                 if ($file != '.' && $file != '..') {
2784 2784
                     $path = $source . '/' . $file;
2785 2785
                     if (is_file($path)) {
2786
-                       /* if (!is_file($dest . '/' . $file) || $overwrite)
2786
+                        /* if (!is_file($dest . '/' . $file) || $overwrite)
2787 2787
                         if (!@copy($path, $dest . '/' . $file)) {
2788 2788
                             echo '<font color="red">File ('.$path.') '.get_lang('NotHavePermission').'</font>';
2789 2789
                         }*/
@@ -2798,12 +2798,12 @@  discard block
 block discarded – undo
2798 2798
         }
2799 2799
     }
2800 2800
 
2801
-	/**
2802
-	 * Gets the new ID of one specific tool item from the tool name and the old ID
2803
-	 * @param	string	Tool name
2804
-	 * @param	integer	Old ID
2805
-	 * @return	integer	New ID
2806
-	 */
2801
+    /**
2802
+     * Gets the new ID of one specific tool item from the tool name and the old ID
2803
+     * @param	string	Tool name
2804
+     * @param	integer	Old ID
2805
+     * @return	integer	New ID
2806
+     */
2807 2807
     public function get_new_id($tool, $ref)
2808 2808
     {
2809 2809
         // Check if the value exist in the current array.
@@ -2825,25 +2825,25 @@  discard block
 block discarded – undo
2825 2825
         }
2826 2826
 
2827 2827
         return '';
2828
-	}
2828
+    }
2829 2829
 
2830
-	/**
2831
-	 * Restore glossary
2832
-	 */
2830
+    /**
2831
+     * Restore glossary
2832
+     */
2833 2833
     public function restore_glossary($session_id = 0)
2834 2834
     {
2835
-		if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2836
-			$table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2837
-			$resources = $this->course->resources;
2838
-			foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2835
+        if ($this->course->has_resources(RESOURCE_GLOSSARY)) {
2836
+            $table_glossary = Database :: get_course_table(TABLE_GLOSSARY);
2837
+            $resources = $this->course->resources;
2838
+            foreach ($resources[RESOURCE_GLOSSARY] as $id => $glossary) {
2839 2839
 
2840 2840
                 $params = [];
2841
-    			if (!empty($session_id)) {
2842
-    				$session_id = intval($session_id);
2841
+                if (!empty($session_id)) {
2842
+                    $session_id = intval($session_id);
2843 2843
                     $params['session_id'] = $session_id;
2844
-    			}
2844
+                }
2845 2845
 
2846
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2846
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2847 2847
                 $glossary->description = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2848 2848
                     $glossary->description,
2849 2849
                     $this->course->code,
@@ -2877,27 +2877,27 @@  discard block
 block discarded – undo
2877 2877
 
2878 2878
                     $this->course->resources[RESOURCE_GLOSSARY][$id]->destination_id = $my_id;
2879 2879
                 }
2880
-			}
2881
-		}
2882
-	}
2880
+            }
2881
+        }
2882
+    }
2883 2883
 
2884 2884
     /**
2885 2885
      * @param int $session_id
2886 2886
      */
2887 2887
     public function restore_wiki($session_id = 0)
2888 2888
     {
2889
-		if ($this->course->has_resources(RESOURCE_WIKI)) {
2890
-			// wiki table of the target course
2891
-			$table_wiki = Database :: get_course_table(TABLE_WIKI);
2892
-			$table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2889
+        if ($this->course->has_resources(RESOURCE_WIKI)) {
2890
+            // wiki table of the target course
2891
+            $table_wiki = Database :: get_course_table(TABLE_WIKI);
2892
+            $table_wiki_conf = Database :: get_course_table(TABLE_WIKI_CONF);
2893 2893
 
2894
-			// storing all the resources that have to be copied in an array
2895
-			$resources = $this->course->resources;
2894
+            // storing all the resources that have to be copied in an array
2895
+            $resources = $this->course->resources;
2896 2896
 
2897
-			foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2898
-				// the sql statement to insert the groups from the old course to the new course
2897
+            foreach ($resources[RESOURCE_WIKI] as $id => $wiki) {
2898
+                // the sql statement to insert the groups from the old course to the new course
2899 2899
 
2900
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2900
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2901 2901
                 $wiki->content = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2902 2902
                     $wiki->content,
2903 2903
                     $this->course->code,
@@ -2932,7 +2932,7 @@  discard block
 block discarded – undo
2932 2932
                     'user_ip' => ''
2933 2933
                 ];
2934 2934
 
2935
-				$new_id = Database::insert($table_wiki, $params);
2935
+                $new_id = Database::insert($table_wiki, $params);
2936 2936
 
2937 2937
                 if ($new_id) {
2938 2938
                     $sql = "UPDATE $table_wiki SET page_id = '$new_id', id = iid
@@ -2962,9 +2962,9 @@  discard block
 block discarded – undo
2962 2962
 
2963 2963
                     Database::insert($table_wiki_conf, $params);
2964 2964
                 }
2965
-			}
2966
-		}
2967
-	}
2965
+            }
2966
+        }
2967
+    }
2968 2968
 
2969 2969
     /**
2970 2970
      * Restore Thematics
@@ -2972,15 +2972,15 @@  discard block
 block discarded – undo
2972 2972
      */
2973 2973
     public function restore_thematic($session_id = 0)
2974 2974
     {
2975
-		if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2975
+        if ($this->course->has_resources(RESOURCE_THEMATIC)) {
2976 2976
             $table_thematic = Database::get_course_table(TABLE_THEMATIC);
2977 2977
             $table_thematic_advance = Database::get_course_table(TABLE_THEMATIC_ADVANCE);
2978 2978
             $table_thematic_plan = Database::get_course_table(TABLE_THEMATIC_PLAN);
2979 2979
 
2980
-			$resources = $this->course->resources;
2981
-			foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2980
+            $resources = $this->course->resources;
2981
+            foreach ($resources[RESOURCE_THEMATIC] as $id => $thematic) {
2982 2982
 
2983
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
2983
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
2984 2984
                 $thematic->params['content'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
2985 2985
                     $thematic->params['content'],
2986 2986
                     $this->course->code,
@@ -2988,13 +2988,13 @@  discard block
 block discarded – undo
2988 2988
                     $this->course->backup_path,
2989 2989
                     $this->course->info['path']
2990 2990
                 );
2991
-				$thematic->params['c_id']  = $this->destination_course_id;
2992
-				unset($thematic->params['id']);
2991
+                $thematic->params['c_id']  = $this->destination_course_id;
2992
+                unset($thematic->params['id']);
2993 2993
                 unset($thematic->params['iid']);
2994 2994
 
2995
-				$last_id = Database::insert($table_thematic, $thematic->params, false);
2995
+                $last_id = Database::insert($table_thematic, $thematic->params, false);
2996 2996
 
2997
-				if ($last_id) {
2997
+                if ($last_id) {
2998 2998
 
2999 2999
                     $sql = "UPDATE $table_thematic SET id = iid WHERE iid = $last_id";
3000 3000
                     Database::query($sql);
@@ -3007,12 +3007,12 @@  discard block
 block discarded – undo
3007 3007
                         api_get_user_id()
3008 3008
                     );
3009 3009
 
3010
-					foreach ($thematic->thematic_advance_list as $thematic_advance) {
3011
-						unset($thematic_advance['id']);
3010
+                    foreach ($thematic->thematic_advance_list as $thematic_advance) {
3011
+                        unset($thematic_advance['id']);
3012 3012
                         unset($thematic_advance['iid']);
3013
-						$thematic_advance['attendance_id'] = 0;
3014
-						$thematic_advance['thematic_id'] = $last_id;
3015
-						$thematic_advance['c_id']  = $this->destination_course_id;
3013
+                        $thematic_advance['attendance_id'] = 0;
3014
+                        $thematic_advance['thematic_id'] = $last_id;
3015
+                        $thematic_advance['c_id']  = $this->destination_course_id;
3016 3016
 
3017 3017
                         $my_id = Database::insert(
3018 3018
                             $table_thematic_advance,
@@ -3020,7 +3020,7 @@  discard block
 block discarded – undo
3020 3020
                             false
3021 3021
                         );
3022 3022
 
3023
-						if ($my_id) {
3023
+                        if ($my_id) {
3024 3024
 
3025 3025
                             $sql = "UPDATE $table_thematic_advance SET id = iid WHERE iid = $my_id";
3026 3026
                             Database::query($sql);
@@ -3032,17 +3032,17 @@  discard block
 block discarded – undo
3032 3032
                                 'ThematicAdvanceAdded',
3033 3033
                                 api_get_user_id()
3034 3034
                             );
3035
-						}
3036
-					}
3035
+                        }
3036
+                    }
3037 3037
 
3038
-					foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
-						unset($thematic_plan['id']);
3038
+                    foreach($thematic->thematic_plan_list as $thematic_plan) {
3039
+                        unset($thematic_plan['id']);
3040 3040
                         unset($thematic_plan['iid']);
3041
-						$thematic_plan['thematic_id'] = $last_id;
3042
-						$thematic_plan['c_id'] = $this->destination_course_id;
3043
-						$my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3041
+                        $thematic_plan['thematic_id'] = $last_id;
3042
+                        $thematic_plan['c_id'] = $this->destination_course_id;
3043
+                        $my_id = Database::insert($table_thematic_plan, $thematic_plan, false);
3044 3044
 
3045
-						if ($my_id) {
3045
+                        if ($my_id) {
3046 3046
 
3047 3047
                             $sql = "UPDATE $table_thematic_plan SET id = iid WHERE iid = $my_id";
3048 3048
                             Database::query($sql);
@@ -3054,12 +3054,12 @@  discard block
 block discarded – undo
3054 3054
                                 'ThematicPlanAdded',
3055 3055
                                 api_get_user_id()
3056 3056
                             );
3057
-						}
3058
-					}
3059
-				}
3060
-			}
3061
-		}
3062
-	}
3057
+                        }
3058
+                    }
3059
+                }
3060
+            }
3061
+        }
3062
+    }
3063 3063
 
3064 3064
     /**
3065 3065
      * Restore Attendance
@@ -3067,14 +3067,14 @@  discard block
 block discarded – undo
3067 3067
      */
3068 3068
     public function restore_attendance($session_id = 0)
3069 3069
     {
3070
-		if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
-			$table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
-			$table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3070
+        if ($this->course->has_resources(RESOURCE_ATTENDANCE)) {
3071
+            $table_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
3072
+            $table_attendance_calendar = Database :: get_course_table(TABLE_ATTENDANCE_CALENDAR);
3073 3073
 
3074
-			$resources = $this->course->resources;
3075
-			foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3074
+            $resources = $this->course->resources;
3075
+            foreach ($resources[RESOURCE_ATTENDANCE] as $id => $obj) {
3076 3076
 
3077
-				// check resources inside html from ckeditor tool and copy correct urls into recipient course
3077
+                // check resources inside html from ckeditor tool and copy correct urls into recipient course
3078 3078
                 $obj->params['description'] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
3079 3079
                     $obj->params['description'],
3080 3080
                     $this->course->code,
@@ -3086,11 +3086,11 @@  discard block
 block discarded – undo
3086 3086
                 unset($obj->params['id']);
3087 3087
                 unset($obj->params['iid']);
3088 3088
 
3089
-				$obj->params['c_id'] = $this->destination_course_id;
3089
+                $obj->params['c_id'] = $this->destination_course_id;
3090 3090
 
3091
-				$last_id = Database::insert($table_attendance, $obj->params);
3091
+                $last_id = Database::insert($table_attendance, $obj->params);
3092 3092
 
3093
-				if (is_numeric($last_id)) {
3093
+                if (is_numeric($last_id)) {
3094 3094
 
3095 3095
                     $sql = "UPDATE $table_attendance SET id = iid WHERE iid = $last_id";
3096 3096
                     Database::query($sql);
@@ -3104,11 +3104,11 @@  discard block
 block discarded – undo
3104 3104
                     );
3105 3105
 
3106 3106
                     foreach ($obj->attendance_calendar as $attendance_calendar) {
3107
-						unset($attendance_calendar['id']);
3107
+                        unset($attendance_calendar['id']);
3108 3108
                         unset($attendance_calendar['iid']);
3109 3109
 
3110
-						$attendance_calendar['attendance_id'] = $last_id;
3111
-						$attendance_calendar['c_id'] = $this->destination_course_id;
3110
+                        $attendance_calendar['attendance_id'] = $last_id;
3111
+                        $attendance_calendar['c_id'] = $this->destination_course_id;
3112 3112
                         $attendanceCalendarId = Database::insert(
3113 3113
                             $table_attendance_calendar,
3114 3114
                             $attendance_calendar
@@ -3116,11 +3116,11 @@  discard block
 block discarded – undo
3116 3116
 
3117 3117
                         $sql = "UPDATE $table_attendance_calendar SET id = iid WHERE iid = $attendanceCalendarId";
3118 3118
                         Database::query($sql);
3119
-					}
3120
-				}
3121
-			}
3122
-		}
3123
-	}
3119
+                    }
3120
+                }
3121
+            }
3122
+        }
3123
+    }
3124 3124
 
3125 3125
     /**
3126 3126
      * Restore Works
@@ -3261,11 +3261,11 @@  discard block
 block discarded – undo
3261 3261
      */
3262 3262
     public function DBUTF8($str)
3263 3263
     {
3264
-		if (UTF8_CONVERT) {
3264
+        if (UTF8_CONVERT) {
3265 3265
             $str = utf8_encode($str);
3266 3266
         }
3267
-		return $str;
3268
-	}
3267
+        return $str;
3268
+    }
3269 3269
 
3270 3270
     /**
3271 3271
      * @param string $str
@@ -3276,8 +3276,8 @@  discard block
 block discarded – undo
3276 3276
         if (UTF8_CONVERT) {
3277 3277
             $str = utf8_encode($str);
3278 3278
         }
3279
-		return Database::escape_string($str);
3280
-	}
3279
+        return Database::escape_string($str);
3280
+    }
3281 3281
 
3282 3282
     /**
3283 3283
      * @param array $array
Please login to merge, or discard this patch.
src/Chamilo/CourseBundle/Component/CourseCopy/CourseSelectForm.php 1 patch
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class CourseSelectForm
19 19
 {
20
-	/**
21
-	 * Display the form
20
+    /**
21
+     * Display the form
22 22
      * @param array $course
23
-	 * @param array $hidden_fields Hidden fields to add to the form.
24
-	 * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
25
-	 */
26
-	public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
23
+     * @param array $hidden_fields Hidden fields to add to the form.
24
+     * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
25
+     */
26
+    public static function display_form($course, $hidden_fields = null, $avoid_serialize = false)
27 27
     {
28 28
         global $charset;
29 29
         $resource_titles[RESOURCE_GRADEBOOK] = get_lang('Gradebook');
@@ -138,47 +138,47 @@  discard block
 block discarded – undo
138 138
             }
139 139
 		</script>
140 140
 		<?php
141
-		// get destination course title
142
-		if (!empty($hidden_fields['destination_course'])) {
141
+        // get destination course title
142
+        if (!empty($hidden_fields['destination_course'])) {
143 143
             $sessionTitle = !empty($hidden_fields['destination_session']) ? ' (' . api_get_session_name($hidden_fields['destination_session']) . ')' : null;
144 144
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
145
-			echo '<h3>';
146
-			echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
147
-			echo '</h3>';
148
-		}
145
+            echo '<h3>';
146
+            echo get_lang('DestinationCourse').' : '.$course_infos['title'] . ' ('.$course_infos['code'].') '.$sessionTitle;
147
+            echo '</h3>';
148
+        }
149 149
         echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
150
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
150
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
151 151
         $icon = Display::returnIconPath('myprogress_bar.gif');
152
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
153
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
152
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="javascript: myUpload.start(\'dynamic_div\',\''.$icon.',\''.get_lang('PleaseStandBy', '').'\',\'upload_form\')">';
153
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
154 154
 
155
-		if (!empty($hidden_fields['destination_course']) &&
155
+        if (!empty($hidden_fields['destination_course']) &&
156 156
             !empty($hidden_fields['origin_course']) &&
157 157
             !empty($hidden_fields['destination_session']) &&
158 158
             !empty($hidden_fields['origin_session'])
159 159
         ) {
160
-			echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
161
-			echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
162
-			echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
163
-			echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
164
-		}
160
+            echo '<input type="hidden" name="destination_course" 	value="'.$hidden_fields['destination_course'].'"/>';
161
+            echo '<input type="hidden" name="origin_course" 		value="'.$hidden_fields['origin_course'].'"/>';
162
+            echo '<input type="hidden" name="destination_session" 	value="'.$hidden_fields['destination_session'].'"/>';
163
+            echo '<input type="hidden" name="origin_session" 		value="'.$hidden_fields['origin_session'].'"/>';
164
+        }
165 165
 
166
-		$element_count = 0;
166
+        $element_count = 0;
167 167
         $forum_categories = array();
168 168
         $forums = array();
169 169
         $forum_topics = array();
170 170
 
171 171
         echo '<p>';
172
-		echo get_lang('SelectResources');
173
-		echo '</p>';
172
+        echo get_lang('SelectResources');
173
+        echo '</p>';
174 174
 
175 175
         Display::display_normal_message(get_lang('DontForgetToSelectTheMediaFilesIfYourResourceNeedIt'));
176 176
 
177 177
         foreach ($course->resources as $type => $resources) {
178 178
             if (count($resources) > 0) {
179
-				switch ($type) {
180
-					//Resources to avoid
181
-					case RESOURCE_FORUMCATEGORY:
179
+                switch ($type) {
180
+                    //Resources to avoid
181
+                    case RESOURCE_FORUMCATEGORY:
182 182
                         foreach ($resources as $id => $resource) {
183 183
                             $forum_categories[$id] = $resource;
184 184
                         }
@@ -204,30 +204,30 @@  discard block
 block discarded – undo
204 204
                     case RESOURCE_SCORM:
205 205
                         break;
206 206
                     default:
207
-						echo '<span id="img_'.$type.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$type'".');" >&nbsp;</span>&nbsp;';
208
-						echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
209
-						echo '<div id="div_'.$type.'">';
210
-						if ($type == RESOURCE_LEARNPATH) {
211
-    						Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
212
-    						Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
213
-						}
214
-						if ($type == RESOURCE_DOCUMENT) {
207
+                        echo '<span id="img_'.$type.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$type'".');" >&nbsp;</span>&nbsp;';
208
+                        echo '<b onclick="javascript:exp('."'$type'".');" >'.$resource_titles[$type].'</b><br />';
209
+                        echo '<div id="div_'.$type.'">';
210
+                        if ($type == RESOURCE_LEARNPATH) {
211
+                            Display::display_warning_message(get_lang('ToExportLearnpathWithQuizYouHaveToSelectQuiz'));
212
+                            Display::display_warning_message(get_lang('IfYourLPsHaveAudioFilesIncludedYouShouldSelectThemFromTheDocuments'));
213
+                        }
214
+                        if ($type == RESOURCE_DOCUMENT) {
215 215
                             if (api_get_setting('show_glossary_in_documents') != 'none') {
216 216
                                 Display::display_warning_message(get_lang('ToExportDocumentsWithGlossaryYouHaveToSelectGlossary'));
217 217
                             }
218
-						}
218
+                        }
219 219
 
220
-						echo '<div class="well">';
220
+                        echo '<div class="well">';
221 221
 
222 222
                         echo '<div class="btn-group">';
223
-						echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
223
+                        echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript: setCheckbox('$type',true);\" >".get_lang('All')."</a>";
224 224
                         echo "<a class=\"btn btn-default\" href=\"javascript: void(0);\" onclick=\"javascript:setCheckbox('$type',false);\" >".get_lang('None')."</a>";
225
-						echo '</div><br />';
225
+                        echo '</div><br />';
226 226
                         echo '<ul class="list-unstyled">';
227
-						foreach ($resources as $id => $resource) {
227
+                        foreach ($resources as $id => $resource) {
228 228
                             if ($resource) {
229 229
                                 echo '<li>';
230
-								// Event obj in 1.9.x in 1.10.x the class is CalendarEvent
230
+                                // Event obj in 1.9.x in 1.10.x the class is CalendarEvent
231 231
                                 Resource::setClassType($resource);
232 232
                                 echo '<label class="checkbox">';
233 233
                                 echo '<input type="checkbox" name="resource['.$type.']['.$id.']"  id="resource['.$type.']['.$id.']" />';
@@ -235,15 +235,15 @@  discard block
 block discarded – undo
235 235
                                 echo '</label>';
236 236
                                 echo '</li>';
237 237
                             }
238
-						}
238
+                        }
239 239
                         echo '</ul>';
240
-						echo '</div>';
241
-						echo '</div>';
242
-						echo '<script language="javascript">exp('."'$type'".')</script>';
243
-						$element_count++;
240
+                        echo '</div>';
241
+                        echo '</div>';
242
+                        echo '<script language="javascript">exp('."'$type'".')</script>';
243
+                        $element_count++;
244 244
                 }
245
-			}
246
-		}
245
+            }
246
+        }
247 247
 
248 248
         //Fixes forum order
249 249
         if (!empty($forum_categories)) {
@@ -298,65 +298,65 @@  discard block
 block discarded – undo
298 298
             echo '<script language="javascript">exp('."'$type'".')</script>';
299 299
         }
300 300
 
301
-		if ($avoid_serialize) {
302
-			/*Documents are avoided due the huge amount of memory that the serialize php function "eats"
301
+        if ($avoid_serialize) {
302
+            /*Documents are avoided due the huge amount of memory that the serialize php function "eats"
303 303
 			(when there are directories with hundred/thousand of files) */
304
-			// this is a known issue of serialize
305
-			$course->resources['document']= null;
306
-		}
304
+            // this is a known issue of serialize
305
+            $course->resources['document']= null;
306
+        }
307 307
 
308
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
308
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
309 309
 
310
-		if (is_array($hidden_fields)) {
311
-			foreach ($hidden_fields as $key => $value) {
312
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
313
-			}
314
-		}
310
+        if (is_array($hidden_fields)) {
311
+            foreach ($hidden_fields as $key => $value) {
312
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
313
+            }
314
+        }
315 315
 
316 316
         $recycleOption = isset($_POST['recycle_option']) ? true : false;
317 317
 
318
-		if (empty($element_count)) {
319
-		    Display::display_warning_message(get_lang('NoDataAvailable'));
320
-		} else {
321
-    		if (!empty($hidden_fields['destination_session'])) {
322
-    			echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
318
+        if (empty($element_count)) {
319
+            Display::display_warning_message(get_lang('NoDataAvailable'));
320
+        } else {
321
+            if (!empty($hidden_fields['destination_session'])) {
322
+                echo '<br /><button class="save" type="submit" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES, $charset))."'".')) return false;" >'.
323 323
                     get_lang('Ok').'</button>';
324
-    		} else {
324
+            } else {
325 325
                 if ($recycleOption) {
326 326
                     echo '<br /><button class="save" type="submit">'.
327 327
                         get_lang('Ok').'</button>';
328 328
                 } else {
329
-    			    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
329
+                    echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.
330 330
                     get_lang('Ok').'</button>';
331 331
                 }
332
-    		}
333
-		}
332
+            }
333
+        }
334 334
 
335
-		CourseSelectForm::display_hidden_quiz_questions($course);
336
-		CourseSelectForm::display_hidden_scorm_directories($course);
337
-		echo '</form>';
338
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
339
-	}
335
+        CourseSelectForm::display_hidden_quiz_questions($course);
336
+        CourseSelectForm::display_hidden_scorm_directories($course);
337
+        echo '</form>';
338
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
339
+    }
340 340
 
341 341
     /**
342 342
      * @param $course
343 343
      */
344 344
     public static function display_hidden_quiz_questions($course)
345 345
     {
346
-		if(is_array($course->resources)){
347
-			foreach ($course->resources as $type => $resources) {
348
-				if (count($resources) > 0) {
349
-					switch ($type) {
350
-						case RESOURCE_QUIZQUESTION:
351
-							foreach ($resources as $id => $resource) {
352
-								echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
353
-							}
354
-							break;
355
-					}
356
-				}
357
-			}
358
-		}
359
-	}
346
+        if(is_array($course->resources)){
347
+            foreach ($course->resources as $type => $resources) {
348
+                if (count($resources) > 0) {
349
+                    switch ($type) {
350
+                        case RESOURCE_QUIZQUESTION:
351
+                            foreach ($resources as $id => $resource) {
352
+                                echo '<input type="hidden" name="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" id="resource['.RESOURCE_QUIZQUESTION.']['.$id.']" value="On" />';
353
+                            }
354
+                            break;
355
+                    }
356
+                }
357
+            }
358
+        }
359
+    }
360 360
 
361 361
     /**
362 362
      * @param $course
@@ -364,30 +364,30 @@  discard block
 block discarded – undo
364 364
     public static function display_hidden_scorm_directories($course)
365 365
     {
366 366
         if (is_array($course->resources)){
367
-			foreach ($course->resources as $type => $resources) {
368
-				if (count($resources) > 0) {
369
-					switch($type) {
370
-						case RESOURCE_SCORM:
371
-							foreach ($resources as $id => $resource) {
372
-								echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
373
-							}
374
-							break;
375
-					}
376
-				}
377
-			}
378
-		}
379
-	}
367
+            foreach ($course->resources as $type => $resources) {
368
+                if (count($resources) > 0) {
369
+                    switch($type) {
370
+                        case RESOURCE_SCORM:
371
+                            foreach ($resources as $id => $resource) {
372
+                                echo '<input type="hidden" name="resource['.RESOURCE_SCORM.']['.$id.']" id="resource['.RESOURCE_SCORM.']['.$id.']" value="On" />';
373
+                            }
374
+                            break;
375
+                    }
376
+                }
377
+            }
378
+        }
379
+    }
380 380
 
381
-	/**
382
-	 * Get the posted course
383
-	 * @param string $from who calls the function?
381
+    /**
382
+     * Get the posted course
383
+     * @param string $from who calls the function?
384 384
      * It can be copy_course, create_backup, import_backup or recycle_course
385 385
      * @param int $session_id
386 386
      * @param string $course_code
387
-	 * @return course The course-object with all resources selected by the user
388
-	 * in the form given by display_form(...)
389
-	 */
390
-	public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
387
+     * @return course The course-object with all resources selected by the user
388
+     * in the form given by display_form(...)
389
+     */
390
+    public static function get_posted_course($from = '', $session_id = 0, $course_code = '')
391 391
     {
392 392
         $course = null;
393 393
 
@@ -397,30 +397,30 @@  discard block
 block discarded – undo
397 397
             return false;
398 398
         }
399 399
 
400
-		// Create the resource DOCUMENT objects
401
-		// Loading the results from the checkboxes of ethe javascript
402
-		$resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
400
+        // Create the resource DOCUMENT objects
401
+        // Loading the results from the checkboxes of ethe javascript
402
+        $resource = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
403 403
 
404
-		$course_info = api_get_course_info($course_code);
405
-		$table_doc = Database::get_course_table(TABLE_DOCUMENT);
406
-		$table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
407
-		$course_id = $course_info['real_id'];
404
+        $course_info = api_get_course_info($course_code);
405
+        $table_doc = Database::get_course_table(TABLE_DOCUMENT);
406
+        $table_prop = Database::get_course_table(TABLE_ITEM_PROPERTY);
407
+        $course_id = $course_info['real_id'];
408 408
 
409
-		/* Searching the documents resource that have been set to null because
409
+        /* Searching the documents resource that have been set to null because
410 410
         $avoid_serialize is true in the display_form() function*/
411
-		if ($from === 'copy_course') {
412
-			if (is_array($resource)) {
413
-				$resource = array_keys($resource);
411
+        if ($from === 'copy_course') {
412
+            if (is_array($resource)) {
413
+                $resource = array_keys($resource);
414 414
 
415
-				foreach	($resource as $resource_item) {
415
+                foreach	($resource as $resource_item) {
416 416
 
417
-					$condition_session = '';
418
-					if (!empty($session_id)) {
419
-						$session_id = intval($session_id);
420
-						$condition_session = ' AND d.session_id ='.$session_id;
421
-					}
417
+                    $condition_session = '';
418
+                    if (!empty($session_id)) {
419
+                        $session_id = intval($session_id);
420
+                        $condition_session = ' AND d.session_id ='.$session_id;
421
+                    }
422 422
 
423
-					$sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
423
+                    $sql = 'SELECT d.id, d.path, d.comment, d.title, d.filetype, d.size
424 424
 							FROM '.$table_doc.' d, '.$table_prop.' p
425 425
 							WHERE
426 426
 							    d.c_id = '.$course_id.' AND
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
                                 p.ref = d.id AND p.visibility != 2 AND
430 430
                                 d.id = '.$resource_item.$condition_session.'
431 431
 							ORDER BY path';
432
-					$db_result = Database::query($sql);
433
-					while ($obj = Database::fetch_object($db_result)) {
432
+                    $db_result = Database::query($sql);
433
+                    while ($obj = Database::fetch_object($db_result)) {
434 434
                         $doc = new Document(
435 435
                             $obj->id,
436 436
                             $obj->path,
@@ -454,25 +454,25 @@  discard block
 block discarded – undo
454 454
                             }
455 455
                             $course->resources[RESOURCE_DOCUMENT][$resource_item]->item_properties = $all_properties;
456 456
                         }
457
-					}
458
-				}
459
-			}
460
-		}
457
+                    }
458
+                }
459
+            }
460
+        }
461 461
 
462
-		if (is_array($course->resources)) {
463
-			foreach ($course->resources as $type => $resources) {
462
+        if (is_array($course->resources)) {
463
+            foreach ($course->resources as $type => $resources) {
464 464
 
465
-				switch ($type) {
466
-					case RESOURCE_SURVEYQUESTION:
467
-						foreach($resources as $id => $obj) {
468
-						    if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
465
+                switch ($type) {
466
+                    case RESOURCE_SURVEYQUESTION:
467
+                        foreach($resources as $id => $obj) {
468
+                            if (isset($_POST['resource'][RESOURCE_SURVEY]) &&
469 469
                                 is_array($_POST['resource'][RESOURCE_SURVEY]) &&
470 470
                                 !in_array($obj->survey_id, array_keys($_POST['resource'][RESOURCE_SURVEY]))
471 471
                             ) {
472
-								unset($course->resources[$type][$id]);
473
-							}
474
-						}
475
-						break;
472
+                                unset($course->resources[$type][$id]);
473
+                            }
474
+                        }
475
+                        break;
476 476
                     case RESOURCE_FORUMTOPIC:
477 477
                     case RESOURCE_FORUMPOST:
478 478
                        //Add post from topic
@@ -524,63 +524,63 @@  discard block
 block discarded – undo
524 524
                                 }
525 525
                             }
526 526
                         }
527
-					case RESOURCE_LINKCATEGORY:
528
-					case RESOURCE_FORUMCATEGORY:
529
-					case RESOURCE_QUIZQUESTION:
530
-					case RESOURCE_DOCUMENT:
531
-						// Mark folders to import which are not selected by the user to import,
532
-						// but in which a document was selected.
533
-						$documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
534
-						if (!empty($resources) && is_array($resources))
535
-							foreach ($resources as $id => $obj) {
536
-								if (isset($obj->file_type) && $obj->file_type == 'folder' &&
527
+                    case RESOURCE_LINKCATEGORY:
528
+                    case RESOURCE_FORUMCATEGORY:
529
+                    case RESOURCE_QUIZQUESTION:
530
+                    case RESOURCE_DOCUMENT:
531
+                        // Mark folders to import which are not selected by the user to import,
532
+                        // but in which a document was selected.
533
+                        $documents = isset($_POST['resource'][RESOURCE_DOCUMENT]) ? $_POST['resource'][RESOURCE_DOCUMENT] : null;
534
+                        if (!empty($resources) && is_array($resources))
535
+                            foreach ($resources as $id => $obj) {
536
+                                if (isset($obj->file_type) && $obj->file_type == 'folder' &&
537 537
                                     !isset($_POST['resource'][RESOURCE_DOCUMENT][$id]) &&
538 538
                                     is_array($documents)
539 539
                                 ) {
540
-									foreach ($documents as $id_to_check => $post_value) {
541
-										$obj_to_check = $resources[$id_to_check];
542
-										$shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
543
-										if ($id_to_check != $id && $obj->path == $shared_path_part) {
544
-											$_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
545
-											break;
546
-										}
547
-									}
548
-								}
549
-							}
550
-					default :
551
-						if (!empty($resources) && is_array($resources)) {
552
-							foreach ($resources as $id => $obj) {
553
-								$resource_is_used_elsewhere = $course->is_linked_resource($obj);
554
-								// check if document is in a quiz (audio/video)
555
-								if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
556
-									foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
540
+                                    foreach ($documents as $id_to_check => $post_value) {
541
+                                        $obj_to_check = $resources[$id_to_check];
542
+                                        $shared_path_part = substr($obj_to_check->path,0,strlen($obj->path));
543
+                                        if ($id_to_check != $id && $obj->path == $shared_path_part) {
544
+                                            $_POST['resource'][RESOURCE_DOCUMENT][$id] = 1;
545
+                                            break;
546
+                                        }
547
+                                    }
548
+                                }
549
+                            }
550
+                    default :
551
+                        if (!empty($resources) && is_array($resources)) {
552
+                            foreach ($resources as $id => $obj) {
553
+                                $resource_is_used_elsewhere = $course->is_linked_resource($obj);
554
+                                // check if document is in a quiz (audio/video)
555
+                                if ($type == RESOURCE_DOCUMENT && $course->has_resources(RESOURCE_QUIZ)) {
556
+                                    foreach($course->resources[RESOURCE_QUIZ] as $quiz) {
557 557
                                         $quiz = $quiz->obj;
558
-										if (isset($quiz->media) && $quiz->media == $id) {
559
-											$resource_is_used_elsewhere = true;
560
-										}
561
-									}
562
-								}
563
-								if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
564
-									unset($course->resources[$type][$id]);
565
-								}
566
-							}
567
-						}
568
-				}
569
-			}
570
-		}
558
+                                        if (isset($quiz->media) && $quiz->media == $id) {
559
+                                            $resource_is_used_elsewhere = true;
560
+                                        }
561
+                                    }
562
+                                }
563
+                                if (!isset($_POST['resource'][$type][$id]) && !$resource_is_used_elsewhere) {
564
+                                    unset($course->resources[$type][$id]);
565
+                                }
566
+                            }
567
+                        }
568
+                }
569
+            }
570
+        }
571 571
 
572
-		return $course;
573
-	}
572
+        return $course;
573
+    }
574 574
 
575
-	/**
576
-	 * Display the form session export
575
+    /**
576
+     * Display the form session export
577 577
      * @param array $list_course
578
-	 * @param array $hidden_fields Hidden fields to add to the form.
578
+     * @param array $hidden_fields Hidden fields to add to the form.
579 579
      * @param boolean $avoid_serialize the document array will be serialize. This is used in the course_copy.php file
580
-	 */
581
-	 public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
582
-     {
583
-         ?>
580
+     */
581
+        public static function display_form_session_export($list_course, $hidden_fields = null, $avoid_serialize = false)
582
+        {
583
+            ?>
584 584
 		<script>
585 585
 			function exp(item) {
586 586
 				el = document.getElementById('div_'+item);
@@ -622,65 +622,65 @@  discard block
 block discarded – undo
622 622
 		</script>
623 623
 		<?php
624 624
 
625
-		//get destination course title
626
-		if(!empty($hidden_fields['destination_course'])) {
627
-             if (!empty($hidden_fields['destination_session'])) {
628
-                 $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
629
-             } else {
630
-                 $sessionTitle = null;
631
-             }
625
+        //get destination course title
626
+        if(!empty($hidden_fields['destination_course'])) {
627
+                if (!empty($hidden_fields['destination_session'])) {
628
+                    $sessionTitle = ' (' . api_get_session_name($hidden_fields['destination_session']) . ')';
629
+                } else {
630
+                    $sessionTitle = null;
631
+                }
632 632
             $course_infos = CourseManager::get_course_information($hidden_fields['destination_course']);
633
-			echo '<h3>';
634
-				echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
635
-			echo '</h3>';
636
-		}
633
+            echo '<h3>';
634
+                echo get_lang('DestinationCourse') . ' : ' . $course_infos['title'] . $sessionTitle;
635
+            echo '</h3>';
636
+        }
637 637
 
638
-		echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
639
-		echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
638
+        echo '<script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/javascript/upload.js" type="text/javascript"></script>';
639
+        echo '<script type="text/javascript">var myUpload = new upload(1000);</script>';
640 640
         $icon = Display::returnIconPath('progress_bar.gif');
641
-		echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
642
-		echo '<input type="hidden" name="action" value="course_select_form"/>';
643
-		foreach ($list_course as $course) {
644
-			foreach ($course->resources as $type => $resources) {
645
-				if (count($resources) > 0) {
646
-					echo '<span id="img_'.$course->code.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$course->code'".');" >&nbsp;</span>';
647
-					echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
648
-					echo '<div id="div_'.$course->code.'">';
649
-					echo '<blockquote>';
641
+        echo '<form method="post" id="upload_form" name="course_select_form" onsubmit="myUpload.start(\'dynamic_div\',\''.$icon.'\',\''.get_lang('PleaseStandBy').'\',\'upload_form\')">';
642
+        echo '<input type="hidden" name="action" value="course_select_form"/>';
643
+        foreach ($list_course as $course) {
644
+            foreach ($course->resources as $type => $resources) {
645
+                if (count($resources) > 0) {
646
+                    echo '<span id="img_'.$course->code.'" class="fa fa-minus-square-o fa-lg" onclick="javascript:exp('."'$course->code'".');" >&nbsp;</span>';
647
+                    echo '<b  onclick="javascript:exp('."'$course->code'".');" > '.$course->code.'</b><br />';
648
+                    echo '<div id="div_'.$course->code.'">';
649
+                    echo '<blockquote>';
650 650
 
651 651
                     echo '<div class="btn-group">';
652
-					echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
652
+                    echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',true);\" >".get_lang('All')."</a>";
653 653
                     echo "<a class=\"btn\" href=\"#\" onclick=\"javascript:setCheckbox('".$course->code."',false);\" >".get_lang('None')."</a>";
654
-					echo '</div><br />';
654
+                    echo '</div><br />';
655 655
 
656
-					foreach ($resources as $id => $resource) {
657
-						echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
656
+                    foreach ($resources as $id => $resource) {
657
+                        echo '<label class="checkbox" for="resource['.$course->code.']['.$id.']">';
658 658
                         echo '<input type="checkbox" name="resource['.$course->code.']['.$id.']" id="resource['.$course->code.']['.$id.']"/>';
659
-						$resource->show();
660
-						echo '</label>';
661
-					}
662
-					echo '</blockquote>';
663
-					echo '</div>';
664
-					echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
665
-				}
666
-			}
667
-		}
668
-		if ($avoid_serialize) {
669
-			//Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
670
-			// this is a known issue of serialize
671
-			$course->resources['document']= null;
672
-		}
673
-		echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
674
-		if (is_array($hidden_fields)) {
675
-			foreach ($hidden_fields as $key => $value) {
676
-				echo "\n";
677
-				echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
678
-			}
679
-		}
680
-		echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
681
-		CourseSelectForm :: display_hidden_quiz_questions($course);
682
-		CourseSelectForm :: display_hidden_scorm_directories($course);
683
-		echo '</form>';
684
-		echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
685
-	}
659
+                        $resource->show();
660
+                        echo '</label>';
661
+                    }
662
+                    echo '</blockquote>';
663
+                    echo '</div>';
664
+                    echo '<script type="text/javascript">exp('."'$course->code'".')</script>';
665
+                }
666
+            }
667
+        }
668
+        if ($avoid_serialize) {
669
+            //Documents are avoided due the huge amount of memory that the serialize php function "eats" (when there are directories with hundred/thousand of files)
670
+            // this is a known issue of serialize
671
+            $course->resources['document']= null;
672
+        }
673
+        echo '<input type="hidden" name="course" value="'.base64_encode(Course::serialize($course)).'"/>';
674
+        if (is_array($hidden_fields)) {
675
+            foreach ($hidden_fields as $key => $value) {
676
+                echo "\n";
677
+                echo '<input type="hidden" name="'.$key.'" value="'.$value.'"/>';
678
+            }
679
+        }
680
+        echo '<br /><button class="save" type="submit" onclick="checkLearnPath(\''.addslashes(get_lang('DocumentsWillBeAddedToo')).'\')">'.get_lang('Ok').'</button>';
681
+        CourseSelectForm :: display_hidden_quiz_questions($course);
682
+        CourseSelectForm :: display_hidden_scorm_directories($course);
683
+        echo '</form>';
684
+        echo '<div id="dynamic_div" style="display:block;margin-left:40%;margin-top:10px;height:50px;"></div>';
685
+    }
686 686
 }
Please login to merge, or discard this patch.
main/exercise/fill_blanks.class.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -726,29 +726,29 @@  discard block
 block discarded – undo
726 726
     }
727 727
 
728 728
     /**
729
-    * Return an array of student state answers for fill the blank questions
730
-    * for each students that answered the question
731
-    * -2  : didn't answer
732
-    * -1  : student answer is wrong
733
-    *  0  : student answer is correct
734
-    * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
735
-    *
736
-    * @param integer $testId
737
-    * @param integer $questionId
738
-    * @param $studentsIdList
739
-    * @param string $startDate
740
-    * @param string $endDate
741
-    * @param bool $useLastAnswerredAttempt
742
-    * @return array
743
-    * (
744
-    *     [student_id] => Array
745
-    *         (
746
-    *             [first fill the blank for question] => -1
747
-    *             [second fill the blank for question] => 2
748
-    *             [third fill the blank for question] => -1
749
-    *         )
750
-    * )
751
-    */
729
+     * Return an array of student state answers for fill the blank questions
730
+     * for each students that answered the question
731
+     * -2  : didn't answer
732
+     * -1  : student answer is wrong
733
+     *  0  : student answer is correct
734
+     * >0  : for fill the blank question with choice menu, is the index of the student answer (right answer indice is 0)
735
+     *
736
+     * @param integer $testId
737
+     * @param integer $questionId
738
+     * @param $studentsIdList
739
+     * @param string $startDate
740
+     * @param string $endDate
741
+     * @param bool $useLastAnswerredAttempt
742
+     * @return array
743
+     * (
744
+     *     [student_id] => Array
745
+     *         (
746
+     *             [first fill the blank for question] => -1
747
+     *             [second fill the blank for question] => 2
748
+     *             [third fill the blank for question] => -1
749
+     *         )
750
+     * )
751
+     */
752 752
     public static function getFillTheBlankTabResult(
753 753
         $testId,
754 754
         $questionId,
@@ -757,17 +757,17 @@  discard block
 block discarded – undo
757 757
         $endDate,
758 758
         $useLastAnswerredAttempt = true
759 759
     ) {
760
-       $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
761
-       $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
762
-       $courseId = api_get_course_int_id();
760
+        $tblTrackEAttempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
761
+        $tblTrackEExercise = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
762
+        $courseId = api_get_course_int_id();
763 763
 
764 764
 
765
-       // request to have all the answers of student for this question
766
-       // student may have doing it several time
767
-       // student may have not answered the bracket id, in this case, is result of the answer is empty
765
+        // request to have all the answers of student for this question
766
+        // student may have doing it several time
767
+        // student may have not answered the bracket id, in this case, is result of the answer is empty
768 768
 
769
-       // we got the less recent attempt first
770
-       $sql = '
769
+        // we got the less recent attempt first
770
+        $sql = '
771 771
            SELECT * FROM '.$tblTrackEAttempt.' tea
772 772
            LEFT JOIN '.$tblTrackEExercise.' tee
773 773
            ON tee.exe_id = tea.exe_id
@@ -782,51 +782,51 @@  discard block
 block discarded – undo
782 782
            ORDER BY user_id, tea.exe_id;
783 783
        ';
784 784
 
785
-       $res = Database::query($sql);
786
-       $tabUserResult = array();
787
-       $bracketNumber = 0;
788
-       // foreach attempts for all students starting with his older attempt
789
-       while ($data = Database::fetch_array($res)) {
790
-           $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
785
+        $res = Database::query($sql);
786
+        $tabUserResult = array();
787
+        $bracketNumber = 0;
788
+        // foreach attempts for all students starting with his older attempt
789
+        while ($data = Database::fetch_array($res)) {
790
+            $tabAnswer = FillBlanks::getAnswerInfo($data['answer'], true);
791 791
 
792
-           // for each bracket to find in this question
793
-           foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
792
+            // for each bracket to find in this question
793
+            foreach ($tabAnswer['studentanswer'] as $bracketNumber => $studentAnswer) {
794 794
 
795
-               if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
796
-                   // student has answered this bracket, cool
797
-                   switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
798
-                       case self::FILL_THE_BLANK_MENU :
795
+                if ($tabAnswer['studentanswer'][$bracketNumber] != '') {
796
+                    // student has answered this bracket, cool
797
+                    switch (FillBlanks::getFillTheBlankAnswerType($tabAnswer['tabwords'][$bracketNumber])) {
798
+                        case self::FILL_THE_BLANK_MENU :
799 799
                            // get the indice of the choosen answer in the menu
800 800
                            // we know that the right answer is the first entry of the menu, ie 0
801 801
                            // (remember, menu entries are shuffled when taking the test)
802 802
                            $tabUserResult[$data['user_id']][$bracketNumber] = FillBlanks::getFillTheBlankMenuAnswerNum(
803
-                               $tabAnswer['tabwords'][$bracketNumber],
804
-                               $tabAnswer['studentanswer'][$bracketNumber]
805
-                           );
806
-                           break;
807
-                       default :
803
+                                $tabAnswer['tabwords'][$bracketNumber],
804
+                                $tabAnswer['studentanswer'][$bracketNumber]
805
+                            );
806
+                            break;
807
+                        default :
808 808
                            if (FillBlanks::isGoodStudentAnswer($tabAnswer['studentanswer'][$bracketNumber], $tabAnswer['tabwords'][$bracketNumber])) {
809
-                               $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
810
-                           } else {
811
-                               $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
812
-                           }
813
-                   }
814
-               } else {
815
-                   // student didn't answer this bracket
816
-                   if ($useLastAnswerredAttempt) {
817
-                       // if we take into account the last answered attempt
818
-                       if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
819
-                           $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
820
-                       }
821
-                   } else {
822
-                       // we take the last attempt, even if the student answer the question before
823
-                       $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
824
-                   }
825
-               }
826
-           }
827
-       }
828
-
829
-       return $tabUserResult;
809
+                                $tabUserResult[$data['user_id']][$bracketNumber] = 0;   //  right answer
810
+                            } else {
811
+                                $tabUserResult[$data['user_id']][$bracketNumber] = -1;  // wrong answer
812
+                            }
813
+                    }
814
+                } else {
815
+                    // student didn't answer this bracket
816
+                    if ($useLastAnswerredAttempt) {
817
+                        // if we take into account the last answered attempt
818
+                        if (!isset($tabUserResult[$data['user_id']][$bracketNumber])) {
819
+                            $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
820
+                        }
821
+                    } else {
822
+                        // we take the last attempt, even if the student answer the question before
823
+                        $tabUserResult[$data['user_id']][$bracketNumber] = -2;      // not answered
824
+                    }
825
+                }
826
+            }
827
+        }
828
+
829
+        return $tabUserResult;
830 830
     }
831 831
 
832 832
     /**
Please login to merge, or discard this patch.
main/resourcelinker/resourcelinker.php 1 patch
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -79,81 +79,81 @@  discard block
 block discarded – undo
79 79
 */
80 80
 if ($from_learnpath == 'yes')
81 81
 {
82
-	//start from clear every time in LearnPath Builder
83
-	$_SESSION['addedresource'] = null;
84
-	$_SESSION['addedresourceid'] = null;
85
-	$_SESSION['addedresourceassigned'] = null;
86
-	unset ($_SESSION['addedresource']);
87
-	unset ($_SESSION['addedresourceid']);
88
-	unset ($_SESSION['addedresourceassigned']);
82
+    //start from clear every time in LearnPath Builder
83
+    $_SESSION['addedresource'] = null;
84
+    $_SESSION['addedresourceid'] = null;
85
+    $_SESSION['addedresourceassigned'] = null;
86
+    unset ($_SESSION['addedresource']);
87
+    unset ($_SESSION['addedresourceid']);
88
+    unset ($_SESSION['addedresourceassigned']);
89 89
 }
90 90
 
91 91
 // Process a new chapter?
92 92
 if (!empty ($_POST['add_dir']) && !empty ($_POST['title']))
93 93
 {
94
-	$title = $_POST['title'];
95
-	$description = '';
96
-	if (!empty ($_POST['description']))
97
-	{
98
-		$description = $_POST['description'];
99
-	}
100
-
101
-	// get max display_order so far in this parent chapter
102
-	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
103
-	$res = Database::query($sql);
104
-	$row = Database::fetch_array($res);
105
-	$max_temp = $row[0];
106
-
107
-	$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
108
-	$res = Database::query($sql);
109
-	$row = Database::fetch_array($res);
110
-	$max_temp2 = $row[0];
111
-	if ($max_temp2 > $max_temp)
112
-	{
113
-		$order = $max_temp2 +1;
114
-	}
115
-	else
116
-	{
117
-		$order = $max_temp +1;
118
-	}
119
-
120
-	$sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
121
-	$res = Database::query($sql);
122
-	if ($res !== false)
123
-	{
124
-		$title = '';
125
-		$description = '';
126
-	}
94
+    $title = $_POST['title'];
95
+    $description = '';
96
+    if (!empty ($_POST['description']))
97
+    {
98
+        $description = $_POST['description'];
99
+    }
100
+
101
+    // get max display_order so far in this parent chapter
102
+    $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE learnpath_id = $learnpath_id "." AND parent_chapter_id = $chapter_id";
103
+    $res = Database::query($sql);
104
+    $row = Database::fetch_array($res);
105
+    $max_temp = $row[0];
106
+
107
+    $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE "." chapter_id = $chapter_id";
108
+    $res = Database::query($sql);
109
+    $row = Database::fetch_array($res);
110
+    $max_temp2 = $row[0];
111
+    if ($max_temp2 > $max_temp)
112
+    {
113
+        $order = $max_temp2 +1;
114
+    }
115
+    else
116
+    {
117
+        $order = $max_temp +1;
118
+    }
119
+
120
+    $sql = "INSERT INTO $tbl_learnpath_chapter "."(learnpath_id,chapter_name,chapter_description,parent_chapter_id,display_order) "." VALUES "."($learnpath_id, '$title', '$description', $chapter_id, $order )";
121
+    $res = Database::query($sql);
122
+    if ($res !== false)
123
+    {
124
+        $title = '';
125
+        $description = '';
126
+    }
127 127
 }
128 128
 
129 129
 // This if when a external link is submitted
130 130
 if (!empty ($_POST['external_link_submit']))
131 131
 {
132
-	$add = true;
133
-	if ($add_2_links != "niet toevoegen")
134
-	{
135
-		// add external link to the links table.
136
-		$pos = strpos($external_link, 'ttp:');
137
-		if ($pos == '')
138
-		{
139
-			$external_link = 'http://'.$external_link;
140
-		}
141
-
142
-		$sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
143
-		$result = Database::query($sql);
144
-		$addedresource[] = "Link";
145
-		$addedresourceid[] = Database::insert_id();
146
-		$_SESSION['addedresource'] = $addedresource;
147
-		$_SESSION['addedresourceid'] = $addedresourceid;
148
-	}
149
-	else
150
-	{
151
-		// do not add external link to the links table
152
-		$addedresource[] = "Externallink";
153
-		$addedresourceid[] = $external_link;
154
-		$_SESSION['addedresource'] = $addedresource;
155
-		$_SESSION['addedresourceid'] = $addedresourceid;
156
-	}
132
+    $add = true;
133
+    if ($add_2_links != "niet toevoegen")
134
+    {
135
+        // add external link to the links table.
136
+        $pos = strpos($external_link, 'ttp:');
137
+        if ($pos == '')
138
+        {
139
+            $external_link = 'http://'.$external_link;
140
+        }
141
+
142
+        $sql = "INSERT INTO $link_table (url, title, category_id) VALUES ('$external_link','$external_link','$add_2_links')";
143
+        $result = Database::query($sql);
144
+        $addedresource[] = "Link";
145
+        $addedresourceid[] = Database::insert_id();
146
+        $_SESSION['addedresource'] = $addedresource;
147
+        $_SESSION['addedresourceid'] = $addedresourceid;
148
+    }
149
+    else
150
+    {
151
+        // do not add external link to the links table
152
+        $addedresource[] = "Externallink";
153
+        $addedresourceid[] = $external_link;
154
+        $_SESSION['addedresource'] = $addedresource;
155
+        $_SESSION['addedresourceid'] = $addedresourceid;
156
+    }
157 157
 }
158 158
 
159 159
 // loading the session variables into local array
@@ -163,107 +163,107 @@  discard block
 block discarded – undo
163 163
 // This is when a resource was added to the session
164 164
 if ($add)
165 165
 {
166
-	// adding the new variable to the local array
167
-	if (empty ($_POST['external_link_submit']))
168
-	{
169
-		//that case is already arranged, see upwards
170
-		$addedresource[] = $content;
171
-		$addedresourceid[] = $add;
172
-	}
173
-	$addedresourceassigned[] = 0;
174
-
175
-	// loading the local array into the session variable
176
-	$_SESSION['addedresource'] = $addedresource;
177
-	$_SESSION['addedresourceid'] = $addedresourceid;
166
+    // adding the new variable to the local array
167
+    if (empty ($_POST['external_link_submit']))
168
+    {
169
+        //that case is already arranged, see upwards
170
+        $addedresource[] = $content;
171
+        $addedresourceid[] = $add;
172
+    }
173
+    $addedresourceassigned[] = 0;
174
+
175
+    // loading the local array into the session variable
176
+    $_SESSION['addedresource'] = $addedresource;
177
+    $_SESSION['addedresourceid'] = $addedresourceid;
178
+
179
+    //---------------------------------------
180
+    //we assign to chapters immediately !
181
+    //---------------------------------------
182
+    $resource_added = false;
183
+    if ($from_learnpath == 'yes')
184
+    {
185
+        $i = 0;
186
+        //calculating the last order of the items of this chapter
187
+        $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
188
+        $result = Database::query($sql);
189
+        if(Database::num_rows($result)==0){
190
+            $lastorder_item = 0;
191
+        }else{
192
+            $row = Database::fetch_array($result);
193
+            $lastorder_item = ($row[0]);
194
+        }
195
+        $sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
196
+        $result = Database::query($sql);
197
+        if(Database::num_rows($result)==0){
198
+            $lastorder_chapter = 0;
199
+        }else{
200
+            $row = Database::fetch_array($result);
201
+            $lastorder_chapter = ($row[0]);
202
+        }
203
+        $lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
178 204
 
179
-	//---------------------------------------
180
-	//we assign to chapters immediately !
181
-	//---------------------------------------
182
-	$resource_added = false;
183
-	if ($from_learnpath == 'yes')
184
-	{
185
-		$i = 0;
186
-		//calculating the last order of the items of this chapter
187
-		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_item WHERE chapter_id=$chapter_id";
188
-		$result = Database::query($sql);
189
-		if(Database::num_rows($result)==0){
190
-			$lastorder_item = 0;
191
-		}else{
192
-			$row = Database::fetch_array($result);
193
-			$lastorder_item = ($row[0]);
194
-		}
195
-		$sql = "SELECT MAX(display_order) FROM $tbl_learnpath_chapter WHERE parent_chapter_id=$chapter_id";
196
-		$result = Database::query($sql);
197
-		if(Database::num_rows($result)==0){
198
-			$lastorder_chapter = 0;
199
-		}else{
200
-			$row = Database::fetch_array($result);
201
-			$lastorder_chapter = ($row[0]);
202
-		}
203
-		$lastorder = ($lastorder_chapter>$lastorder_item?$lastorder_chapter+1:$lastorder_item+1);
204
-
205
-		foreach ($addedresource as $addedresource_item)
206
-		{
207
-			// in the case we added a chapter, add this into the chapters list with the correct parent_id
208
-			if ($addedresource_item == "Chap")
209
-			{
210
-				$sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
211
-				Database::query($sql);
212
-			}
213
-
214
-			if (!$addedresourceassigned[$i])
215
-			{
216
-				//not to assign it twice
217
-				if ($addedresource_item == "Ass")
218
-				{
219
-					$addedresource_item = "Assignments";
220
-				}
221
-				if ($addedresource_item == "Drop")
222
-				{
223
-					$addedresource_item = "Dropbox";
224
-				}
225
-				if ($addedresource_item == "Intro")
226
-				{
227
-					$addedresource_item = "Introduction_text";
228
-				}
229
-				if ($addedresource_item == "Course_desc")
230
-				{
231
-					$addedresource_item = "Course_description";
232
-				}
233
-				if ($addedresource_item == "Group")
234
-				{
235
-					$addedresource_item = "Groups";
236
-				}
237
-				if ($addedresource_item == "User")
238
-				{
239
-					$addedresource_item = "Users";
240
-				}
241
-				if ($target == '')
242
-				{
243
-					$target = '_self';
244
-				}
245
-				if ($addedresource_item == 'Link')
246
-				{
247
-					$addedresource_item .= ' '.$target;
248
-				}
249
-				$sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
250
-				$result = Database::query($sql);
251
-				$addedresourceassigned[$i] = 1;
252
-				$resource_added = true;
253
-			}
254
-			$i ++;
255
-			$lastorder ++;
256
-		}
257
-		//$_SESSION['addedresource']=null;
258
-		//$_SESSION['addedresourceid']=null;
259
-		// cleaning up the session once again
260
-		$_SESSION['addedresource'] = null;
261
-   		$_SESSION['addedresourceid'] = null;
262
-   		$_SESSION['addedresourceassigned'] = null;
263
-   		unset ($_SESSION['addedresource']);
264
-   		unset ($_SESSION['addedresourceid']);
265
-   		unset ($_SESSION['addedresourceassigned']);
266
-	}
205
+        foreach ($addedresource as $addedresource_item)
206
+        {
207
+            // in the case we added a chapter, add this into the chapters list with the correct parent_id
208
+            if ($addedresource_item == "Chap")
209
+            {
210
+                $sql = "INSERT INTO $tbl_learnpath_chapter ("."'learnpath_id','chapter_name','chapter_description','parent_chapter_id','display_order'".") VALUES (".$learnpath_id.",'".$learnpath_chapter_name."','".$learnpath_chapter_description."',".$chapter_id.",".$lastorder.")";
211
+                Database::query($sql);
212
+            }
213
+
214
+            if (!$addedresourceassigned[$i])
215
+            {
216
+                //not to assign it twice
217
+                if ($addedresource_item == "Ass")
218
+                {
219
+                    $addedresource_item = "Assignments";
220
+                }
221
+                if ($addedresource_item == "Drop")
222
+                {
223
+                    $addedresource_item = "Dropbox";
224
+                }
225
+                if ($addedresource_item == "Intro")
226
+                {
227
+                    $addedresource_item = "Introduction_text";
228
+                }
229
+                if ($addedresource_item == "Course_desc")
230
+                {
231
+                    $addedresource_item = "Course_description";
232
+                }
233
+                if ($addedresource_item == "Group")
234
+                {
235
+                    $addedresource_item = "Groups";
236
+                }
237
+                if ($addedresource_item == "User")
238
+                {
239
+                    $addedresource_item = "Users";
240
+                }
241
+                if ($target == '')
242
+                {
243
+                    $target = '_self';
244
+                }
245
+                if ($addedresource_item == 'Link')
246
+                {
247
+                    $addedresource_item .= ' '.$target;
248
+                }
249
+                $sql = "INSERT INTO $tbl_learnpath_item (id, chapter_id, item_type, item_id, display_order) VALUES ( '$autoid', '$chapter_id', '$addedresource_item','$addedresourceid[$i]','".$lastorder."')";
250
+                $result = Database::query($sql);
251
+                $addedresourceassigned[$i] = 1;
252
+                $resource_added = true;
253
+            }
254
+            $i ++;
255
+            $lastorder ++;
256
+        }
257
+        //$_SESSION['addedresource']=null;
258
+        //$_SESSION['addedresourceid']=null;
259
+        // cleaning up the session once again
260
+        $_SESSION['addedresource'] = null;
261
+            $_SESSION['addedresourceid'] = null;
262
+            $_SESSION['addedresourceassigned'] = null;
263
+            unset ($_SESSION['addedresource']);
264
+            unset ($_SESSION['addedresourceid']);
265
+            unset ($_SESSION['addedresourceassigned']);
266
+    }
267 267
 }
268 268
 
269 269
 /*
@@ -278,64 +278,64 @@  discard block
 block discarded – undo
278 278
 */
279 279
 if ($_GET["source_id"])
280 280
 {
281
-	switch ($_GET["source_id"])
282
-	{
283
-		case "1" : // coming from Agenda
284
-			if ($action == "edit")
285
-			{
286
-				$url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
287
-			}
288
-			elseif ($action == "add")
289
-		{
290
-				$url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
291
-			}
292
-			else
293
-			{
294
-				$url = "../calendar/agenda.php?action=add";
295
-			}
296
-			$originaltoolname = get_lang("Agenda");
297
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
298
-			unset($_SESSION['from_learnpath']);
299
-			unset ($from_learnpath);
300
-			break;
301
-		case "2" : // coming from forum: new topic
302
-			$url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
303
-			$originaltoolname = get_lang("ForumAddNewTopic");
304
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
305
-			unset($_SESSION['from_learnpath']);
306
-			unset ($from_learnpath);
307
-			break;
308
-		case "3" : // coming from forum: edit topic
309
-			$url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
310
-			$originaltoolname = get_lang("ForumEditTopic");
311
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
312
-			unset($_SESSION['from_learnpath']);
313
-			unset ($from_learnpath);
314
-			break;
315
-		case "4" : // coming from exercises: edit topic
316
-			$url = "../exercise/admin.php?modifyAnswers=$modifyAnswers";
317
-			$originaltoolname = get_lang("ExerciseAnswers");
318
-			$breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
319
-			unset($_SESSION['from_learnpath']);
320
-			unset ($from_learnpath);
321
-			break;
322
-		case "5" : // coming from learning path
323
-			$from_learnpath = 'yes';
324
-			Session::write('from_learnpath',$from_learnpath);
325
-			break;
326
-			/*************************************** end add [email protected] *********************************/
327
-
328
-	}
329
-	// We do not come from the learning path. We store the name of the tool & url in a session.
330
-	if ($from_learnpath != 'yes')
331
-	{
332
-		if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
333
-		{
334
-			$_SESSION["origintoolurl"] = $breadcrumbelement["url"];
335
-			$_SESSION["origintoolname"] = $breadcrumbelement["name"];
336
-			$interbreadcrumb = "";
337
-		}
338
-	}
281
+    switch ($_GET["source_id"])
282
+    {
283
+        case "1" : // coming from Agenda
284
+            if ($action == "edit")
285
+            {
286
+                $url = "../calendar/agenda.php?action=edit&id=49&originalresource=$originalresource";
287
+            }
288
+            elseif ($action == "add")
289
+        {
290
+                $url = "../calendar/agenda.php?action=add&originalresource=$originalresource";
291
+            }
292
+            else
293
+            {
294
+                $url = "../calendar/agenda.php?action=add";
295
+            }
296
+            $originaltoolname = get_lang("Agenda");
297
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
298
+            unset($_SESSION['from_learnpath']);
299
+            unset ($from_learnpath);
300
+            break;
301
+        case "2" : // coming from forum: new topic
302
+            $url = "../phpbb/newtopic.php?forum=$source_forum&md5=$md5";
303
+            $originaltoolname = get_lang("ForumAddNewTopic");
304
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
305
+            unset($_SESSION['from_learnpath']);
306
+            unset ($from_learnpath);
307
+            break;
308
+        case "3" : // coming from forum: edit topic
309
+            $url = "../phpbb/editpost.php?post_id=$post_id&topic=$topic&forum=$forum&md5=$md5&originalresource=no";
310
+            $originaltoolname = get_lang("ForumEditTopic");
311
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
312
+            unset($_SESSION['from_learnpath']);
313
+            unset ($from_learnpath);
314
+            break;
315
+        case "4" : // coming from exercises: edit topic
316
+            $url = "../exercise/admin.php?modifyAnswers=$modifyAnswers";
317
+            $originaltoolname = get_lang("ExerciseAnswers");
318
+            $breadcrumbelement = array ("url" => $url, "name" => $originaltoolname);
319
+            unset($_SESSION['from_learnpath']);
320
+            unset ($from_learnpath);
321
+            break;
322
+        case "5" : // coming from learning path
323
+            $from_learnpath = 'yes';
324
+            Session::write('from_learnpath',$from_learnpath);
325
+            break;
326
+            /*************************************** end add [email protected] *********************************/
327
+
328
+    }
329
+    // We do not come from the learning path. We store the name of the tool & url in a session.
330
+    if ($from_learnpath != 'yes')
331
+    {
332
+        if (!$_SESSION["origintoolurl"] OR $_SESSION["origintoolurl"]<>$interbreadcrumb["url"])
333
+        {
334
+            $_SESSION["origintoolurl"] = $breadcrumbelement["url"];
335
+            $_SESSION["origintoolname"] = $breadcrumbelement["name"];
336
+            $interbreadcrumb = "";
337
+        }
338
+    }
339 339
 
340 340
 }
341 341
 
@@ -343,26 +343,26 @@  discard block
 block discarded – undo
343 343
 // the information from the session. Else we use the information of the learningpath itself.
344 344
 if ($from_learnpath != 'yes')
345 345
 {
346
-	$nameTools = get_lang('AddResource');
347
-	$interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
346
+    $nameTools = get_lang('AddResource');
347
+    $interbreadcrumb[] = array ("url" => $_SESSION["origintoolurl"], "name" => $_SESSION["origintoolname"]);
348 348
 }
349 349
 else
350 350
 {
351
-	$learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
351
+    $learnpath_select_query = "	SELECT * FROM $tbl_learnpath_main
352 352
 		  								WHERE learnpath_id=$learnpath_id";
353
-	$sql_result = Database::query($learnpath_select_query);
354
-	$therow = Database::fetch_array($sql_result);
353
+    $sql_result = Database::query($learnpath_select_query);
354
+    $therow = Database::fetch_array($sql_result);
355 355
 
356
-	$learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
356
+    $learnpath_chapter_query = "	SELECT * FROM $tbl_learnpath_chapter
357 357
 		  								WHERE (learnpath_id = '$learnpath_id' and id = '$chapter_id')";
358
-	$sql_result = Database::query($learnpath_chapter_query);
359
-	$therow2 = Database::fetch_array($sql_result);
358
+    $sql_result = Database::query($learnpath_chapter_query);
359
+    $therow2 = Database::fetch_array($sql_result);
360 360
 
361
-	$from_learnpath = 'yes';
362
-	$_SESSION['from_learnpath'] = $from_learnpath;
363
-	$interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
364
-	$interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
365
-	$interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");
361
+    $from_learnpath = 'yes';
362
+    $_SESSION['from_learnpath'] = $from_learnpath;
363
+    $interbreadcrumb[] = array ("url" => "../scorm/scormdocument.php", "name" => get_lang('LearningPath'));
364
+    $interbreadcrumb[] = array ("url" => "../learnpath/learnpath_handler.php?learnpath_id=$learnpath_id", "name" => "{$therow['learnpath_name']}");
365
+    $interbreadcrumb[] = array ("url" => api_get_self()."?action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no", "name" => "{$therow2['chapter_name']}");
366 366
 
367 367
 }
368 368
 
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 echo "<h3>".$nameTools;
381 381
 if ($from_learnpath == 'yes')
382 382
 {
383
-	echo get_lang("AddResource")." - {$therow2['chapter_name']}";
383
+    echo get_lang("AddResource")." - {$therow2['chapter_name']}";
384 384
 }
385 385
 echo "</h3>";
386 386
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 $result_select_active=Database::query($sql_select_active);
394 394
 while ($row=Database::fetch_array($result_select_active))
395 395
 {
396
-	$active_modules[]=$row['name'];
396
+    $active_modules[]=$row['name'];
397 397
 }
398 398
 
399 399
 
@@ -536,12 +536,12 @@  discard block
 block discarded – undo
536 536
 
537 537
 if ($from_learnpath != 'yes')
538 538
 {
539
-	echo "<tr><td>&nbsp;</td></tr>";
540
-	echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
541
-	echo count($addedresource);
542
-	echo ")</b></td></tr>";
543
-	echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
544
-	echo "</td></tr>";
539
+    echo "<tr><td>&nbsp;</td></tr>";
540
+    echo "<tr><td><b>".get_lang('ResourcesAdded')." (";
541
+    echo count($addedresource);
542
+    echo ")</b></td></tr>";
543
+    echo "<tr><td nowrap><a href=\"".api_get_self()."?showresources=true&action=$action&id=$id&learnpath_id=$learnpath_id&chapter_id=$chapter_id&source_forum=$source_forum&originalresource=no\">".get_lang('ShowDelete')."</a>";
544
+    echo "</td></tr>";
545 545
 }
546 546
 ?>
547 547
         <tr>
@@ -557,11 +557,11 @@  discard block
 block discarded – undo
557 557
 
558 558
 if ($from_learnpath != 'yes')
559 559
 {
560
-	echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
560
+    echo "<form method=\"post\" action=\"{$_SESSION['origintoolurl']}\" style=\"margin: 0px;\"><input type=\"submit\" value=\"".get_lang('Ok')."\"></form>";
561 561
 }
562 562
 else
563 563
 {
564
-	echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".'  '.get_lang('Ok').'  '."\"></form>";
564
+    echo "<form method=\"get\" action=\"../learnpath/learnpath_handler.php\" style=\"margin: 0px;\"><input type=\"hidden\" name=\"learnpath_id\" value=\"".htmlentities($learnpath_id)."\"><input type=\"submit\" value=\"".'  '.get_lang('Ok').'  '."\"></form>";
565 565
 }
566 566
 ?>
567 567
 
@@ -577,40 +577,40 @@  discard block
 block discarded – undo
577 577
 
578 578
 if ($resource_added)
579 579
 {
580
-	Display :: display_normal_message(get_lang("ResourceAdded"));
580
+    Display :: display_normal_message(get_lang("ResourceAdded"));
581 581
 }
582 582
 
583 583
 if ($from_learnpath != 'yes')
584 584
 {
585
-	echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
585
+    echo count($addedresource)." ".api_strtolower(get_lang('ResourcesAdded'))."<br/>";
586 586
 }
587 587
 //echo "<hr>";
588 588
 
589 589
 // Agenda items -->
590 590
 if ($content == "Agenda")
591 591
 {
592
-	$TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
593
-	$TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
592
+    $TABLEAGENDA 			= Database::get_course_table(TABLE_AGENDA);
593
+    $TABLE_ITEM_PROPERTY 	= Database::get_course_table(TABLE_ITEM_PROPERTY);
594 594
 
595
-	$sql="SELECT agenda.*, toolitemproperties.*
595
+    $sql="SELECT agenda.*, toolitemproperties.*
596 596
 					FROM ".$TABLEAGENDA." agenda, ".$TABLE_ITEM_PROPERTY." toolitemproperties
597 597
 					WHERE agenda.id = toolitemproperties.ref
598 598
 					AND toolitemproperties.tool='".TOOL_CALENDAR_EVENT."'
599 599
 					AND (toolitemproperties.to_group_id='0' OR toolitemproperties.to_group_id IS NULL)
600 600
 					AND toolitemproperties.visibility='1'";
601 601
 
602
-	$result = Database::query($sql);
603
-
604
-	while ($myrow = Database::fetch_array($result))
605
-	{
606
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
607
-		echo "<img src='../img/agenda.gif' alt='agenda'>";
608
-		echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
609
-		echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
610
-		echo $myrow["content"]."<br />";
611
-		showorhide_addresourcelink($content, $myrow["id"]);
612
-		echo "</td></tr></table><br />";
613
-	}
602
+    $result = Database::query($sql);
603
+
604
+    while ($myrow = Database::fetch_array($result))
605
+    {
606
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\">";
607
+        echo "<img src='../img/agenda.gif' alt='agenda'>";
608
+        echo api_convert_and_format_date($myrow["start_date"], null, date_default_timezone_get())."<br />";
609
+        echo "<b>".$myrow["title"]."</b></td></tr><tr><td>";
610
+        echo $myrow["content"]."<br />";
611
+        showorhide_addresourcelink($content, $myrow["id"]);
612
+        echo "</td></tr></table><br />";
613
+    }
614 614
 } // end if ($_GET["resource"]=="Agenda")
615 615
 
616 616
 /*
@@ -620,12 +620,12 @@  discard block
 block discarded – undo
620 620
 */
621 621
 if ($content == "chapter")
622 622
 {
623
-	echo '<table><form name="add_dir" action="'.'" method="POST">'."\n";
624
-	echo '  <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
625
-	echo '  <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
626
-	echo '  <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
627
-	echo '</form></table>'."\n";
628
-	//echo "<hr>";
623
+    echo '<table><form name="add_dir" action="'.'" method="POST">'."\n";
624
+    echo '  <tr><td>'.get_lang('Title').'</td><td><input type="text" name="title" value="'.$title.'"></input></td></tr>'."\n";
625
+    echo '  <tr><td>'.get_lang('Description').'</td><td><input type="text" name="description" value="'.$description.'"></input></td></tr>'."\n";
626
+    echo '  <tr><td></td><td><input type="submit" name="add_dir" value="'.get_lang('AddIt').'"/></td></tr>'."\n";
627
+    echo '</form></table>'."\n";
628
+    //echo "<hr>";
629 629
 }
630 630
 
631 631
 /*
@@ -640,23 +640,23 @@  discard block
 block discarded – undo
640 640
 //				b. one is a student AND the documents tool is active. Student cannot add documents if the documents tool is inactive (teacher can do this)
641 641
 if ($content == "Document" OR (empty($content) AND (api_is_allowed_to_edit() OR in_array(TOOL_DOCUMENT,$active_modules))) AND !$_GET['showresources'])
642 642
 {
643
-	// setting variables for file locations
644
-	$baseServDir = $_configuration['root_sys'];
645
-	$courseDir = $_course['path']."/document";
646
-	$baseWorkDir = $baseServDir.$courseDir;
647
-	// showing the link to move one folder up (when not in the root folder)
648
-	show_folder_up($chapter_id);
649
-	// showing the blue bar with the path in it when we are not in the root
650
-	if (get_levels($folder))
651
-	{
652
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
653
-		echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
654
-		echo $folder."</b></font></td></tr></table>";
655
-	}
656
-
657
-	// showing the documents and subfolders of the folder we are in.
658
-	show_documents($folder, $chapter_id);
659
-	//echo "<hr>";
643
+    // setting variables for file locations
644
+    $baseServDir = $_configuration['root_sys'];
645
+    $courseDir = $_course['path']."/document";
646
+    $baseWorkDir = $baseServDir.$courseDir;
647
+    // showing the link to move one folder up (when not in the root folder)
648
+    show_folder_up($chapter_id);
649
+    // showing the blue bar with the path in it when we are not in the root
650
+    if (get_levels($folder))
651
+    {
652
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#4171B5\">";
653
+        echo "<img src=\"../img/opendir.gif\" alt='directory'><font color=\"#ffffff\"><b>";
654
+        echo $folder."</b></font></td></tr></table>";
655
+    }
656
+
657
+    // showing the documents and subfolders of the folder we are in.
658
+    show_documents($folder, $chapter_id);
659
+    //echo "<hr>";
660 660
 }
661 661
 
662 662
 /*
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 */
667 667
 if ($content == "Ad_Valvas")
668 668
 {
669
-	$tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
670
-	$sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i
669
+    $tbl_announcement = Database :: get_course_table(TABLE_ANNOUNCEMENT);
670
+    $sql = "SELECT * FROM ".$tbl_announcement." a, ".$item_property_table." i
671 671
 			WHERE
672 672
 				i.tool = '".TOOL_ANNOUNCEMENT."' AND
673 673
 				a.id=i.ref AND
@@ -676,17 +676,17 @@  discard block
 block discarded – undo
676 676
 				i.to_user_id IS NULL
677 677
 			ORDER BY a.display_order ASC";
678 678
 
679
-	$result = Database::query($sql);
680
-	while ($myrow = Database::fetch_array($result))
681
-	{
682
-		echo "<table width=\"100%\"><tr><td>";
683
-		echo "<img src='../img/valves.gif' alt='advalvas'>";
684
-		echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
685
-		echo "</td></tr><tr><td>";
686
-		echo $myrow["title"]."<br />";
687
-		showorhide_addresourcelink($content, $myrow["id"]);
688
-		echo "</td></tr></table>";
689
-	}
679
+    $result = Database::query($sql);
680
+    while ($myrow = Database::fetch_array($result))
681
+    {
682
+        echo "<table width=\"100%\"><tr><td>";
683
+        echo "<img src='../img/valves.gif' alt='advalvas'>";
684
+        echo api_convert_and_format_date($myrow["end_date"], DATE_FORMAT_LONG, date_default_timezone_get());
685
+        echo "</td></tr><tr><td>";
686
+        echo $myrow["title"]."<br />";
687
+        showorhide_addresourcelink($content, $myrow["id"]);
688
+        echo "</td></tr></table>";
689
+    }
690 690
 }
691 691
 
692 692
 /*
@@ -696,75 +696,75 @@  discard block
 block discarded – undo
696 696
 */
697 697
 if ($content == "Forum")
698 698
 {
699
-	$TBL_FORUMS 		= Database::get_course_table(TABLE_FORUM);
700
-	$TBL_CATAGORIES 	= Database::get_course_table(TABLE_FORUM_CATEGORY);
701
-	$TBL_FORUMTOPICS 	= Database::get_course_table(TABLE_FORUM_POST);
702
-	$tbl_posts 			= Database::get_course_table(TABLE_FORUM_POST);
703
-	$tbl_posts_text 	= Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
704
-
705
-	echo "<table width='100%'>";
699
+    $TBL_FORUMS 		= Database::get_course_table(TABLE_FORUM);
700
+    $TBL_CATAGORIES 	= Database::get_course_table(TABLE_FORUM_CATEGORY);
701
+    $TBL_FORUMTOPICS 	= Database::get_course_table(TABLE_FORUM_POST);
702
+    $tbl_posts 			= Database::get_course_table(TABLE_FORUM_POST);
703
+    $tbl_posts_text 	= Database::get_course_table(TOOL_FORUM_POST_TEXT_TABLE);
704
+
705
+    echo "<table width='100%'>";
706
+
707
+    // displaying the categories and the forums
708
+    if (!$forum and !$thread)
709
+    {
710
+        $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
711
+        $result = Database::query($sql);
712
+        while ($myrow = Database::fetch_array($result))
713
+        {
714
+            if ($myrow["cat_title"] !== $old_cat_title)
715
+            {
716
+                echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
717
+            }
718
+            $old_cat_title = $myrow["cat_title"];
719
+            echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
720
+            showorhide_addresourcelink("Forum", $myrow["forum_id"]);
721
+            echo "</td></tr>";
722
+        }
723
+    }
724
+    //displaying all the threads of one forum
725
+    if ($forum)
726
+    {
727
+        // displaying the category title
728
+        $sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
729
+        $result = Database::query($sql);
730
+        $myrow = Database::fetch_array($result);
731
+        echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
732
+
733
+        // displaying the forum title
734
+        $sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
735
+        $result = Database::query($sql);
736
+        $myrow = Database::fetch_array($result);
737
+        echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
738
+
739
+        if (!$thread)
740
+        {
741
+            // displaying all the threads of this forum
742
+            $sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
743
+            $result = Database::query($sql);
744
+            while ($myrow = Database::fetch_array($result))
745
+            {
746
+                echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
747
+                showorhide_addresourcelink("Thread", $myrow["topic_id"]);
748
+                echo "</td></tr>";
749
+            }
750
+        }
751
+        else
752
+        {
753
+            // displaying all the replies
754
+            $sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
755
+            $result = Database::query($sql);
756
+            while ($myrow = Database::fetch_array($result))
757
+            {
758
+                echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
759
+                echo $myrow["post_text"]."</td>";
760
+                echo "<td>";
761
+                showorhide_addresourcelink("Post", $myrow["post_id"]);
762
+                echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
763
+            }
706 764
 
707
-	// displaying the categories and the forums
708
-	if (!$forum and !$thread)
709
-	{
710
-		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_CATAGORIES." categories WHERE forums.cat_id=categories.cat_id ORDER BY forums.cat_id DESC";
711
-		$result = Database::query($sql);
712
-		while ($myrow = Database::fetch_array($result))
713
-		{
714
-			if ($myrow["cat_title"] !== $old_cat_title)
715
-			{
716
-				echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
717
-			}
718
-			$old_cat_title = $myrow["cat_title"];
719
-			echo "<tr><td><img src='../img/forum.gif'><a href='".api_get_self()."?content=Forum&category=".$myrow["cat_id"]."&forum=".$myrow["forum_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["forum_name"]."</td><td>";
720
-			showorhide_addresourcelink("Forum", $myrow["forum_id"]);
721
-			echo "</td></tr>";
722
-		}
723
-	}
724
-	//displaying all the threads of one forum
725
-	if ($forum)
726
-	{
727
-		// displaying the category title
728
-		$sql = "SELECT * FROM ".$TBL_CATAGORIES." WHERE cat_id=$category";
729
-		$result = Database::query($sql);
730
-		$myrow = Database::fetch_array($result);
731
-		echo "<tr><td bgcolor='#4171B5' colspan='2'><font color='white'><b>".$myrow["cat_title"]."</b></font></td></tr>";
732
-
733
-		// displaying the forum title
734
-		$sql = "SELECT * FROM ".$TBL_FORUMS." forums, ".$TBL_FORUMTOPICS." topics WHERE forums.forum_id=topics.forum_id";
735
-		$result = Database::query($sql);
736
-		$myrow = Database::fetch_array($result);
737
-		echo "<tr><td bgcolor='#cccccc' colspan='2'><b>".$myrow["forum_name"]."</b></td></tr>";
738
-
739
-		if (!$thread)
740
-		{
741
-			// displaying all the threads of this forum
742
-			$sql = "SELECT * FROM ".$TBL_FORUMTOPICS." WHERE forum_id=$forum";
743
-			$result = Database::query($sql);
744
-			while ($myrow = Database::fetch_array($result))
745
-			{
746
-				echo "<tr><td><a href='".api_get_self()."?content=Forum&category=$category&forum=1&thread=".$myrow["topic_id"]."&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".$myrow["topic_title"]."</a>  (".$myrow["prenom"]." ".$myrow["nom"].")</td><td>";
747
-				showorhide_addresourcelink("Thread", $myrow["topic_id"]);
748
-				echo "</td></tr>";
749
-			}
750
-		}
751
-		else
752
-		{
753
-			// displaying all the replies
754
-			$sql = "SELECT * FROM ".$tbl_posts." post, ".$tbl_posts_text." post_text WHERE post_text.post_id=post.post_id and post.topic_id=$thread ORDER BY post_text.post_id ASC";
755
-			$result = Database::query($sql);
756
-			while ($myrow = Database::fetch_array($result))
757
-			{
758
-				echo "<tr><td><b>".$myrow["post_title"]."</b><br>";
759
-				echo $myrow["post_text"]."</td>";
760
-				echo "<td>";
761
-				showorhide_addresourcelink("Post", $myrow["post_id"]);
762
-				echo "</td></tr><tr><td colspan='2'><hr noshade></td></tr>";
763
-			}
764
-
765
-		}
766
-	}
767
-	echo "</table>";
765
+        }
766
+    }
767
+    echo "</table>";
768 768
 }
769 769
 
770 770
 /*
@@ -774,57 +774,57 @@  discard block
 block discarded – undo
774 774
 */
775 775
 if ($content == "Link")
776 776
 {
777
-	// including the links language file
778
-	include ("../lang/$language/link.inc.php");
779
-
780
-	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
781
-	if (($learnpath_id != '') and ($content == 'Link'))
782
-	{
783
-		echo "<form name='learnpath_link'><table>";
784
-		echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
785
-		if ($target == '_self')
786
-		{
787
-			echo "selected";
788
-		}
789
-		echo ">".get_lang('SameWindow')."</option><option value='_blank'";
790
-		if ($target == '_blank')
791
-		{
792
-			echo "selected";
793
-		}
794
-		echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
795
-	}
796
-
797
-	// showing the links that are in the root (having no category)
798
-	$sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
799
-	$result = Database::query($sql);
800
-	if (Database::num_rows($result) > 0)
801
-	{
802
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
803
-		while ($myrow = Database::fetch_array($result))
804
-		{
805
-			echo "<img src='../img/links.gif'>".$myrow["title"];
806
-			echo "<br>";
807
-			showorhide_addresourcelink($content, $myrow["id"]);
808
-			echo "<br><br>";
809
-		}
810
-	}
811
-
812
-	// showing the categories and the links in it.
813
-	$sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
814
-	$resultcategories = Database::query($sqlcategories) or die;
815
-	while ($myrow = @ Database::fetch_array($resultcategories))
816
-	{
817
-		$sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
818
-		echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
819
-		$result_links = Database::query($sql_links);
820
-		while ($myrow = Database::fetch_array($result_links))
821
-		{
822
-			echo "<img src='../img/links.gif' />".$myrow["title"];
823
-			echo "<br>";
824
-			showorhide_addresourcelink($content, $myrow["id"]);
825
-			echo "<br><br>";
826
-		}
827
-	}
777
+    // including the links language file
778
+    include ("../lang/$language/link.inc.php");
779
+
780
+    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
781
+    if (($learnpath_id != '') and ($content == 'Link'))
782
+    {
783
+        echo "<form name='learnpath_link'><table>";
784
+        echo "<tr></td><td align='left'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target' onchange='targetfunc()'><option value='_self' ";
785
+        if ($target == '_self')
786
+        {
787
+            echo "selected";
788
+        }
789
+        echo ">".get_lang('SameWindow')."</option><option value='_blank'";
790
+        if ($target == '_blank')
791
+        {
792
+            echo "selected";
793
+        }
794
+        echo ">".get_lang('NewWindow')."</option></select></td></tr></table></form>";
795
+    }
796
+
797
+    // showing the links that are in the root (having no category)
798
+    $sql = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE (l.category_id=0 or l.category_id IS NULL) AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1'";
799
+    $result = Database::query($sql);
800
+    if (Database::num_rows($result) > 0)
801
+    {
802
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".get_lang('NoCategory')."</i></td></tr></table>";
803
+        while ($myrow = Database::fetch_array($result))
804
+        {
805
+            echo "<img src='../img/links.gif'>".$myrow["title"];
806
+            echo "<br>";
807
+            showorhide_addresourcelink($content, $myrow["id"]);
808
+            echo "<br><br>";
809
+        }
810
+    }
811
+
812
+    // showing the categories and the links in it.
813
+    $sqlcategories = "SELECT * FROM ".$tbl_categories." ORDER by display_order DESC";
814
+    $resultcategories = Database::query($sqlcategories) or die;
815
+    while ($myrow = @ Database::fetch_array($resultcategories))
816
+    {
817
+        $sql_links = "SELECT * FROM ".$link_table." l, ".$item_property_table." ip WHERE l.category_id='".$myrow["id"]."' AND ip.tool = '".TOOL_LINK."' AND l.id=ip.ref AND ip.visibility='1' ORDER BY l.display_order DESC";
818
+        echo "<table width=\"100%\"><tr><td bgcolor=\"#E6E6E6\"><i>".$myrow["category_title"]."</i></td></tr></table>";
819
+        $result_links = Database::query($sql_links);
820
+        while ($myrow = Database::fetch_array($result_links))
821
+        {
822
+            echo "<img src='../img/links.gif' />".$myrow["title"];
823
+            echo "<br>";
824
+            showorhide_addresourcelink($content, $myrow["id"]);
825
+            echo "<br><br>";
826
+        }
827
+    }
828 828
 }
829 829
 
830 830
 /*
@@ -834,31 +834,31 @@  discard block
 block discarded – undo
834 834
 */
835 835
 if (($content == "Exercise") or ($content == "HotPotatoes"))
836 836
 {
837
-	$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
838
-	$result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
839
-	while ($myrow = Database::fetch_array($result))
840
-	{
841
-		echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
842
-		showorhide_addresourcelink($content, $myrow["id"]);
843
-		echo "<br><br>";
844
-	}
837
+    $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
838
+    $result = Database::query("SELECT * FROM ".$TBL_EXERCICES." WHERE active='1' ORDER BY id ASC");
839
+    while ($myrow = Database::fetch_array($result))
840
+    {
841
+        echo "<img src='../img/quiz.gif'>".$myrow["title"]."<br>";
842
+        showorhide_addresourcelink($content, $myrow["id"]);
843
+        echo "<br><br>";
844
+    }
845
+
846
+    if ($from_learnpath == 'yes')
847
+    {
848
+        $uploadPath = "/HotPotatoes_files";
849
+        $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
850
+        $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
851
+        $sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
852
+        $result = Database::query($sql);
853
+        while ($myrow = Database::fetch_array($result))
854
+        {
855
+            $path = $myrow["path"];
856
+            echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
857
+            showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
858
+            echo "<br><br>";
845 859
 
846
-	if ($from_learnpath == 'yes')
847
-	{
848
-		$uploadPath = "/HotPotatoes_files";
849
-		$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
850
-		$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
851
-		$sql = "SELECT * FROM ".$TBL_DOCUMENT." WHERE (path LIKE '%htm%' OR path LIKE '%html%') AND path LIKE '".$uploadPath."/%/%' ORDER BY id ASC";
852
-		$result = Database::query($sql);
853
-		while ($myrow = Database::fetch_array($result))
854
-		{
855
-			$path = $myrow["path"];
856
-			echo "<img src='../img/jqz.gif'>".GetQuizName($path, $documentPath)."<br>";
857
-			showorhide_addresourcelink("HotPotatoes", $myrow["id"]);
858
-			echo "<br><br>";
859
-
860
-		}
861
-	}
860
+        }
861
+    }
862 862
 }
863 863
 
864 864
 /*
@@ -876,10 +876,10 @@  discard block
 block discarded – undo
876 876
       <td align="left"><input name="external_link" type="text" id="external_link" value="http://"></td>
877 877
 	  <?php
878 878
 
879
-	if ($learnpath_id != '')
880
-	{
881
-		echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
882
-	}
879
+    if ($learnpath_id != '')
880
+    {
881
+        echo "</tr><tr><td align='right'>".get_lang('LinkTarget')." :</td><td align='left'><select name='target'><option value='_self'>".get_lang('SameWindow')."</option><option value='_blank'>".get_lang('NewWindow')."</option></select></td>";
882
+    }
883 883
 ?>
884 884
 	</tr>
885 885
     <tr>
@@ -891,14 +891,14 @@  discard block
 block discarded – undo
891 891
 	  <option value="0"><?php echo get_lang('MainCategory'); ?></option>
892 892
 		<?php
893 893
 
894
-	$tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
895
-	$sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
896
-	echo $sql;
897
-	$result = Database::query($sql);
898
-	while ($row = Database::fetch_array($result))
899
-	{
900
-		echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
901
-	}
894
+    $tbl_categories = Database::get_course_table(TABLE_LINK_CATEGORY);
895
+    $sql = "SELECT * FROM $tbl_categories ORDER BY display_order ASC";
896
+    echo $sql;
897
+    $result = Database::query($sql);
898
+    while ($row = Database::fetch_array($result))
899
+    {
900
+        echo "<option value='".$row["id"]."'>".$row["category_title"]."</option>";
901
+    }
902 902
 ?>
903 903
 
904 904
       </select><?php } ?></td>
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
 */
928 928
 if ($content == "Assignment")
929 929
 {
930
-	echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
930
+    echo "<a href=".api_get_self()."?content=Ass&add=Ass&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no>".get_lang('AddAssignmentPage')."</a>";
931 931
 }
932 932
 
933 933
 /*
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 */
938 938
 if ($content == "Dropbox")
939 939
 {
940
-	echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
940
+    echo "<a href='".api_get_self()."?content=Drop&add=Drop&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('DropboxAdd')."</a>";
941 941
 }
942 942
 
943 943
 /*
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
 */
948 948
 if ($content == "Introduction_text")
949 949
 {
950
-	echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
950
+    echo "<a href='".api_get_self()."?content=Intro&add=Intro&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('IntroductionTextAdd')."</a>";
951 951
 }
952 952
 
953 953
 /*
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 */
958 958
 if ($content == "Course_description")
959 959
 {
960
-	echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
960
+    echo "<a href='".api_get_self()."?content=Course_desc&add=Course_desc&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('CourseDescriptionAdd')."</a>";
961 961
 }
962 962
 
963 963
 /*
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 */
968 968
 if ($content == "Groups")
969 969
 {
970
-	echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
970
+    echo "<a href='".api_get_self()."?content=Group&add=Group&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('$GroupsAdd')."</a>";
971 971
 }
972 972
 
973 973
 /*
@@ -977,13 +977,13 @@  discard block
 block discarded – undo
977 977
 */
978 978
 if ($content == "Users")
979 979
 {
980
-	echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
980
+    echo "<a href='".api_get_self()."?content=User&add=User&action=$action&learnpath_id=$learnpath_id&chapter_id=$chapter_id&originalresource=no'>".get_lang('UsersAdd')."</a>";
981 981
 }
982 982
 
983 983
 if ($showresources)
984 984
 {
985
-	//echo "<h4>".get_lang('ResourceAdded')."</h4>";
986
-	display_resources(1);
985
+    //echo "<h4>".get_lang('ResourceAdded')."</h4>";
986
+    display_resources(1);
987 987
 }
988 988
 
989 989
 echo "</td></tr></table>";
Please login to merge, or discard this patch.
main/webservices/cm_webservice_course.php 1 patch
Indentation   +511 added lines, -511 removed lines patch added patch discarded remove patch
@@ -10,521 +10,521 @@
 block discarded – undo
10 10
  */
11 11
 class WSCMCourse extends WSCM
12 12
 {
13
-	/**
14
-	 * Deletes a course (helper method)
15
-	 *
16
-	 * @param string Course id field name
17
-	 * @param string Course id value
18
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
19
-	 */
20
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
-		if($course_id instanceof WSCMError) {
23
-			return $course_id;
24
-		} else {
25
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
26
-			CourseManager::delete_course($course_code);
27
-			return true;
28
-		}
29
-	}
30
-
31
-	/**
32
-	 * Deletes a course
33
-	 *
34
-	 * @param string API secret key
35
-	 * @param string Course id field name
36
-	 * @param string Course id value
37
-	 */
38
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
-		$verifKey = $this->verifyKey($secret_key);
40
-		if($verifKey instanceof WSError) {
41
-			$this->handleError($verifKey);
42
-		} else {
43
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
-			if($result instanceof WSError) {
45
-				$this->handleError($result);
46
-			}
47
-		}
48
-	}
49
-
50
-	/**
51
-	 * Deletes multiple courses
52
-	 *
53
-	 * @param string API secret key
54
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
-	 * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
-	 * than 0, an error occured
57
-	 */
58
-	public function DeleteCourses($secret_key, $courses) {
59
-		$verifKey = $this->verifyKey($secret_key);
60
-		if($verifKey instanceof WSError) {
61
-			$this->handleError($verifKey);
62
-		} else {
63
-			$results = array();
64
-			foreach($courses as $course) {
65
-				$result_tmp = array();
66
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
-				$result_tmp['course_id_value'] = $course['course_id_value'];
68
-				if($result_op instanceof WSCMError) {
69
-					// Return the error in the results
70
-					$result_tmp['result'] = $result_op->toArray();
71
-				} else {
72
-					$result_tmp['result'] = $this->getSuccessfulResult();
73
-				}
74
-				$results[] = $result_tmp;
75
-			}
76
-			return $results;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Creates a course (helper method)
82
-	 *
83
-	 * @param string Title
84
-	 * @param string Category code
85
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
86
-	 * @param string Tutor name
87
-	 * @param string Course admin user id field name
88
-	 * @param string Course admin user id value
89
-	 * @param string Course language
90
-	 * @param string Course id field name
91
-	 * @param string Course id value
92
-	 * @param array Course extra fields
93
-	 * @return mixed Generated id if creation was successful, WSError otherwise
94
-	 */
95
-	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
-		// Add the original course id field name and value to the extra fields if needed
97
-		$extras_associative = array();
98
-		if($course_id_field_name != "chamilo_course_id") {
99
-			$extras_associative[$course_id_field_name] = $course_id_value;
100
-		}
101
-		foreach($extras as $extra) {
102
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
103
-		}
104
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
-		if($course_admin_id instanceof WSError) {
106
-			return $course_admin_id;
107
-		}
108
-		if($wanted_code == '') {
109
-			$wanted_code = CourseManager::generate_course_code($title);
110
-		}
111
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
-		if (!$result) {
113
-			return new WSError(202, 'There was an error creating the course');
114
-		} else {
115
-			// Update extra fields
116
-			foreach($extras_associative as $fname => $fvalue) {
117
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
-			}
119
-			// Get course id
120
-			$course_info = CourseManager::get_course_information($result);
121
-			return $course_info['real_id'];
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * Creates a course
127
-	 *
128
-	 * @param string API secret key
129
-	 * @param string Title
130
-	 * @param string Category code
131
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
132
-	 * @param string Tutor name
133
-	 * @param string Course admin user id field name
134
-	 * @param string Course admin user id value
135
-	 * @param string Course language
136
-	 * @param string Course id field name
137
-	 * @param string Course id value
138
-	 * @param array Course extra fields
139
-	 * @return int Course id generated
140
-	 */
141
-	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
-		// First, verify the secret key
143
-		$verifKey = $this->verifyKey($secret_key);
144
-		if($verifKey instanceof WSError) {
145
-			$this->handleError($verifKey);
146
-		} else {
147
-			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
-			if($result instanceof WSError) {
149
-				$this->handleError($result);
150
-			} else {
151
-				return $result;
152
-			}
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Create multiple courses
158
-	 *
159
-	 * @param string API secret key
160
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
-	 * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
-	 */
163
-	public function CreateCourses($secret_key, $courses) {
164
-		// First, verify the secret key
165
-		$verifKey = $this->verifyKey($secret_key);
166
-		if($verifKey instanceof WSCMError) {
167
-			$this->handleError($verifKey);
168
-		} else {
169
-			$results = array();
170
-			foreach($courses as $course) {
171
-				$result_tmp = array();
172
-				//reinitialize variables just in case
173
-				$title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
-				extract($course);
175
-				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
-				if($result instanceof WSCMError) {
177
-					$result_tmp['result'] = $result->toArray();
178
-					$result_tmp['course_id_value'] = $course_id_value;
179
-					$result_tmp['course_id_generated'] = 0;
180
-				} else {
181
-					$result_tmp['result'] = $this->getSuccessfulResult();
182
-					$result_tmp['course_id_value'] = $course_id_value;
183
-					$result_tmp['course_id_generated'] = $result;
184
-				}
185
-				$results[] = $result_tmp;
186
-			}
187
-			return $results;
188
-		}
189
-	}
190
-
191
-	/**
192
-	 * Edits a course (helper method)
193
-	 *
194
-	 * @param string Course id field name
195
-	 * @param string Course id value
196
-	 * @param string Title
197
-	 * @param string Category code
198
-	 * @param string Department name
199
-	 * @param string Department url
200
-	 * @param string Course language
201
-	 * @param int Visibility
202
-	 * @param int Subscribe (0 = denied, 1 = allowed)
203
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
204
-	 * @param string Visual code
205
-	 * @param array Course extra fields
206
-	 * @return mixed True in case of success, WSError otherwise
207
-	 */
208
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
-		if($course_id instanceof WSCMError) {
211
-			return $course_id;
212
-		} else {
213
-			$attributes = array();
214
-			if(!empty($title)) {
215
-				$attributes['title'] = $title;
216
-			}
217
-			if(!empty($category_code)) {
218
-				$attributes['category_code'] = $category_code;
219
-			}
220
-			if(!empty($department_name)) {
221
-				$attributes['department_name'] = $department_name;
222
-			}
223
-			if(!empty($department_url)) {
224
-				$attributes['department_url'] = $department_url;
225
-			}
226
-			if(!empty($language)) {
227
-				$attributes['course_language'] = $language;
228
-			}
229
-			if($visibility != '') {
230
-				$attributes['visibility'] = (int)$visibility;
231
-			}
232
-			if($subscribe != '') {
233
-				$attributes['subscribe'] = (int)$subscribe;
234
-			}
235
-			if($unsubscribe != '') {
236
-				$attributes['unsubscribe'] = (int)$unsubscribe;
237
-			}
238
-			if(!empty($visual_code)) {
239
-				$attributes['visual_code'] = $visual_code;
240
-			}
241
-			if(!empty($attributes)) {
242
-				CourseManager::update_attributes($course_id, $attributes);
243
-			}
244
-			if(!empty($extras)) {
245
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
246
-				$extras_associative = array();
247
-				foreach($extras as $extra) {
248
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
249
-				}
250
-				foreach($extras_associative as $fname => $fvalue) {
251
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
-				}
253
-			}
254
-			return true;
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * Edits a course
260
-	 *
261
-	 * @param string API secret key
262
-	 * @param string Course id field name
263
-	 * @param string Course id value
264
-	 * @param string Title
265
-	 * @param string Category code
266
-	 * @param string Department name
267
-	 * @param string Department url
268
-	 * @param string Course language
269
-	 * @param int Visibility
270
-	 * @param int Subscribe (0 = denied, 1 = allowed)
271
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
272
-	 * @param string Visual code
273
-	 * @param array Course extra fields
274
-	 */
275
-	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
-		$verifKey = $this->verifyKey($secret_key);
277
-		if($verifKey instanceof WSCMError) {
278
-			$this->handleError($verifKey);
279
-		} else {
280
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
-			if($result instanceof WSCMError) {
282
-				$this->handleError($result);
283
-			}
284
-		}
285
-	}
286
-
287
-	/**
288
-	 * List courses
289
-	 *
290
-	 * @param string API secret key
291
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
-	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
-	 */
295
-	public function ListCourses($secret_key, $course_id_field_name) {
296
-		$verifKey = $this->verifyKey($secret_key);
297
-		if($verifKey instanceof WSError) {
298
-			$this->handleError($verifKey);
299
-		} else {
300
-			$courses_result = array();
301
-			$category_names = array();
302
-
303
-			$courses = CourseManager::get_courses_list();
304
-			foreach($courses as $course) {
305
-				$course_tmp = array();
306
-				$course_tmp['id'] = $course['id'];
307
-				$course_tmp['code'] = $course['code'];
308
-				$course_tmp['title'] = $course['title'];
309
-				$course_tmp['language'] = $course['course_language'];
310
-				$course_tmp['visibility'] = $course['visibility'];
311
-
312
-				// Determining category name
313
-				if($category_names[$course['category_code']]) {
314
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
315
-				} else {
316
-					$category = CourseManager::get_course_category($course['category_code']);
317
-					$category_names[$course['category_code']] = $category['name'];
318
-					$course_tmp['category_name'] = $category['name'];
319
-				}
320
-
321
-				// Determining number of students registered in course
322
-				$user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
-				$course_tmp['number_students'] = count($user_list);
324
-
325
-				// Determining external course id
326
-				$course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
-
328
-
329
-				$courses_result[] = $course_tmp;
330
-			}
331
-
332
-			return $courses_result;
333
-		}
334
-	}
335
-
336
-	/**
337
-	 * Subscribe or unsubscribe user to a course (helper method)
338
-	 *
339
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
-	 * @param string Course id value.
341
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
342
-	 * @param string User id value
343
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
344
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
345
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
346
-	 */
347
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
-		if($course_id instanceof WSError) {
350
-			return $course_id;
351
-		} else {
352
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
-			if($user_id instanceof WSError) {
354
-				return $user_id;
355
-			} else {
356
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
357
-				if($state == 0) {
358
-					// Unsubscribe user
359
-					CourseManager::unsubscribe_user($user_id, $course_code);
360
-					return true;
361
-				} else {
362
-					// Subscribe user
363
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
-						return true;
365
-					} else {
366
-						return new WSError(203, 'An error occured subscribing to this course');
367
-					}
368
-				}
369
-			}
370
-		}
371
-	}
372
-
373
-	/**
374
-	 * Subscribe user to a course
375
-	 *
376
-	 * @param string API secret key
377
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
-	 * @param string Course id value.
379
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
380
-	 * @param string User id value
381
-	 * @param int Status (1 = Teacher, 5 = Student)
382
-	 */
383
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
-		$verifKey = $this->verifyKey($secret_key);
385
-		if($verifKey instanceof WSError) {
386
-			$this->handleError($verifKey);
387
-		} else {
388
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
-			if($result instanceof WSError) {
390
-				$this->handleError($result);
391
-			}
392
-		}
393
-	}
394
-
395
-	/**
396
-	 * Unsusbscribe user from course
397
-	 *
398
-	 * @param string API secret key
399
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
-	 * @param string Course id value.
401
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
402
-	 * @param string User id value
403
-	 */
404
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
-		$verifKey = $this->verifyKey($secret_key);
406
-		if($verifKey instanceof WSError) {
407
-			$this->handleError($verifKey);
408
-		} else {
409
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
-			if($result instanceof WSError) {
411
-				$this->handleError($result);
412
-			}
413
-		}
414
-	}
415
-
416
-	/**
417
-	 * Returns the descriptions of a course, along with their id
418
-	 *
419
-	 * @param string API secret key
420
-	 * @param string Course id field name
421
-	 * @param string Course id value
422
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
-	 */
424
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
-		$verifKey = $this->verifyKey($secret_key);
426
-		if($verifKey instanceof WSError) {
427
-			$this->handleError($verifKey);
428
-		} else {
429
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
-			if($course_id instanceof WSError) {
431
-				return $course_id;
432
-			} else {
433
-				// Course exists, get its descriptions
434
-				$descriptions = CourseDescription::get_descriptions($course_id);
435
-				$results = array();
436
-				foreach($descriptions as $description) {
437
-					$results[] = array('course_desc_id' => $description->get_description_type(),
438
-						'course_desc_title' => $description->get_title(),
439
-						'course_desc_content' => $description->get_content());
440
-				}
441
-				return $results;
442
-			}
443
-		}
444
-	}
445
-
446
-
447
-	/**
448
-	 * Edit course description
449
-	 *
450
-	 * @param string API secret key
451
-	 * @param string Course id field name
452
-	 * @param string Course id value
453
-	 * @param int Category id from course description
454
-	 * @param string Description title
455
-	 * @param string Course description content
456
-	 */
457
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
-		$verifKey = $this->verifyKey($secret_key);
459
-		if($verifKey instanceof WSError) {
460
-			$this->handleError($verifKey);
461
-		} else {
462
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
-			if($course_id instanceof WSError) {
464
-				return $course_id;
465
-			} else {
466
-				// Create the new course description
467
-				$cd = new CourseDescription();
468
-				$cd->set_description_type($course_desc_id);
469
-				$cd->set_title($course_desc_title);
470
-				$cd->set_content($course_desc_content);
471
-				$cd->set_session_id(0);
472
-
473
-				// Get course info
13
+    /**
14
+     * Deletes a course (helper method)
15
+     *
16
+     * @param string Course id field name
17
+     * @param string Course id value
18
+     * @return mixed True if the course was successfully deleted, WSError otherwise
19
+     */
20
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
21
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
22
+        if($course_id instanceof WSCMError) {
23
+            return $course_id;
24
+        } else {
25
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
26
+            CourseManager::delete_course($course_code);
27
+            return true;
28
+        }
29
+    }
30
+
31
+    /**
32
+     * Deletes a course
33
+     *
34
+     * @param string API secret key
35
+     * @param string Course id field name
36
+     * @param string Course id value
37
+     */
38
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
39
+        $verifKey = $this->verifyKey($secret_key);
40
+        if($verifKey instanceof WSError) {
41
+            $this->handleError($verifKey);
42
+        } else {
43
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
44
+            if($result instanceof WSError) {
45
+                $this->handleError($result);
46
+            }
47
+        }
48
+    }
49
+
50
+    /**
51
+     * Deletes multiple courses
52
+     *
53
+     * @param string API secret key
54
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
55
+     * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
56
+     * than 0, an error occured
57
+     */
58
+    public function DeleteCourses($secret_key, $courses) {
59
+        $verifKey = $this->verifyKey($secret_key);
60
+        if($verifKey instanceof WSError) {
61
+            $this->handleError($verifKey);
62
+        } else {
63
+            $results = array();
64
+            foreach($courses as $course) {
65
+                $result_tmp = array();
66
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
67
+                $result_tmp['course_id_value'] = $course['course_id_value'];
68
+                if($result_op instanceof WSCMError) {
69
+                    // Return the error in the results
70
+                    $result_tmp['result'] = $result_op->toArray();
71
+                } else {
72
+                    $result_tmp['result'] = $this->getSuccessfulResult();
73
+                }
74
+                $results[] = $result_tmp;
75
+            }
76
+            return $results;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Creates a course (helper method)
82
+     *
83
+     * @param string Title
84
+     * @param string Category code
85
+     * @param string Wanted code. If it's not defined, it will be generated automatically
86
+     * @param string Tutor name
87
+     * @param string Course admin user id field name
88
+     * @param string Course admin user id value
89
+     * @param string Course language
90
+     * @param string Course id field name
91
+     * @param string Course id value
92
+     * @param array Course extra fields
93
+     * @return mixed Generated id if creation was successful, WSError otherwise
94
+     */
95
+    protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
96
+        // Add the original course id field name and value to the extra fields if needed
97
+        $extras_associative = array();
98
+        if($course_id_field_name != "chamilo_course_id") {
99
+            $extras_associative[$course_id_field_name] = $course_id_value;
100
+        }
101
+        foreach($extras as $extra) {
102
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
103
+        }
104
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
105
+        if($course_admin_id instanceof WSError) {
106
+            return $course_admin_id;
107
+        }
108
+        if($wanted_code == '') {
109
+            $wanted_code = CourseManager::generate_course_code($title);
110
+        }
111
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
112
+        if (!$result) {
113
+            return new WSError(202, 'There was an error creating the course');
114
+        } else {
115
+            // Update extra fields
116
+            foreach($extras_associative as $fname => $fvalue) {
117
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
118
+            }
119
+            // Get course id
120
+            $course_info = CourseManager::get_course_information($result);
121
+            return $course_info['real_id'];
122
+        }
123
+    }
124
+
125
+    /**
126
+     * Creates a course
127
+     *
128
+     * @param string API secret key
129
+     * @param string Title
130
+     * @param string Category code
131
+     * @param string Wanted code. If it's not defined, it will be generated automatically
132
+     * @param string Tutor name
133
+     * @param string Course admin user id field name
134
+     * @param string Course admin user id value
135
+     * @param string Course language
136
+     * @param string Course id field name
137
+     * @param string Course id value
138
+     * @param array Course extra fields
139
+     * @return int Course id generated
140
+     */
141
+    public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
142
+        // First, verify the secret key
143
+        $verifKey = $this->verifyKey($secret_key);
144
+        if($verifKey instanceof WSError) {
145
+            $this->handleError($verifKey);
146
+        } else {
147
+            $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
148
+            if($result instanceof WSError) {
149
+                $this->handleError($result);
150
+            } else {
151
+                return $result;
152
+            }
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Create multiple courses
158
+     *
159
+     * @param string API secret key
160
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
161
+     * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
162
+     */
163
+    public function CreateCourses($secret_key, $courses) {
164
+        // First, verify the secret key
165
+        $verifKey = $this->verifyKey($secret_key);
166
+        if($verifKey instanceof WSCMError) {
167
+            $this->handleError($verifKey);
168
+        } else {
169
+            $results = array();
170
+            foreach($courses as $course) {
171
+                $result_tmp = array();
172
+                //reinitialize variables just in case
173
+                $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = null;
174
+                extract($course);
175
+                $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
176
+                if($result instanceof WSCMError) {
177
+                    $result_tmp['result'] = $result->toArray();
178
+                    $result_tmp['course_id_value'] = $course_id_value;
179
+                    $result_tmp['course_id_generated'] = 0;
180
+                } else {
181
+                    $result_tmp['result'] = $this->getSuccessfulResult();
182
+                    $result_tmp['course_id_value'] = $course_id_value;
183
+                    $result_tmp['course_id_generated'] = $result;
184
+                }
185
+                $results[] = $result_tmp;
186
+            }
187
+            return $results;
188
+        }
189
+    }
190
+
191
+    /**
192
+     * Edits a course (helper method)
193
+     *
194
+     * @param string Course id field name
195
+     * @param string Course id value
196
+     * @param string Title
197
+     * @param string Category code
198
+     * @param string Department name
199
+     * @param string Department url
200
+     * @param string Course language
201
+     * @param int Visibility
202
+     * @param int Subscribe (0 = denied, 1 = allowed)
203
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
204
+     * @param string Visual code
205
+     * @param array Course extra fields
206
+     * @return mixed True in case of success, WSError otherwise
207
+     */
208
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
209
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
210
+        if($course_id instanceof WSCMError) {
211
+            return $course_id;
212
+        } else {
213
+            $attributes = array();
214
+            if(!empty($title)) {
215
+                $attributes['title'] = $title;
216
+            }
217
+            if(!empty($category_code)) {
218
+                $attributes['category_code'] = $category_code;
219
+            }
220
+            if(!empty($department_name)) {
221
+                $attributes['department_name'] = $department_name;
222
+            }
223
+            if(!empty($department_url)) {
224
+                $attributes['department_url'] = $department_url;
225
+            }
226
+            if(!empty($language)) {
227
+                $attributes['course_language'] = $language;
228
+            }
229
+            if($visibility != '') {
230
+                $attributes['visibility'] = (int)$visibility;
231
+            }
232
+            if($subscribe != '') {
233
+                $attributes['subscribe'] = (int)$subscribe;
234
+            }
235
+            if($unsubscribe != '') {
236
+                $attributes['unsubscribe'] = (int)$unsubscribe;
237
+            }
238
+            if(!empty($visual_code)) {
239
+                $attributes['visual_code'] = $visual_code;
240
+            }
241
+            if(!empty($attributes)) {
242
+                CourseManager::update_attributes($course_id, $attributes);
243
+            }
244
+            if(!empty($extras)) {
245
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
246
+                $extras_associative = array();
247
+                foreach($extras as $extra) {
248
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
249
+                }
250
+                foreach($extras_associative as $fname => $fvalue) {
251
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
252
+                }
253
+            }
254
+            return true;
255
+        }
256
+    }
257
+
258
+    /**
259
+     * Edits a course
260
+     *
261
+     * @param string API secret key
262
+     * @param string Course id field name
263
+     * @param string Course id value
264
+     * @param string Title
265
+     * @param string Category code
266
+     * @param string Department name
267
+     * @param string Department url
268
+     * @param string Course language
269
+     * @param int Visibility
270
+     * @param int Subscribe (0 = denied, 1 = allowed)
271
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
272
+     * @param string Visual code
273
+     * @param array Course extra fields
274
+     */
275
+    public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
276
+        $verifKey = $this->verifyKey($secret_key);
277
+        if($verifKey instanceof WSCMError) {
278
+            $this->handleError($verifKey);
279
+        } else {
280
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
281
+            if($result instanceof WSCMError) {
282
+                $this->handleError($result);
283
+            }
284
+        }
285
+    }
286
+
287
+    /**
288
+     * List courses
289
+     *
290
+     * @param string API secret key
291
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
292
+     * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
293
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
294
+     */
295
+    public function ListCourses($secret_key, $course_id_field_name) {
296
+        $verifKey = $this->verifyKey($secret_key);
297
+        if($verifKey instanceof WSError) {
298
+            $this->handleError($verifKey);
299
+        } else {
300
+            $courses_result = array();
301
+            $category_names = array();
302
+
303
+            $courses = CourseManager::get_courses_list();
304
+            foreach($courses as $course) {
305
+                $course_tmp = array();
306
+                $course_tmp['id'] = $course['id'];
307
+                $course_tmp['code'] = $course['code'];
308
+                $course_tmp['title'] = $course['title'];
309
+                $course_tmp['language'] = $course['course_language'];
310
+                $course_tmp['visibility'] = $course['visibility'];
311
+
312
+                // Determining category name
313
+                if($category_names[$course['category_code']]) {
314
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
315
+                } else {
316
+                    $category = CourseManager::get_course_category($course['category_code']);
317
+                    $category_names[$course['category_code']] = $category['name'];
318
+                    $course_tmp['category_name'] = $category['name'];
319
+                }
320
+
321
+                // Determining number of students registered in course
322
+                $user_list = CourseManager::get_user_list_from_course_code($course['code']);
323
+                $course_tmp['number_students'] = count($user_list);
324
+
325
+                // Determining external course id
326
+                $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']);
327
+
328
+
329
+                $courses_result[] = $course_tmp;
330
+            }
331
+
332
+            return $courses_result;
333
+        }
334
+    }
335
+
336
+    /**
337
+     * Subscribe or unsubscribe user to a course (helper method)
338
+     *
339
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
340
+     * @param string Course id value.
341
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
342
+     * @param string User id value
343
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
344
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
345
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
346
+     */
347
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
348
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
349
+        if($course_id instanceof WSError) {
350
+            return $course_id;
351
+        } else {
352
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
353
+            if($user_id instanceof WSError) {
354
+                return $user_id;
355
+            } else {
356
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
357
+                if($state == 0) {
358
+                    // Unsubscribe user
359
+                    CourseManager::unsubscribe_user($user_id, $course_code);
360
+                    return true;
361
+                } else {
362
+                    // Subscribe user
363
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
364
+                        return true;
365
+                    } else {
366
+                        return new WSError(203, 'An error occured subscribing to this course');
367
+                    }
368
+                }
369
+            }
370
+        }
371
+    }
372
+
373
+    /**
374
+     * Subscribe user to a course
375
+     *
376
+     * @param string API secret key
377
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
378
+     * @param string Course id value.
379
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
380
+     * @param string User id value
381
+     * @param int Status (1 = Teacher, 5 = Student)
382
+     */
383
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
384
+        $verifKey = $this->verifyKey($secret_key);
385
+        if($verifKey instanceof WSError) {
386
+            $this->handleError($verifKey);
387
+        } else {
388
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
389
+            if($result instanceof WSError) {
390
+                $this->handleError($result);
391
+            }
392
+        }
393
+    }
394
+
395
+    /**
396
+     * Unsusbscribe user from course
397
+     *
398
+     * @param string API secret key
399
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
400
+     * @param string Course id value.
401
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
402
+     * @param string User id value
403
+     */
404
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
405
+        $verifKey = $this->verifyKey($secret_key);
406
+        if($verifKey instanceof WSError) {
407
+            $this->handleError($verifKey);
408
+        } else {
409
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
410
+            if($result instanceof WSError) {
411
+                $this->handleError($result);
412
+            }
413
+        }
414
+    }
415
+
416
+    /**
417
+     * Returns the descriptions of a course, along with their id
418
+     *
419
+     * @param string API secret key
420
+     * @param string Course id field name
421
+     * @param string Course id value
422
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
423
+     */
424
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
425
+        $verifKey = $this->verifyKey($secret_key);
426
+        if($verifKey instanceof WSError) {
427
+            $this->handleError($verifKey);
428
+        } else {
429
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
430
+            if($course_id instanceof WSError) {
431
+                return $course_id;
432
+            } else {
433
+                // Course exists, get its descriptions
434
+                $descriptions = CourseDescription::get_descriptions($course_id);
435
+                $results = array();
436
+                foreach($descriptions as $description) {
437
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
438
+                        'course_desc_title' => $description->get_title(),
439
+                        'course_desc_content' => $description->get_content());
440
+                }
441
+                return $results;
442
+            }
443
+        }
444
+    }
445
+
446
+
447
+    /**
448
+     * Edit course description
449
+     *
450
+     * @param string API secret key
451
+     * @param string Course id field name
452
+     * @param string Course id value
453
+     * @param int Category id from course description
454
+     * @param string Description title
455
+     * @param string Course description content
456
+     */
457
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
458
+        $verifKey = $this->verifyKey($secret_key);
459
+        if($verifKey instanceof WSError) {
460
+            $this->handleError($verifKey);
461
+        } else {
462
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
463
+            if($course_id instanceof WSError) {
464
+                return $course_id;
465
+            } else {
466
+                // Create the new course description
467
+                $cd = new CourseDescription();
468
+                $cd->set_description_type($course_desc_id);
469
+                $cd->set_title($course_desc_title);
470
+                $cd->set_content($course_desc_content);
471
+                $cd->set_session_id(0);
472
+
473
+                // Get course info
474 474
                 $course_info = CourseManager::get_course_information(
475 475
                     CourseManager::get_course_code_from_course_id($course_id)
476 476
                 );
477
-				// Check if this course description exists
478
-				$descriptions = CourseDescription::get_descriptions($course_id);
479
-				$exists = false;
480
-				foreach($descriptions as $description) {
481
-					if($description->get_description_type() == $course_desc_id) {
482
-						$exists = true;
483
-					}
484
-				}
477
+                // Check if this course description exists
478
+                $descriptions = CourseDescription::get_descriptions($course_id);
479
+                $exists = false;
480
+                foreach($descriptions as $description) {
481
+                    if($description->get_description_type() == $course_desc_id) {
482
+                        $exists = true;
483
+                    }
484
+                }
485 485
                 $cd->set_course_id($course_info['real_id']);
486
-				if (!$exists) {
487
-					$cd->set_progress(0);
488
-					$cd->insert();
489
-				} else {
490
-					$cd->update();
491
-				}
492
-			}
493
-		}
494
-	}
495
-	public function unreadMessage($username, $password)
496
-	{
497
-		if($this->verifyUserPass($username, $password) == "valid")
498
-		{
499
-			$table_message = Database::get_main_table(TABLE_MESSAGE);
500
-			$user_id = UserManager::get_user_id_from_username($username);
501
-			$condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
-
503
-			$sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
-
505
-			$sql_result = Database::query($sql_query);
506
-			$result = Database::fetch_array($sql_result);
507
-			return $result['number_messages'];
508
-		}
509
-		return "0";
510
-	}
511
-
512
-	public function get_message_data($username, $password)
513
-	{
514
-		if($this->verifyUserPass($username, $password) == "valid")
515
-		{
516
-			$user_id = get_user_id_from_username($username);
517
-
518
-		}
519
-
520
-	}
521
-
522
-	public function nada($username, $password)
523
-	{
524
-		if($this->verifyUserPass($username, $password) == "valid")
525
-			return $username.$password;
526
-		return $username;
527
-	}
486
+                if (!$exists) {
487
+                    $cd->set_progress(0);
488
+                    $cd->insert();
489
+                } else {
490
+                    $cd->update();
491
+                }
492
+            }
493
+        }
494
+    }
495
+    public function unreadMessage($username, $password)
496
+    {
497
+        if($this->verifyUserPass($username, $password) == "valid")
498
+        {
499
+            $table_message = Database::get_main_table(TABLE_MESSAGE);
500
+            $user_id = UserManager::get_user_id_from_username($username);
501
+            $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1');
502
+
503
+            $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id;
504
+
505
+            $sql_result = Database::query($sql_query);
506
+            $result = Database::fetch_array($sql_result);
507
+            return $result['number_messages'];
508
+        }
509
+        return "0";
510
+    }
511
+
512
+    public function get_message_data($username, $password)
513
+    {
514
+        if($this->verifyUserPass($username, $password) == "valid")
515
+        {
516
+            $user_id = get_user_id_from_username($username);
517
+
518
+        }
519
+
520
+    }
521
+
522
+    public function nada($username, $password)
523
+    {
524
+        if($this->verifyUserPass($username, $password) == "valid")
525
+            return $username.$password;
526
+        return $username;
527
+    }
528 528
 
529 529
 
530 530
 
Please login to merge, or discard this patch.
main/webservices/webservice_course.php 1 patch
Indentation   +455 added lines, -455 removed lines patch added patch discarded remove patch
@@ -12,490 +12,490 @@
 block discarded – undo
12 12
  */
13 13
 class WSCourse extends WS
14 14
 {
15
-	/**
16
-	 * Deletes a course (helper method)
17
-	 *
18
-	 * @param string Course id field name
19
-	 * @param string Course id value
20
-	 * @return mixed True if the course was successfully deleted, WSError otherwise
21
-	 */
22
-	protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
-		if($course_id instanceof WSError) {
25
-			return $course_id;
26
-		} else {
27
-			$course_code = CourseManager::get_course_code_from_course_id($course_id);
28
-			CourseManager::delete_course($course_code);
29
-			return true;
30
-		}
31
-	}
15
+    /**
16
+     * Deletes a course (helper method)
17
+     *
18
+     * @param string Course id field name
19
+     * @param string Course id value
20
+     * @return mixed True if the course was successfully deleted, WSError otherwise
21
+     */
22
+    protected function deleteCourseHelper($course_id_field_name, $course_id_value) {
23
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
24
+        if($course_id instanceof WSError) {
25
+            return $course_id;
26
+        } else {
27
+            $course_code = CourseManager::get_course_code_from_course_id($course_id);
28
+            CourseManager::delete_course($course_code);
29
+            return true;
30
+        }
31
+    }
32 32
 
33
-	/**
34
-	 * Deletes a course
35
-	 *
36
-	 * @param string API secret key
37
-	 * @param string Course id field name
38
-	 * @param string Course id value
39
-	 */
40
-	public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
-		$verifKey = $this->verifyKey($secret_key);
42
-		if($verifKey instanceof WSError) {
43
-			$this->handleError($verifKey);
44
-		} else {
45
-			$result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
-			if($result instanceof WSError) {
47
-				$this->handleError($result);
48
-			}
49
-		}
50
-	}
33
+    /**
34
+     * Deletes a course
35
+     *
36
+     * @param string API secret key
37
+     * @param string Course id field name
38
+     * @param string Course id value
39
+     */
40
+    public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) {
41
+        $verifKey = $this->verifyKey($secret_key);
42
+        if($verifKey instanceof WSError) {
43
+            $this->handleError($verifKey);
44
+        } else {
45
+            $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value);
46
+            if($result instanceof WSError) {
47
+                $this->handleError($result);
48
+            }
49
+        }
50
+    }
51 51
 
52
-	/**
53
-	 * Deletes multiple courses
54
-	 *
55
-	 * @param string API secret key
56
-	 * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
-	 * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
58
-	 * than 0, an error occured
59
-	 */
60
-	public function DeleteCourses($secret_key, $courses) {
61
-		$verifKey = $this->verifyKey($secret_key);
62
-		if($verifKey instanceof WSError) {
63
-			$this->handleError($verifKey);
64
-		} else {
65
-			$results = array();
66
-			foreach($courses as $course) {
67
-				$result_tmp = array();
68
-				$result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
-				$result_tmp['course_id_value'] = $course['course_id_value'];
70
-				if($result_op instanceof WSError) {
71
-					// Return the error in the results
72
-					$result_tmp['result'] = $result_op->toArray();
73
-				} else {
74
-					$result_tmp['result'] = $this->getSuccessfulResult();
75
-				}
76
-				$results[] = $result_tmp;
77
-			}
78
-			return $results;
79
-		}
80
-	}
52
+    /**
53
+     * Deletes multiple courses
54
+     *
55
+     * @param string API secret key
56
+     * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value')
57
+     * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different
58
+     * than 0, an error occured
59
+     */
60
+    public function DeleteCourses($secret_key, $courses) {
61
+        $verifKey = $this->verifyKey($secret_key);
62
+        if($verifKey instanceof WSError) {
63
+            $this->handleError($verifKey);
64
+        } else {
65
+            $results = array();
66
+            foreach($courses as $course) {
67
+                $result_tmp = array();
68
+                $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']);
69
+                $result_tmp['course_id_value'] = $course['course_id_value'];
70
+                if($result_op instanceof WSError) {
71
+                    // Return the error in the results
72
+                    $result_tmp['result'] = $result_op->toArray();
73
+                } else {
74
+                    $result_tmp['result'] = $this->getSuccessfulResult();
75
+                }
76
+                $results[] = $result_tmp;
77
+            }
78
+            return $results;
79
+        }
80
+    }
81 81
 
82
-	/**
83
-	 * Creates a course (helper method)
84
-	 *
85
-	 * @param string Title
86
-	 * @param string Category code
87
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
88
-	 * @param string Tutor name
89
-	 * @param string Course admin user id field name
90
-	 * @param string Course admin user id value
91
-	 * @param string Course language
92
-	 * @param string Course id field name
93
-	 * @param string Course id value
94
-	 * @param array Course extra fields
95
-	 * @return mixed Generated id if creation was successful, WSError otherwise
96
-	 */
97
-	protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
98
-		// Add the original course id field name and value to the extra fields if needed
99
-		$extras_associative = array();
100
-		if($course_id_field_name != "chamilo_course_id") {
101
-			$extras_associative[$course_id_field_name] = $course_id_value;
102
-		}
103
-		foreach($extras as $extra) {
104
-			$extras_associative[$extra['field_name']] = $extra['field_value'];
105
-		}
106
-		$course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
-		if($course_admin_id instanceof WSError) {
108
-			return $course_admin_id;
109
-		}
110
-		if($wanted_code == '') {
111
-			$wanted_code = CourseManager::generate_course_code($title);
112
-		}
113
-		$result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
-		if (!$result) {
115
-			return new WSError(202, 'There was an error creating the course');
116
-		} else {
117
-			// Update extra fields
118
-			foreach($extras_associative as $fname => $fvalue) {
119
-				CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
-			}
121
-			// Get course id
122
-			$course_info = CourseManager::get_course_information($result);
123
-			return $course_info['real_id'];
124
-		}
125
-	}
82
+    /**
83
+     * Creates a course (helper method)
84
+     *
85
+     * @param string Title
86
+     * @param string Category code
87
+     * @param string Wanted code. If it's not defined, it will be generated automatically
88
+     * @param string Tutor name
89
+     * @param string Course admin user id field name
90
+     * @param string Course admin user id value
91
+     * @param string Course language
92
+     * @param string Course id field name
93
+     * @param string Course id value
94
+     * @param array Course extra fields
95
+     * @return mixed Generated id if creation was successful, WSError otherwise
96
+     */
97
+    protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
98
+        // Add the original course id field name and value to the extra fields if needed
99
+        $extras_associative = array();
100
+        if($course_id_field_name != "chamilo_course_id") {
101
+            $extras_associative[$course_id_field_name] = $course_id_value;
102
+        }
103
+        foreach($extras as $extra) {
104
+            $extras_associative[$extra['field_name']] = $extra['field_value'];
105
+        }
106
+        $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value);
107
+        if($course_admin_id instanceof WSError) {
108
+            return $course_admin_id;
109
+        }
110
+        if($wanted_code == '') {
111
+            $wanted_code = CourseManager::generate_course_code($title);
112
+        }
113
+        $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0);
114
+        if (!$result) {
115
+            return new WSError(202, 'There was an error creating the course');
116
+        } else {
117
+            // Update extra fields
118
+            foreach($extras_associative as $fname => $fvalue) {
119
+                CourseManager::update_course_extra_field_value($result, $fname, $fvalue);
120
+            }
121
+            // Get course id
122
+            $course_info = CourseManager::get_course_information($result);
123
+            return $course_info['real_id'];
124
+        }
125
+    }
126 126
 
127
-	/**
128
-	 * Creates a course
129
-	 *
130
-	 * @param string API secret key
131
-	 * @param string Title
132
-	 * @param string Category code
133
-	 * @param string Wanted code. If it's not defined, it will be generated automatically
134
-	 * @param string Tutor name
135
-	 * @param string Course admin user id field name
136
-	 * @param string Course admin user id value
137
-	 * @param string Course language
138
-	 * @param string Course id field name
139
-	 * @param string Course id value
140
-	 * @param array Course extra fields
141
-	 * @return int Course id generated
142
-	 */
143
-	public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
144
-		// First, verify the secret key
145
-		$verifKey = $this->verifyKey($secret_key);
146
-		if($verifKey instanceof WSError) {
147
-			$this->handleError($verifKey);
148
-		} else {
149
-			$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
150
-			if($result instanceof WSError) {
151
-				$this->handleError($result);
152
-			} else {
153
-				return $result;
154
-			}
155
-		}
156
-	}
127
+    /**
128
+     * Creates a course
129
+     *
130
+     * @param string API secret key
131
+     * @param string Title
132
+     * @param string Category code
133
+     * @param string Wanted code. If it's not defined, it will be generated automatically
134
+     * @param string Tutor name
135
+     * @param string Course admin user id field name
136
+     * @param string Course admin user id value
137
+     * @param string Course language
138
+     * @param string Course id field name
139
+     * @param string Course id value
140
+     * @param array Course extra fields
141
+     * @return int Course id generated
142
+     */
143
+    public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) {
144
+        // First, verify the secret key
145
+        $verifKey = $this->verifyKey($secret_key);
146
+        if($verifKey instanceof WSError) {
147
+            $this->handleError($verifKey);
148
+        } else {
149
+            $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
150
+            if($result instanceof WSError) {
151
+                $this->handleError($result);
152
+            } else {
153
+                return $result;
154
+            }
155
+        }
156
+    }
157 157
 
158
-	/**
159
-	 * Create multiple courses
160
-	 *
161
-	 * @param string API secret key
162
-	 * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
-	 * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
164
-	 */
165
-	public function CreateCourses($secret_key, $courses) {
166
-		// First, verify the secret key
167
-		$verifKey = $this->verifyKey($secret_key);
168
-		if($verifKey instanceof WSError) {
169
-			$this->handleError($verifKey);
170
-		} else {
171
-			$results = array();
172
-			foreach($courses as $course) {
173
-				$result_tmp = array();
158
+    /**
159
+     * Create multiple courses
160
+     *
161
+     * @param string API secret key
162
+     * @param array Courses to be created, with elements following the structure presented in CreateCourse
163
+     * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful'))
164
+     */
165
+    public function CreateCourses($secret_key, $courses) {
166
+        // First, verify the secret key
167
+        $verifKey = $this->verifyKey($secret_key);
168
+        if($verifKey instanceof WSError) {
169
+            $this->handleError($verifKey);
170
+        } else {
171
+            $results = array();
172
+            foreach($courses as $course) {
173
+                $result_tmp = array();
174 174
                 // re-initialize variables just in case
175 175
                 $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0;
176
-				extract($course);
177
-				$result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
178
-				if($result instanceof WSError) {
179
-					$result_tmp['result'] = $result->toArray();
180
-					$result_tmp['course_id_value'] = $course_id_value;
181
-					$result_tmp['course_id_generated'] = 0;
182
-				} else {
183
-					$result_tmp['result'] = $this->getSuccessfulResult();
184
-					$result_tmp['course_id_value'] = $course_id_value;
185
-					$result_tmp['course_id_generated'] = $result;
186
-				}
187
-				$results[] = $result_tmp;
188
-			}
189
-			return $results;
190
-		}
191
-	}
176
+                extract($course);
177
+                $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras);
178
+                if($result instanceof WSError) {
179
+                    $result_tmp['result'] = $result->toArray();
180
+                    $result_tmp['course_id_value'] = $course_id_value;
181
+                    $result_tmp['course_id_generated'] = 0;
182
+                } else {
183
+                    $result_tmp['result'] = $this->getSuccessfulResult();
184
+                    $result_tmp['course_id_value'] = $course_id_value;
185
+                    $result_tmp['course_id_generated'] = $result;
186
+                }
187
+                $results[] = $result_tmp;
188
+            }
189
+            return $results;
190
+        }
191
+    }
192 192
 
193
-	/**
194
-	 * Edits a course (helper method)
195
-	 *
196
-	 * @param string Course id field name
197
-	 * @param string Course id value
198
-	 * @param string Title
199
-	 * @param string Category code
200
-	 * @param string Department name
201
-	 * @param string Department url
202
-	 * @param string Course language
203
-	 * @param int Visibility
204
-	 * @param int Subscribe (0 = denied, 1 = allowed)
205
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
206
-	 * @param string Visual code
207
-	 * @param array Course extra fields
208
-	 * @return mixed True in case of success, WSError otherwise
209
-	 */
210
-	protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
-		if($course_id instanceof WSError) {
213
-			return $course_id;
214
-		} else {
215
-			$attributes = array();
216
-			if(!empty($title)) {
217
-				$attributes['title'] = $title;
218
-			}
219
-			if(!empty($category_code)) {
220
-				$attributes['category_code'] = $category_code;
221
-			}
222
-			if(!empty($department_name)) {
223
-				$attributes['department_name'] = $department_name;
224
-			}
225
-			if(!empty($department_url)) {
226
-				$attributes['department_url'] = $department_url;
227
-			}
228
-			if(!empty($language)) {
229
-				$attributes['course_language'] = $language;
230
-			}
231
-			if($visibility != '') {
232
-				$attributes['visibility'] = (int)$visibility;
233
-			}
234
-			if($subscribe != '') {
235
-				$attributes['subscribe'] = (int)$subscribe;
236
-			}
237
-			if($unsubscribe != '') {
238
-				$attributes['unsubscribe'] = (int)$unsubscribe;
239
-			}
240
-			if(!empty($visual_code)) {
241
-				$attributes['visual_code'] = $visual_code;
242
-			}
243
-			if(!empty($attributes)) {
244
-				CourseManager::update_attributes($course_id, $attributes);
245
-			}
246
-			if(!empty($extras)) {
247
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
248
-				$extras_associative = array();
249
-				foreach($extras as $extra) {
250
-					$extras_associative[$extra['field_name']] = $extra['field_value'];
251
-				}
252
-				foreach($extras_associative as $fname => $fvalue) {
253
-					CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
-				}
255
-			}
256
-			return true;
257
-		}
258
-	}
193
+    /**
194
+     * Edits a course (helper method)
195
+     *
196
+     * @param string Course id field name
197
+     * @param string Course id value
198
+     * @param string Title
199
+     * @param string Category code
200
+     * @param string Department name
201
+     * @param string Department url
202
+     * @param string Course language
203
+     * @param int Visibility
204
+     * @param int Subscribe (0 = denied, 1 = allowed)
205
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
206
+     * @param string Visual code
207
+     * @param array Course extra fields
208
+     * @return mixed True in case of success, WSError otherwise
209
+     */
210
+    protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
211
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
212
+        if($course_id instanceof WSError) {
213
+            return $course_id;
214
+        } else {
215
+            $attributes = array();
216
+            if(!empty($title)) {
217
+                $attributes['title'] = $title;
218
+            }
219
+            if(!empty($category_code)) {
220
+                $attributes['category_code'] = $category_code;
221
+            }
222
+            if(!empty($department_name)) {
223
+                $attributes['department_name'] = $department_name;
224
+            }
225
+            if(!empty($department_url)) {
226
+                $attributes['department_url'] = $department_url;
227
+            }
228
+            if(!empty($language)) {
229
+                $attributes['course_language'] = $language;
230
+            }
231
+            if($visibility != '') {
232
+                $attributes['visibility'] = (int)$visibility;
233
+            }
234
+            if($subscribe != '') {
235
+                $attributes['subscribe'] = (int)$subscribe;
236
+            }
237
+            if($unsubscribe != '') {
238
+                $attributes['unsubscribe'] = (int)$unsubscribe;
239
+            }
240
+            if(!empty($visual_code)) {
241
+                $attributes['visual_code'] = $visual_code;
242
+            }
243
+            if(!empty($attributes)) {
244
+                CourseManager::update_attributes($course_id, $attributes);
245
+            }
246
+            if(!empty($extras)) {
247
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
248
+                $extras_associative = array();
249
+                foreach($extras as $extra) {
250
+                    $extras_associative[$extra['field_name']] = $extra['field_value'];
251
+                }
252
+                foreach($extras_associative as $fname => $fvalue) {
253
+                    CourseManager::update_extra_field_value($course_code, $fname, $fvalue);
254
+                }
255
+            }
256
+            return true;
257
+        }
258
+    }
259 259
 
260
-	/**
261
-	 * Edits a course
262
-	 *
263
-	 * @param string API secret key
264
-	 * @param string Course id field name
265
-	 * @param string Course id value
266
-	 * @param string Title
267
-	 * @param string Category code
268
-	 * @param string Department name
269
-	 * @param string Department url
270
-	 * @param string Course language
271
-	 * @param int Visibility
272
-	 * @param int Subscribe (0 = denied, 1 = allowed)
273
-	 * @param int Unsubscribe (0 = denied, 1 = allowed)
274
-	 * @param string Visual code
275
-	 * @param array Course extra fields
276
-	 */
277
-	public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
278
-		$verifKey = $this->verifyKey($secret_key);
279
-		if($verifKey instanceof WSError) {
280
-			$this->handleError($verifKey);
281
-		} else {
282
-			$result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
-			if($result instanceof WSError) {
284
-				$this->handleError($result);
285
-			}
286
-		}
287
-	}
260
+    /**
261
+     * Edits a course
262
+     *
263
+     * @param string API secret key
264
+     * @param string Course id field name
265
+     * @param string Course id value
266
+     * @param string Title
267
+     * @param string Category code
268
+     * @param string Department name
269
+     * @param string Department url
270
+     * @param string Course language
271
+     * @param int Visibility
272
+     * @param int Subscribe (0 = denied, 1 = allowed)
273
+     * @param int Unsubscribe (0 = denied, 1 = allowed)
274
+     * @param string Visual code
275
+     * @param array Course extra fields
276
+     */
277
+    public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) {
278
+        $verifKey = $this->verifyKey($secret_key);
279
+        if($verifKey instanceof WSError) {
280
+            $this->handleError($verifKey);
281
+        } else {
282
+            $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras);
283
+            if($result instanceof WSError) {
284
+                $this->handleError($result);
285
+            }
286
+        }
287
+    }
288 288
 
289
-	/**
290
-	 * List courses
291
-	 *
292
-	 * @param string API secret key
293
-	 * @param string A list of visibility filter we want to apply
294
-	 * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
295
-	 * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
-	 */
297
-	public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
-		$verifKey = $this->verifyKey($secret_key);
299
-		if($verifKey instanceof WSError) {
300
-			$this->handleError($verifKey);
301
-		} else {
289
+    /**
290
+     * List courses
291
+     *
292
+     * @param string API secret key
293
+     * @param string A list of visibility filter we want to apply
294
+     * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility',
295
+     * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id')
296
+     */
297
+    public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') {
298
+        $verifKey = $this->verifyKey($secret_key);
299
+        if($verifKey instanceof WSError) {
300
+            $this->handleError($verifKey);
301
+        } else {
302 302
             $visibilities = split(',',$visibility);
303 303
             $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0');
304 304
             foreach ($visibilities as $p => $visibility) {
305 305
                 $visibilities[$p] = $vis[$visibility];
306 306
             }
307
-			$courses_result = array();
308
-			$category_names = array();
307
+            $courses_result = array();
308
+            $category_names = array();
309 309
 
310
-			$courses = CourseManager::get_courses_list();
311
-			foreach($courses as $course) {
310
+            $courses = CourseManager::get_courses_list();
311
+            foreach($courses as $course) {
312 312
                 //skip elements that do not match required visibility
313 313
                 if (!in_array($course['visibility'],$visibilities)) { continue; }
314
-				$course_tmp = array();
315
-				$course_tmp['id'] = $course['id'];
316
-				$course_tmp['code'] = $course['code'];
317
-				$course_tmp['title'] = $course['title'];
318
-				$course_tmp['language'] = $course['course_language'];
319
-				$course_tmp['visibility'] = $course['visibility'];
314
+                $course_tmp = array();
315
+                $course_tmp['id'] = $course['id'];
316
+                $course_tmp['code'] = $course['code'];
317
+                $course_tmp['title'] = $course['title'];
318
+                $course_tmp['language'] = $course['course_language'];
319
+                $course_tmp['visibility'] = $course['visibility'];
320 320
 
321
-				// Determining category name
322
-				if($category_names[$course['category_code']]) {
323
-					$course_tmp['category_name'] = $category_names[$course['category_code']];
324
-				} else {
325
-					$category = CourseManager::get_course_category($course['category_code']);
326
-					$category_names[$course['category_code']] = $category['name'];
327
-					$course_tmp['category_name'] = $category['name'];
328
-				}
321
+                // Determining category name
322
+                if($category_names[$course['category_code']]) {
323
+                    $course_tmp['category_name'] = $category_names[$course['category_code']];
324
+                } else {
325
+                    $category = CourseManager::get_course_category($course['category_code']);
326
+                    $category_names[$course['category_code']] = $category['name'];
327
+                    $course_tmp['category_name'] = $category['name'];
328
+                }
329 329
 
330
-				// Determining number of students registered in course
331
-				$user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
-				$course_tmp['number_students'] = count($user_list);
330
+                // Determining number of students registered in course
331
+                $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0);
332
+                $course_tmp['number_students'] = count($user_list);
333 333
 
334
-				// Determining external course id - this code misses the external course id field name
335
-				// $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
334
+                // Determining external course id - this code misses the external course id field name
335
+                // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']);
336 336
 
337 337
 
338
-				$courses_result[] = $course_tmp;
339
-			}
338
+                $courses_result[] = $course_tmp;
339
+            }
340 340
 
341
-			return $courses_result;
342
-		}
343
-	}
341
+            return $courses_result;
342
+        }
343
+    }
344 344
 
345
-	/**
346
-	 * Subscribe or unsubscribe user to a course (helper method)
347
-	 *
348
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
-	 * @param string Course id value.
350
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
351
-	 * @param string User id value
352
-	 * @param int Set to 1 to subscribe, 0 to unsubscribe
353
-	 * @param int Status (STUDENT or TEACHER) Used for subscription only
354
-	 * @return mixed True if subscription or unsubscription was successful, false otherwise
355
-	 */
356
-	protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
-		$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
-		if($course_id instanceof WSError) {
359
-			return $course_id;
360
-		} else {
361
-			$user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
-			if($user_id instanceof WSError) {
363
-				return $user_id;
364
-			} else {
365
-				$course_code = CourseManager::get_course_code_from_course_id($course_id);
366
-				if($state == 0) {
367
-					// Unsubscribe user
368
-					CourseManager::unsubscribe_user($user_id, $course_code);
369
-					return true;
370
-				} else {
371
-					// Subscribe user
372
-					if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
-						return true;
374
-					} else {
375
-						return new WSError(203, 'An error occured subscribing to this course');
376
-					}
377
-				}
378
-			}
379
-		}
380
-	}
345
+    /**
346
+     * Subscribe or unsubscribe user to a course (helper method)
347
+     *
348
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
349
+     * @param string Course id value.
350
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
351
+     * @param string User id value
352
+     * @param int Set to 1 to subscribe, 0 to unsubscribe
353
+     * @param int Status (STUDENT or TEACHER) Used for subscription only
354
+     * @return mixed True if subscription or unsubscription was successful, false otherwise
355
+     */
356
+    protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) {
357
+        $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
358
+        if($course_id instanceof WSError) {
359
+            return $course_id;
360
+        } else {
361
+            $user_id = $this->getUserId($user_id_field_name, $user_id_value);
362
+            if($user_id instanceof WSError) {
363
+                return $user_id;
364
+            } else {
365
+                $course_code = CourseManager::get_course_code_from_course_id($course_id);
366
+                if($state == 0) {
367
+                    // Unsubscribe user
368
+                    CourseManager::unsubscribe_user($user_id, $course_code);
369
+                    return true;
370
+                } else {
371
+                    // Subscribe user
372
+                    if(CourseManager::subscribe_user($user_id, $course_code, $status)) {
373
+                        return true;
374
+                    } else {
375
+                        return new WSError(203, 'An error occured subscribing to this course');
376
+                    }
377
+                }
378
+            }
379
+        }
380
+    }
381 381
 
382
-	/**
383
-	 * Subscribe user to a course
384
-	 *
385
-	 * @param string API secret key
386
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
-	 * @param string Course id value.
388
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
389
-	 * @param string User id value
390
-	 * @param int Status (1 = Teacher, 5 = Student)
391
-	 */
392
-	public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
-		$verifKey = $this->verifyKey($secret_key);
394
-		if($verifKey instanceof WSError) {
395
-			$this->handleError($verifKey);
396
-		} else {
397
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
-			if($result instanceof WSError) {
399
-				$this->handleError($result);
400
-			}
401
-		}
402
-	}
382
+    /**
383
+     * Subscribe user to a course
384
+     *
385
+     * @param string API secret key
386
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
387
+     * @param string Course id value.
388
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
389
+     * @param string User id value
390
+     * @param int Status (1 = Teacher, 5 = Student)
391
+     */
392
+    public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) {
393
+        $verifKey = $this->verifyKey($secret_key);
394
+        if($verifKey instanceof WSError) {
395
+            $this->handleError($verifKey);
396
+        } else {
397
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status);
398
+            if($result instanceof WSError) {
399
+                $this->handleError($result);
400
+            }
401
+        }
402
+    }
403 403
 
404
-	/**
405
-	 * Unsusbscribe user from course
406
-	 *
407
-	 * @param string API secret key
408
-	 * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
-	 * @param string Course id value.
410
-	 * @param string User id field name. Use "chamilo_user_id" to use internal id
411
-	 * @param string User id value
412
-	 */
413
-	public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
-		$verifKey = $this->verifyKey($secret_key);
415
-		if($verifKey instanceof WSError) {
416
-			$this->handleError($verifKey);
417
-		} else {
418
-			$result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
-			if($result instanceof WSError) {
420
-				$this->handleError($result);
421
-			}
422
-		}
423
-	}
404
+    /**
405
+     * Unsusbscribe user from course
406
+     *
407
+     * @param string API secret key
408
+     * @param string Course id field name. Use "chamilo_course_id" to use internal id
409
+     * @param string Course id value.
410
+     * @param string User id field name. Use "chamilo_user_id" to use internal id
411
+     * @param string User id value
412
+     */
413
+    public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) {
414
+        $verifKey = $this->verifyKey($secret_key);
415
+        if($verifKey instanceof WSError) {
416
+            $this->handleError($verifKey);
417
+        } else {
418
+            $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0);
419
+            if($result instanceof WSError) {
420
+                $this->handleError($result);
421
+            }
422
+        }
423
+    }
424 424
 
425
-	/**
426
-	 * Returns the descriptions of a course, along with their id
427
-	 *
428
-	 * @param string API secret key
429
-	 * @param string Course id field name
430
-	 * @param string Course id value
431
-	 * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
-	 */
433
-	public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
-		$verifKey = $this->verifyKey($secret_key);
435
-		if($verifKey instanceof WSError) {
436
-			$this->handleError($verifKey);
437
-		} else {
438
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
-			if($course_id instanceof WSError) {
440
-				return $course_id;
441
-			} else {
442
-				// Course exists, get its descriptions
443
-				$descriptions = CourseDescription::get_descriptions($course_id);
444
-				$results = array();
445
-				foreach($descriptions as $description) {
446
-					$results[] = array('course_desc_id' => $description->get_description_type(),
447
-										'course_desc_title' => $description->get_title(),
448
-										'course_desc_content' => $description->get_content());
449
-				}
450
-				return $results;
451
-			}
452
-		}
453
-	}
425
+    /**
426
+     * Returns the descriptions of a course, along with their id
427
+     *
428
+     * @param string API secret key
429
+     * @param string Course id field name
430
+     * @param string Course id value
431
+     * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content')
432
+     */
433
+    public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) {
434
+        $verifKey = $this->verifyKey($secret_key);
435
+        if($verifKey instanceof WSError) {
436
+            $this->handleError($verifKey);
437
+        } else {
438
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
439
+            if($course_id instanceof WSError) {
440
+                return $course_id;
441
+            } else {
442
+                // Course exists, get its descriptions
443
+                $descriptions = CourseDescription::get_descriptions($course_id);
444
+                $results = array();
445
+                foreach($descriptions as $description) {
446
+                    $results[] = array('course_desc_id' => $description->get_description_type(),
447
+                                        'course_desc_title' => $description->get_title(),
448
+                                        'course_desc_content' => $description->get_content());
449
+                }
450
+                return $results;
451
+            }
452
+        }
453
+    }
454 454
 
455 455
 
456
-	/**
457
-	 * Edit course description
458
-	 *
459
-	 * @param string API secret key
460
-	 * @param string Course id field name
461
-	 * @param string Course id value
462
-	 * @param int Category id from course description
463
-	 * @param string Description title
464
-	 * @param string Course description content
465
-	 */
466
-	public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
-		$verifKey = $this->verifyKey($secret_key);
468
-		if($verifKey instanceof WSError) {
469
-			$this->handleError($verifKey);
470
-		} else {
471
-			$course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
-			if($course_id instanceof WSError) {
473
-				return $course_id;
474
-			} else {
475
-				// Create the new course description
476
-				$cd = new CourseDescription();
477
-				$cd->set_description_type($course_desc_id);
478
-				$cd->set_title($course_desc_title);
479
-				$cd->set_content($course_desc_content);
480
-				$cd->set_session_id(0);
481
-				// Get course info
482
-				$course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
456
+    /**
457
+     * Edit course description
458
+     *
459
+     * @param string API secret key
460
+     * @param string Course id field name
461
+     * @param string Course id value
462
+     * @param int Category id from course description
463
+     * @param string Description title
464
+     * @param string Course description content
465
+     */
466
+    public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) {
467
+        $verifKey = $this->verifyKey($secret_key);
468
+        if($verifKey instanceof WSError) {
469
+            $this->handleError($verifKey);
470
+        } else {
471
+            $course_id = $this->getCourseId($course_id_field_name, $course_id_value);
472
+            if($course_id instanceof WSError) {
473
+                return $course_id;
474
+            } else {
475
+                // Create the new course description
476
+                $cd = new CourseDescription();
477
+                $cd->set_description_type($course_desc_id);
478
+                $cd->set_title($course_desc_title);
479
+                $cd->set_content($course_desc_content);
480
+                $cd->set_session_id(0);
481
+                // Get course info
482
+                $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id));
483 483
                 $cd->set_course_id($course_info['real_id']);
484
-				// Check if this course description exists
485
-				$descriptions = CourseDescription::get_descriptions($course_id);
486
-				$exists = false;
487
-				foreach($descriptions as $description) {
488
-					if($description->get_description_type() == $course_desc_id) {
489
-						$exists = true;
490
-					}
491
-				}
492
-				if (!$exists) {
493
-					$cd->set_progress(0);
494
-					$cd->insert();
495
-				} else {
496
-					$cd->update();
497
-				}
498
-			}
499
-		}
500
-	}
484
+                // Check if this course description exists
485
+                $descriptions = CourseDescription::get_descriptions($course_id);
486
+                $exists = false;
487
+                foreach($descriptions as $description) {
488
+                    if($description->get_description_type() == $course_desc_id) {
489
+                        $exists = true;
490
+                    }
491
+                }
492
+                if (!$exists) {
493
+                    $cd->set_progress(0);
494
+                    $cd->insert();
495
+                } else {
496
+                    $cd->update();
497
+                }
498
+            }
499
+        }
500
+    }
501 501
 }
Please login to merge, or discard this patch.