Completed
Push — master ( bf34f3...88111b )
by Michael
03:08
created
class/Form/Elements/SmartFormUploadElement.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,8 +19,8 @@
 block discarded – undo
19 19
 class SmartFormUploadElement extends \XoopsFormFile
20 20
 {
21 21
     /**
22
-     * @param $object
23
-     * @param $key
22
+     * @param string $object
23
+     * @param string $key
24 24
      */
25 25
     public function SmartFormFileElement($object, $key)
26 26
     {
Please login to merge, or discard this patch.
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -18,25 +18,25 @@
 block discarded – undo
18 18
  */
19 19
 class SmartFormUploadElement extends \XoopsFormFile
20 20
 {
21
-    /**
22
-     * @param $object
23
-     * @param $key
24
-     */
25
-    public function SmartFormFileElement($object, $key)
26
-    {
27
-        parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
28
-        $this->setExtra(' size=50');
29
-    }
21
+	/**
22
+	 * @param $object
23
+	 * @param $key
24
+	 */
25
+	public function SmartFormFileElement($object, $key)
26
+	{
27
+		parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0);
28
+		$this->setExtra(' size=50');
29
+	}
30 30
 
31
-    /**
32
-     * prepare HTML for output
33
-     *
34
-     * @return string HTML
35
-     */
36
-    public function render()
37
-    {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
31
+	/**
32
+	 * prepare HTML for output
33
+	 *
34
+	 * @return string HTML
35
+	 */
36
+	public function render()
37
+	{
38
+		return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39 39
                 <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . ">
40 40
                 <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>";
41
-    }
41
+	}
42 42
 }
Please login to merge, or discard this patch.
class/SmartDbTable.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@
 block discarded – undo
164 164
     }
165 165
 
166 166
     /**
167
-     * @param $field
167
+     * @param string $field
168 168
      * @return bool
169 169
      */
170 170
     public function fieldExists($field)
Please login to merge, or discard this patch.
Indentation   +499 added lines, -500 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@  discard block
 block discarded – undo
25 25
  * Contains the classes for updating database tables
26 26
  *
27 27
  * @license GNU
28
-
29 28
  */
30 29
 /**
31 30
  * SmartDbTable class
@@ -38,7 +37,7 @@  discard block
 block discarded – undo
38 37
  */
39 38
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
40 39
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
41
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
40
+	require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
42 41
 }
43 42
 /**
44 43
  * Include the language constants for the SmartObjectDBUpdater
@@ -46,7 +45,7 @@  discard block
 block discarded – undo
46 45
 global $xoopsConfig;
47 46
 $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
48 47
 if (!file_exists($common_file)) {
49
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
48
+	$common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
50 49
 }
51 50
 include $common_file;
52 51
 
@@ -55,501 +54,501 @@  discard block
 block discarded – undo
55 54
  */
56 55
 class SmartDbTable
57 56
 {
58
-    /**
59
-     * @var string $_name name of the table
60
-     */
61
-    public $_name;
62
-    /**
63
-     * @var string $_structure structure of the table
64
-     */
65
-    public $_structure;
66
-
67
-    /**
68
-     * @var array $_data containing valued of each records to be added
69
-     */
70
-    public $_data;
71
-
72
-    /**
73
-     * @var array $_alteredFields containing fields to be altered
74
-     */
75
-    public $_alteredFields;
76
-
77
-    /**
78
-     * @var array $_newFields containing new fields to be added
79
-     */
80
-    public $_newFields;
81
-
82
-    /**
83
-     * @var array $_droppedFields containing fields to be dropped
84
-     */
85
-    public $_droppedFields;
86
-
87
-    /**
88
-     * @var array $_flagForDrop flag table to drop it
89
-     */
90
-    public $_flagForDrop = false;
91
-
92
-    /**
93
-     * @var array $_updatedFields containing fields which values will be updated
94
-     */
95
-    public $_updatedFields;
96
-
97
-    /**
98
-     * @var array $_updatedFields containing fields which values will be updated
99
-     */ //felix
100
-    public $_updatedWhere;
101
-
102
-    public $_existingFieldsArray = false;
103
-
104
-    /**
105
-     * Constructor
106
-     *
107
-     * @param string $name name of the table
108
-     *
109
-     */
110
-    public function __construct($name)
111
-    {
112
-        $this->_name = $name;
113
-        $this->_data = [];
114
-    }
115
-
116
-    /**
117
-     * Return the table name, prefixed with site table prefix
118
-     *
119
-     * @return string table name
120
-     *
121
-     */
122
-    public function name()
123
-    {
124
-        global $xoopsDB;
125
-
126
-        return $xoopsDB->prefix($this->_name);
127
-    }
128
-
129
-    /**
130
-     * Checks if the table already exists in the database
131
-     *
132
-     * @return bool TRUE if it exists, FALSE if not
133
-     *
134
-     */
135
-    public function exists()
136
-    {
137
-        return smart_TableExists($this->_name);
138
-    }
139
-
140
-    /**
141
-     * @return mixed
142
-     */
143
-    public function getExistingFieldsArray()
144
-    {
145
-        global $xoopsDB;
146
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
147
-        while (false !== ($existing_field = $xoopsDB->fetchArray($result))) {
148
-            $fields[$existing_field['Field']] = $existing_field['Type'];
149
-            if ('YES' !== $existing_field['Null']) {
150
-                $fields[$existing_field['Field']] .= ' NOT NULL';
151
-            }
152
-            if ($existing_field['Extra']) {
153
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
154
-            }
155
-            if (!(null === $existing_field['Default'])
156
-                && ($existing_field['Default']
157
-                    || '' === $existing_field['Default']
158
-                    || 0 == $existing_field['Default'])) {
159
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
160
-            }
161
-        }
162
-
163
-        return $fields;
164
-    }
165
-
166
-    /**
167
-     * @param $field
168
-     * @return bool
169
-     */
170
-    public function fieldExists($field)
171
-    {
172
-        $existingFields = $this->getExistingFieldsArray();
173
-
174
-        return isset($existingFields[$field]);
175
-    }
176
-
177
-    /**
178
-     * Set the table structure
179
-     *
180
-     * Example:
181
-     *
182
-     *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
183
-     *                `date` int(11) NOT NULL default '0',
184
-     *                `status` int(1) NOT NULL default '-1',
185
-     *                `itemid` int(11) NOT NULL default '0',
186
-     *                `uid` int(11) NOT NULL default '0',
187
-     *                `price` float NOT NULL default '0',
188
-     *                `currency` varchar(100) NOT NULL default '',
189
-     *                PRIMARY KEY  (`transactionid`)");
190
-     *
191
-     * @param string $structure table structure
192
-     *
193
-     */
194
-    public function setStructure($structure)
195
-    {
196
-        $this->_structure = $structure;
197
-    }
198
-
199
-    /**
200
-     * Return the table structure
201
-     *
202
-     * @return string table structure
203
-     *
204
-     */
205
-    public function getStructure()
206
-    {
207
-        return sprintf($this->_structure, $this->name());
208
-    }
209
-
210
-    /**
211
-     * Add values of a record to be added
212
-     *
213
-     * @param string $data values of a record
214
-     *
215
-     */
216
-    public function setData($data)
217
-    {
218
-        $this->_data[] = $data;
219
-    }
220
-
221
-    /**
222
-     * Get the data array
223
-     *
224
-     * @return array containing the records values to be added
225
-     *
226
-     */
227
-    public function getData()
228
-    {
229
-        return $this->_data;
230
-    }
231
-
232
-    /**
233
-     * Use to insert data in a table
234
-     *
235
-     * @return bool true if success, false if an error occured
236
-     *
237
-     */
238
-    public function addData()
239
-    {
240
-        global $xoopsDB;
241
-        foreach ($this->getData() as $data) {
242
-            $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
243
-            $ret   = $xoopsDB->query($query);
244
-            if (!$ret) {
245
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
246
-            } else {
247
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
248
-            }
249
-        }
250
-
251
-        return $ret;
252
-    }
253
-
254
-    /**
255
-     * Add a field to be added
256
-     *
257
-     * @param string $name       name of the field
258
-     * @param string $properties properties of the field
259
-     * @param bool   $newname
260
-     * @param bool   $showerror
261
-     */
262
-    public function addAlteredField($name, $properties, $newname = false, $showerror = true)
263
-    {
264
-        $field['name']          = $name;
265
-        $field['properties']    = $properties;
266
-        $field['showerror']     = $showerror;
267
-        $field['newname']       = $newname;
268
-        $this->_alteredFields[] = $field;
269
-    }
270
-    /**
271
-     * Invert values 0 to 1 and 1 to 0
272
-     *
273
-     * @param string $name name of the field
274
-     * @param        $newValue
275
-     * @param        $oldValue
276
-     * @internal param string $old old propertie
277
-     * @internal param string $new new propertie
278
-     */ //felix
279
-    public function addUpdatedWhere($name, $newValue, $oldValue)
280
-    {
281
-        $field['name']         = $name;
282
-        $field['value']        = $newValue;
283
-        $field['where']        = $oldValue;
284
-        $this->_updatedWhere[] = $field;
285
-    }
286
-
287
-    /**
288
-     * Add new field of a record to be added
289
-     *
290
-     * @param string $name       name of the field
291
-     * @param string $properties properties of the field
292
-     *
293
-     */
294
-    public function addNewField($name, $properties)
295
-    {
296
-        $field['name']       = $name;
297
-        $field['properties'] = $properties;
298
-        $this->_newFields[]  = $field;
299
-    }
300
-
301
-    /**
302
-     * Get fields that need to be altered
303
-     *
304
-     * @return array fields that need to be altered
305
-     *
306
-     */
307
-    public function getAlteredFields()
308
-    {
309
-        return $this->_alteredFields;
310
-    }
311
-
312
-    /**
313
-     * Add field for which the value will be updated
314
-     *
315
-     * @param string $name  name of the field
316
-     * @param string $value value to be set
317
-     *
318
-     */
319
-    public function addUpdatedField($name, $value)
320
-    {
321
-        $field['name']          = $name;
322
-        $field['value']         = $value;
323
-        $this->_updatedFields[] = $field;
324
-    }
325
-
326
-    /**
327
-     * Get new fields to be added
328
-     *
329
-     * @return array fields to be added
330
-     *
331
-     */
332
-    public function getNewFields()
333
-    {
334
-        return $this->_newFields;
335
-    }
336
-
337
-    /**
338
-     * Get fields which values need to be updated
339
-     *
340
-     * @return array fields which values need to be updated
341
-     *
342
-     */
343
-    public function getUpdatedFields()
344
-    {
345
-        return $this->_updatedFields;
346
-    }
347
-    /**
348
-     * Get fields which values need to be updated
349
-     *
350
-     * @return array fields which values need to be updated
351
-     *
352
-     */ //felix
353
-    public function getUpdatedWhere()
354
-    {
355
-        return $this->_updatedWhere;
356
-    }
357
-
358
-    /**
359
-     * Add values of a record to be added
360
-     *
361
-     * @param string $name name of the field
362
-     *
363
-     */
364
-    public function addDroppedField($name)
365
-    {
366
-        $this->_droppedFields[] = $name;
367
-    }
368
-
369
-    /**
370
-     * Get fields that need to be dropped
371
-     *
372
-     * @return array fields that need to be dropped
373
-     *
374
-     */
375
-    public function getDroppedFields()
376
-    {
377
-        return $this->_droppedFields;
378
-    }
379
-
380
-    /**
381
-     * Set the flag to drop the table
382
-     *
383
-     */
384
-    public function setFlagForDrop()
385
-    {
386
-        $this->_flagForDrop = true;
387
-    }
388
-
389
-    /**
390
-     * Use to create a table
391
-     *
392
-     * @return bool true if success, false if an error occured
393
-     *
394
-     */
395
-    public function createTable()
396
-    {
397
-        global $xoopsDB;
398
-        $query = $this->getStructure();
399
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
400
-        //xoops_debug($query);
401
-        $ret = $xoopsDB->query($query);
402
-        if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
404
-        } else {
405
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
406
-        }
407
-
408
-        return $ret;
409
-    }
410
-
411
-    /**
412
-     * Use to drop a table
413
-     *
414
-     * @return bool true if success, false if an error occured
415
-     *
416
-     */
417
-    public function dropTable()
418
-    {
419
-        global $xoopsDB;
420
-        $query = sprintf('DROP TABLE %s', $this->name());
421
-        $ret   = $xoopsDB->query($query);
422
-        if (!$ret) {
423
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
424
-
425
-            return false;
426
-        } else {
427
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
428
-
429
-            return true;
430
-        }
431
-    }
432
-
433
-    /**
434
-     * Use to alter a table
435
-     *
436
-     * @return bool true if success, false if an error occured
437
-     *
438
-     */
439
-    public function alterTable()
440
-    {
441
-        global $xoopsDB;
442
-        $ret = true;
443
-
444
-        foreach ($this->getAlteredFields() as $alteredField) {
445
-            if (!$alteredField['newname']) {
446
-                $alteredField['newname'] = $alteredField['name'];
447
-            }
448
-
449
-            $query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
450
-            $ret   = $ret && $xoopsDB->query($query);
451
-            if ($alteredField['showerror']) {
452
-                if (!$ret) {
453
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
454
-                } else {
455
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
456
-                }
457
-            }
458
-        }
459
-
460
-        return $ret;
461
-    }
462
-
463
-    /**
464
-     * Use to add new fileds in the table
465
-     *
466
-     * @return bool true if success, false if an error occured
467
-     *
468
-     */
469
-    public function addNewFields()
470
-    {
471
-        global $xoopsDB;
472
-        $ret = true;
473
-        foreach ($this->getNewFields() as $newField) {
474
-            $query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
475
-            //echo $query;
476
-            $ret = $ret && $xoopsDB->query($query);
477
-            if (!$ret) {
478
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
479
-            } else {
480
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
481
-            }
482
-        }
483
-
484
-        return $ret;
485
-    }
486
-
487
-    /**
488
-     * Use to update fields values
489
-     *
490
-     * @return bool true if success, false if an error occured
491
-     *
492
-     */
493
-    public function updateFieldsValues()
494
-    {
495
-        global $xoopsDB;
496
-        $ret = true;
497
-        foreach ($this->getUpdatedFields() as $updatedField) {
498
-            $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
499
-            $ret   = $ret && $xoopsDB->query($query);
500
-            if (!$ret) {
501
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
502
-            } else {
503
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
504
-            }
505
-        }
506
-
507
-        return $ret;
508
-    }
509
-    /**
510
-     * Use to update fields values
511
-     *
512
-     * @return bool true if success, false if an error occured
513
-     *
514
-     */ //felix
515
-    public function updateWhereValues()
516
-    {
517
-        global $xoopsDB;
518
-        $ret = true;
519
-        foreach ($this->getUpdatedWhere() as $updatedWhere) {
520
-            $query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
521
-            //echo $query."<br>";
522
-            $ret = $ret && $xoopsDB->query($query);
523
-            if (!$ret) {
524
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
525
-            } else {
526
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
527
-            }
528
-        }
529
-
530
-        return $ret;
531
-    }
532
-
533
-    /**
534
-     * Use to drop fields
535
-     *
536
-     * @return bool true if success, false if an error occured
537
-     *
538
-     */
539
-    public function dropFields()
540
-    {
541
-        global $xoopsDB;
542
-        $ret = true;
543
-        foreach ($this->getDroppedFields() as $droppedField) {
544
-            $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
545
-            $ret   = $ret && $xoopsDB->query($query);
546
-            if (!$ret) {
547
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
548
-            } else {
549
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
550
-            }
551
-        }
552
-
553
-        return $ret;
554
-    }
57
+	/**
58
+	 * @var string $_name name of the table
59
+	 */
60
+	public $_name;
61
+	/**
62
+	 * @var string $_structure structure of the table
63
+	 */
64
+	public $_structure;
65
+
66
+	/**
67
+	 * @var array $_data containing valued of each records to be added
68
+	 */
69
+	public $_data;
70
+
71
+	/**
72
+	 * @var array $_alteredFields containing fields to be altered
73
+	 */
74
+	public $_alteredFields;
75
+
76
+	/**
77
+	 * @var array $_newFields containing new fields to be added
78
+	 */
79
+	public $_newFields;
80
+
81
+	/**
82
+	 * @var array $_droppedFields containing fields to be dropped
83
+	 */
84
+	public $_droppedFields;
85
+
86
+	/**
87
+	 * @var array $_flagForDrop flag table to drop it
88
+	 */
89
+	public $_flagForDrop = false;
90
+
91
+	/**
92
+	 * @var array $_updatedFields containing fields which values will be updated
93
+	 */
94
+	public $_updatedFields;
95
+
96
+	/**
97
+	 * @var array $_updatedFields containing fields which values will be updated
98
+	 */ //felix
99
+	public $_updatedWhere;
100
+
101
+	public $_existingFieldsArray = false;
102
+
103
+	/**
104
+	 * Constructor
105
+	 *
106
+	 * @param string $name name of the table
107
+	 *
108
+	 */
109
+	public function __construct($name)
110
+	{
111
+		$this->_name = $name;
112
+		$this->_data = [];
113
+	}
114
+
115
+	/**
116
+	 * Return the table name, prefixed with site table prefix
117
+	 *
118
+	 * @return string table name
119
+	 *
120
+	 */
121
+	public function name()
122
+	{
123
+		global $xoopsDB;
124
+
125
+		return $xoopsDB->prefix($this->_name);
126
+	}
127
+
128
+	/**
129
+	 * Checks if the table already exists in the database
130
+	 *
131
+	 * @return bool TRUE if it exists, FALSE if not
132
+	 *
133
+	 */
134
+	public function exists()
135
+	{
136
+		return smart_TableExists($this->_name);
137
+	}
138
+
139
+	/**
140
+	 * @return mixed
141
+	 */
142
+	public function getExistingFieldsArray()
143
+	{
144
+		global $xoopsDB;
145
+		$result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
146
+		while (false !== ($existing_field = $xoopsDB->fetchArray($result))) {
147
+			$fields[$existing_field['Field']] = $existing_field['Type'];
148
+			if ('YES' !== $existing_field['Null']) {
149
+				$fields[$existing_field['Field']] .= ' NOT NULL';
150
+			}
151
+			if ($existing_field['Extra']) {
152
+				$fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
153
+			}
154
+			if (!(null === $existing_field['Default'])
155
+				&& ($existing_field['Default']
156
+					|| '' === $existing_field['Default']
157
+					|| 0 == $existing_field['Default'])) {
158
+				$fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
159
+			}
160
+		}
161
+
162
+		return $fields;
163
+	}
164
+
165
+	/**
166
+	 * @param $field
167
+	 * @return bool
168
+	 */
169
+	public function fieldExists($field)
170
+	{
171
+		$existingFields = $this->getExistingFieldsArray();
172
+
173
+		return isset($existingFields[$field]);
174
+	}
175
+
176
+	/**
177
+	 * Set the table structure
178
+	 *
179
+	 * Example:
180
+	 *
181
+	 *      $table->setStructure("`transactionid` int(11) NOT NULL auto_increment,
182
+	 *                `date` int(11) NOT NULL default '0',
183
+	 *                `status` int(1) NOT NULL default '-1',
184
+	 *                `itemid` int(11) NOT NULL default '0',
185
+	 *                `uid` int(11) NOT NULL default '0',
186
+	 *                `price` float NOT NULL default '0',
187
+	 *                `currency` varchar(100) NOT NULL default '',
188
+	 *                PRIMARY KEY  (`transactionid`)");
189
+	 *
190
+	 * @param string $structure table structure
191
+	 *
192
+	 */
193
+	public function setStructure($structure)
194
+	{
195
+		$this->_structure = $structure;
196
+	}
197
+
198
+	/**
199
+	 * Return the table structure
200
+	 *
201
+	 * @return string table structure
202
+	 *
203
+	 */
204
+	public function getStructure()
205
+	{
206
+		return sprintf($this->_structure, $this->name());
207
+	}
208
+
209
+	/**
210
+	 * Add values of a record to be added
211
+	 *
212
+	 * @param string $data values of a record
213
+	 *
214
+	 */
215
+	public function setData($data)
216
+	{
217
+		$this->_data[] = $data;
218
+	}
219
+
220
+	/**
221
+	 * Get the data array
222
+	 *
223
+	 * @return array containing the records values to be added
224
+	 *
225
+	 */
226
+	public function getData()
227
+	{
228
+		return $this->_data;
229
+	}
230
+
231
+	/**
232
+	 * Use to insert data in a table
233
+	 *
234
+	 * @return bool true if success, false if an error occured
235
+	 *
236
+	 */
237
+	public function addData()
238
+	{
239
+		global $xoopsDB;
240
+		foreach ($this->getData() as $data) {
241
+			$query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
242
+			$ret   = $xoopsDB->query($query);
243
+			if (!$ret) {
244
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
245
+			} else {
246
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
247
+			}
248
+		}
249
+
250
+		return $ret;
251
+	}
252
+
253
+	/**
254
+	 * Add a field to be added
255
+	 *
256
+	 * @param string $name       name of the field
257
+	 * @param string $properties properties of the field
258
+	 * @param bool   $newname
259
+	 * @param bool   $showerror
260
+	 */
261
+	public function addAlteredField($name, $properties, $newname = false, $showerror = true)
262
+	{
263
+		$field['name']          = $name;
264
+		$field['properties']    = $properties;
265
+		$field['showerror']     = $showerror;
266
+		$field['newname']       = $newname;
267
+		$this->_alteredFields[] = $field;
268
+	}
269
+	/**
270
+	 * Invert values 0 to 1 and 1 to 0
271
+	 *
272
+	 * @param string $name name of the field
273
+	 * @param        $newValue
274
+	 * @param        $oldValue
275
+	 * @internal param string $old old propertie
276
+	 * @internal param string $new new propertie
277
+	 */ //felix
278
+	public function addUpdatedWhere($name, $newValue, $oldValue)
279
+	{
280
+		$field['name']         = $name;
281
+		$field['value']        = $newValue;
282
+		$field['where']        = $oldValue;
283
+		$this->_updatedWhere[] = $field;
284
+	}
285
+
286
+	/**
287
+	 * Add new field of a record to be added
288
+	 *
289
+	 * @param string $name       name of the field
290
+	 * @param string $properties properties of the field
291
+	 *
292
+	 */
293
+	public function addNewField($name, $properties)
294
+	{
295
+		$field['name']       = $name;
296
+		$field['properties'] = $properties;
297
+		$this->_newFields[]  = $field;
298
+	}
299
+
300
+	/**
301
+	 * Get fields that need to be altered
302
+	 *
303
+	 * @return array fields that need to be altered
304
+	 *
305
+	 */
306
+	public function getAlteredFields()
307
+	{
308
+		return $this->_alteredFields;
309
+	}
310
+
311
+	/**
312
+	 * Add field for which the value will be updated
313
+	 *
314
+	 * @param string $name  name of the field
315
+	 * @param string $value value to be set
316
+	 *
317
+	 */
318
+	public function addUpdatedField($name, $value)
319
+	{
320
+		$field['name']          = $name;
321
+		$field['value']         = $value;
322
+		$this->_updatedFields[] = $field;
323
+	}
324
+
325
+	/**
326
+	 * Get new fields to be added
327
+	 *
328
+	 * @return array fields to be added
329
+	 *
330
+	 */
331
+	public function getNewFields()
332
+	{
333
+		return $this->_newFields;
334
+	}
335
+
336
+	/**
337
+	 * Get fields which values need to be updated
338
+	 *
339
+	 * @return array fields which values need to be updated
340
+	 *
341
+	 */
342
+	public function getUpdatedFields()
343
+	{
344
+		return $this->_updatedFields;
345
+	}
346
+	/**
347
+	 * Get fields which values need to be updated
348
+	 *
349
+	 * @return array fields which values need to be updated
350
+	 *
351
+	 */ //felix
352
+	public function getUpdatedWhere()
353
+	{
354
+		return $this->_updatedWhere;
355
+	}
356
+
357
+	/**
358
+	 * Add values of a record to be added
359
+	 *
360
+	 * @param string $name name of the field
361
+	 *
362
+	 */
363
+	public function addDroppedField($name)
364
+	{
365
+		$this->_droppedFields[] = $name;
366
+	}
367
+
368
+	/**
369
+	 * Get fields that need to be dropped
370
+	 *
371
+	 * @return array fields that need to be dropped
372
+	 *
373
+	 */
374
+	public function getDroppedFields()
375
+	{
376
+		return $this->_droppedFields;
377
+	}
378
+
379
+	/**
380
+	 * Set the flag to drop the table
381
+	 *
382
+	 */
383
+	public function setFlagForDrop()
384
+	{
385
+		$this->_flagForDrop = true;
386
+	}
387
+
388
+	/**
389
+	 * Use to create a table
390
+	 *
391
+	 * @return bool true if success, false if an error occured
392
+	 *
393
+	 */
394
+	public function createTable()
395
+	{
396
+		global $xoopsDB;
397
+		$query = $this->getStructure();
398
+		$query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
399
+		//xoops_debug($query);
400
+		$ret = $xoopsDB->query($query);
401
+		if (!$ret) {
402
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
403
+		} else {
404
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
405
+		}
406
+
407
+		return $ret;
408
+	}
409
+
410
+	/**
411
+	 * Use to drop a table
412
+	 *
413
+	 * @return bool true if success, false if an error occured
414
+	 *
415
+	 */
416
+	public function dropTable()
417
+	{
418
+		global $xoopsDB;
419
+		$query = sprintf('DROP TABLE %s', $this->name());
420
+		$ret   = $xoopsDB->query($query);
421
+		if (!$ret) {
422
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
423
+
424
+			return false;
425
+		} else {
426
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
427
+
428
+			return true;
429
+		}
430
+	}
431
+
432
+	/**
433
+	 * Use to alter a table
434
+	 *
435
+	 * @return bool true if success, false if an error occured
436
+	 *
437
+	 */
438
+	public function alterTable()
439
+	{
440
+		global $xoopsDB;
441
+		$ret = true;
442
+
443
+		foreach ($this->getAlteredFields() as $alteredField) {
444
+			if (!$alteredField['newname']) {
445
+				$alteredField['newname'] = $alteredField['name'];
446
+			}
447
+
448
+			$query = sprintf('ALTER TABLE `%s` CHANGE `%s` `%s` %s', $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']);
449
+			$ret   = $ret && $xoopsDB->query($query);
450
+			if ($alteredField['showerror']) {
451
+				if (!$ret) {
452
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
453
+				} else {
454
+					echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
455
+				}
456
+			}
457
+		}
458
+
459
+		return $ret;
460
+	}
461
+
462
+	/**
463
+	 * Use to add new fileds in the table
464
+	 *
465
+	 * @return bool true if success, false if an error occured
466
+	 *
467
+	 */
468
+	public function addNewFields()
469
+	{
470
+		global $xoopsDB;
471
+		$ret = true;
472
+		foreach ($this->getNewFields() as $newField) {
473
+			$query = sprintf('ALTER TABLE `%s` ADD `%s` %s', $this->name(), $newField['name'], $newField['properties']);
474
+			//echo $query;
475
+			$ret = $ret && $xoopsDB->query($query);
476
+			if (!$ret) {
477
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
478
+			} else {
479
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
480
+			}
481
+		}
482
+
483
+		return $ret;
484
+	}
485
+
486
+	/**
487
+	 * Use to update fields values
488
+	 *
489
+	 * @return bool true if success, false if an error occured
490
+	 *
491
+	 */
492
+	public function updateFieldsValues()
493
+	{
494
+		global $xoopsDB;
495
+		$ret = true;
496
+		foreach ($this->getUpdatedFields() as $updatedField) {
497
+			$query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
498
+			$ret   = $ret && $xoopsDB->query($query);
499
+			if (!$ret) {
500
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
501
+			} else {
502
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
503
+			}
504
+		}
505
+
506
+		return $ret;
507
+	}
508
+	/**
509
+	 * Use to update fields values
510
+	 *
511
+	 * @return bool true if success, false if an error occured
512
+	 *
513
+	 */ //felix
514
+	public function updateWhereValues()
515
+	{
516
+		global $xoopsDB;
517
+		$ret = true;
518
+		foreach ($this->getUpdatedWhere() as $updatedWhere) {
519
+			$query = sprintf('UPDATE %s SET %s = %s WHERE %s  %s', $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']);
520
+			//echo $query."<br>";
521
+			$ret = $ret && $xoopsDB->query($query);
522
+			if (!$ret) {
523
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
524
+			} else {
525
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
526
+			}
527
+		}
528
+
529
+		return $ret;
530
+	}
531
+
532
+	/**
533
+	 * Use to drop fields
534
+	 *
535
+	 * @return bool true if success, false if an error occured
536
+	 *
537
+	 */
538
+	public function dropFields()
539
+	{
540
+		global $xoopsDB;
541
+		$ret = true;
542
+		foreach ($this->getDroppedFields() as $droppedField) {
543
+			$query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
544
+			$ret   = $ret && $xoopsDB->query($query);
545
+			if (!$ret) {
546
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
547
+			} else {
548
+				echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
549
+			}
550
+		}
551
+
552
+		return $ret;
553
+	}
555 554
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
  */
39 39
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
40 40
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
41
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
41
+    require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
42 42
 }
43 43
 /**
44 44
  * Include the language constants for the SmartObjectDBUpdater
45 45
  */
46 46
 global $xoopsConfig;
47
-$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
47
+$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php';
48 48
 if (!file_exists($common_file)) {
49
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
49
+    $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php';
50 50
 }
51 51
 include $common_file;
52 52
 
@@ -143,20 +143,20 @@  discard block
 block discarded – undo
143 143
     public function getExistingFieldsArray()
144 144
     {
145 145
         global $xoopsDB;
146
-        $result = $xoopsDB->query('SHOW COLUMNS FROM ' . $this->name());
146
+        $result = $xoopsDB->query('SHOW COLUMNS FROM '.$this->name());
147 147
         while (false !== ($existing_field = $xoopsDB->fetchArray($result))) {
148 148
             $fields[$existing_field['Field']] = $existing_field['Type'];
149 149
             if ('YES' !== $existing_field['Null']) {
150 150
                 $fields[$existing_field['Field']] .= ' NOT NULL';
151 151
             }
152 152
             if ($existing_field['Extra']) {
153
-                $fields[$existing_field['Field']] .= ' ' . $existing_field['Extra'];
153
+                $fields[$existing_field['Field']] .= ' '.$existing_field['Extra'];
154 154
             }
155 155
             if (!(null === $existing_field['Default'])
156 156
                 && ($existing_field['Default']
157 157
                     || '' === $existing_field['Default']
158 158
                     || 0 == $existing_field['Default'])) {
159
-                $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'";
159
+                $fields[$existing_field['Field']] .= " default '".$existing_field['Default']."'";
160 160
             }
161 161
         }
162 162
 
@@ -242,9 +242,9 @@  discard block
 block discarded – undo
242 242
             $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data);
243 243
             $ret   = $xoopsDB->query($query);
244 244
             if (!$ret) {
245
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . '<br>';
245
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()).'<br>';
246 246
             } else {
247
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . '<br>';
247
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_ADD_DATA, $this->name()).'<br>';
248 248
             }
249 249
         }
250 250
 
@@ -396,13 +396,13 @@  discard block
 block discarded – undo
396 396
     {
397 397
         global $xoopsDB;
398 398
         $query = $this->getStructure();
399
-        $query = 'CREATE TABLE `' . $this->name() . '` (' . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
399
+        $query = 'CREATE TABLE `'.$this->name().'` ('.$query.") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'";
400 400
         //xoops_debug($query);
401 401
         $ret = $xoopsDB->query($query);
402 402
         if (!$ret) {
403
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
403
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
404 404
         } else {
405
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . '<br>';
405
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CREATE_TABLE, $this->name()).'<br>';
406 406
         }
407 407
 
408 408
         return $ret;
@@ -420,11 +420,11 @@  discard block
 block discarded – undo
420 420
         $query = sprintf('DROP TABLE %s', $this->name());
421 421
         $ret   = $xoopsDB->query($query);
422 422
         if (!$ret) {
423
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
423
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
424 424
 
425 425
             return false;
426 426
         } else {
427
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . '<br>';
427
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROP_TABLE, $this->name()).'<br>';
428 428
 
429 429
             return true;
430 430
         }
@@ -450,9 +450,9 @@  discard block
 block discarded – undo
450 450
             $ret   = $ret && $xoopsDB->query($query);
451 451
             if ($alteredField['showerror']) {
452 452
                 if (!$ret) {
453
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
453
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()).' ('.$xoopsDB->error().')<br>';
454 454
                 } else {
455
-                    echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . '<br>';
455
+                    echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()).'<br>';
456 456
                 }
457 457
             }
458 458
         }
@@ -475,9 +475,9 @@  discard block
 block discarded – undo
475 475
             //echo $query;
476 476
             $ret = $ret && $xoopsDB->query($query);
477 477
             if (!$ret) {
478
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . '<br>';
478
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()).'<br>';
479 479
             } else {
480
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . '<br>';
480
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()).'<br>';
481 481
             }
482 482
         }
483 483
 
@@ -498,9 +498,9 @@  discard block
 block discarded – undo
498 498
             $query = sprintf('UPDATE %s SET %s = %s', $this->name(), $updatedField['name'], $updatedField['value']);
499 499
             $ret   = $ret && $xoopsDB->query($query);
500 500
             if (!$ret) {
501
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
501
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
502 502
             } else {
503
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
503
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
504 504
             }
505 505
         }
506 506
 
@@ -521,9 +521,9 @@  discard block
 block discarded – undo
521 521
             //echo $query."<br>";
522 522
             $ret = $ret && $xoopsDB->query($query);
523 523
             if (!$ret) {
524
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
524
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()).' ('.$xoopsDB->error().')<br>';
525 525
             } else {
526
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . '<br>';
526
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()).'<br>';
527 527
             }
528 528
         }
529 529
 
@@ -544,9 +544,9 @@  discard block
 block discarded – undo
544 544
             $query = sprintf('ALTER TABLE %s DROP %s', $this->name(), $droppedField);
545 545
             $ret   = $ret && $xoopsDB->query($query);
546 546
             if (!$ret) {
547
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()) . ' (' . $xoopsDB->error() . ')<br>';
547
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD_ERR, $droppedField, $this->name()).' ('.$xoopsDB->error().')<br>';
548 548
             } else {
549
-                echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()) . '<br>';
549
+                echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_DROPFIELD, $droppedField, $this->name()).'<br>';
550 550
             }
551 551
         }
552 552
 
Please login to merge, or discard this patch.
class/SmartObjectColumn.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
 
34 34
     /**
35 35
      * SmartObjectColumn constructor.
36
-     * @param        $keyname
36
+     * @param        string $keyname
37 37
      * @param string $align
38 38
      * @param bool   $width
39 39
      * @param bool   $customMethodForValue
Please login to merge, or discard this patch.
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -23,82 +23,82 @@
 block discarded – undo
23 23
  */
24 24
 class SmartObjectColumn
25 25
 {
26
-    public $_keyname;
27
-    public $_align;
28
-    public $_width;
29
-    public $_customMethodForValue;
30
-    public $_extraParams;
31
-    public $_sortable;
32
-    public $_customCaption;
26
+	public $_keyname;
27
+	public $_align;
28
+	public $_width;
29
+	public $_customMethodForValue;
30
+	public $_extraParams;
31
+	public $_sortable;
32
+	public $_customCaption;
33 33
 
34
-    /**
35
-     * SmartObjectColumn constructor.
36
-     * @param        $keyname
37
-     * @param string $align
38
-     * @param bool   $width
39
-     * @param bool   $customMethodForValue
40
-     * @param bool   $param
41
-     * @param bool   $customCaption
42
-     * @param bool   $sortable
43
-     */
44
-    public function __construct(
45
-        $keyname,
46
-        $align = 'left',
47
-        $width = false,
48
-        $customMethodForValue = false,
49
-        $param = false,
50
-        $customCaption = false,
51
-        $sortable = true
52
-    ) {
53
-        $this->_keyname              = $keyname;
54
-        $this->_align                = $align;
55
-        $this->_width                = $width;
56
-        $this->_customMethodForValue = $customMethodForValue;
57
-        $this->_sortable             = $sortable;
58
-        $this->_param                = $param;
59
-        $this->_customCaption        = $customCaption;
60
-    }
34
+	/**
35
+	 * SmartObjectColumn constructor.
36
+	 * @param        $keyname
37
+	 * @param string $align
38
+	 * @param bool   $width
39
+	 * @param bool   $customMethodForValue
40
+	 * @param bool   $param
41
+	 * @param bool   $customCaption
42
+	 * @param bool   $sortable
43
+	 */
44
+	public function __construct(
45
+		$keyname,
46
+		$align = 'left',
47
+		$width = false,
48
+		$customMethodForValue = false,
49
+		$param = false,
50
+		$customCaption = false,
51
+		$sortable = true
52
+	) {
53
+		$this->_keyname              = $keyname;
54
+		$this->_align                = $align;
55
+		$this->_width                = $width;
56
+		$this->_customMethodForValue = $customMethodForValue;
57
+		$this->_sortable             = $sortable;
58
+		$this->_param                = $param;
59
+		$this->_customCaption        = $customCaption;
60
+	}
61 61
 
62
-    public function getKeyName()
63
-    {
64
-        return $this->_keyname;
65
-    }
62
+	public function getKeyName()
63
+	{
64
+		return $this->_keyname;
65
+	}
66 66
 
67
-    /**
68
-     * @return string
69
-     */
70
-    public function getAlign()
71
-    {
72
-        return $this->_align;
73
-    }
67
+	/**
68
+	 * @return string
69
+	 */
70
+	public function getAlign()
71
+	{
72
+		return $this->_align;
73
+	}
74 74
 
75
-    /**
76
-     * @return bool
77
-     */
78
-    public function isSortable()
79
-    {
80
-        return $this->_sortable;
81
-    }
75
+	/**
76
+	 * @return bool
77
+	 */
78
+	public function isSortable()
79
+	{
80
+		return $this->_sortable;
81
+	}
82 82
 
83
-    /**
84
-     * @return bool|string
85
-     */
86
-    public function getWidth()
87
-    {
88
-        if ($this->_width) {
89
-            $ret = $this->_width;
90
-        } else {
91
-            $ret = '';
92
-        }
83
+	/**
84
+	 * @return bool|string
85
+	 */
86
+	public function getWidth()
87
+	{
88
+		if ($this->_width) {
89
+			$ret = $this->_width;
90
+		} else {
91
+			$ret = '';
92
+		}
93 93
 
94
-        return $ret;
95
-    }
94
+		return $ret;
95
+	}
96 96
 
97
-    /**
98
-     * @return bool
99
-     */
100
-    public function getCustomCaption()
101
-    {
102
-        return $this->_customCaption;
103
-    }
97
+	/**
98
+	 * @return bool
99
+	 */
100
+	public function getCustomCaption()
101
+	{
102
+		return $this->_customCaption;
103
+	}
104 104
 }
Please login to merge, or discard this patch.
class/SmartObjectController.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
 
127 127
     /**
128 128
      * @param        $smartObj
129
-     * @param        $objectid
130
-     * @param        $created_success_msg
131
-     * @param        $modified_success_msg
129
+     * @param        integer $objectid
130
+     * @param        string $created_success_msg
131
+     * @param        string $modified_success_msg
132 132
      * @param  bool  $redirect_page
133 133
      * @param  bool  $debug
134 134
      * @return mixed
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     }
441 441
 
442 442
     /**
443
-     * @param         $smartObj
443
+     * @param         SmartMlObject $smartObj
444 444
      * @param  bool   $onlyUrl
445 445
      * @param  bool   $withimage
446 446
      * @return string
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
     }
499 499
 
500 500
     /**
501
-     * @param $smartObj
501
+     * @param BaseSmartObject $smartObj
502 502
      * @return string
503 503
      */
504 504
     public function getPrintAndMailLink($smartObj)
Please login to merge, or discard this patch.
Indentation   +506 added lines, -506 removed lines patch added patch discarded remove patch
@@ -33,511 +33,511 @@
 block discarded – undo
33 33
  */
34 34
 class SmartObjectController
35 35
 {
36
-    public $handler;
37
-
38
-    /**
39
-     * SmartObjectController constructor.
40
-     * @param $handler
41
-     */
42
-    public function __construct($handler)
43
-    {
44
-        $this->handler = $handler;
45
-    }
46
-
47
-    /**
48
-     * @param $smartObj
49
-     */
50
-    public function postDataToObject(&$smartObj)
51
-    {
52
-        foreach (array_keys($smartObj->vars) as $key) {
53
-            switch ($smartObj->vars[$key]['data_type']) {
54
-                case XOBJ_DTYPE_IMAGE:
55
-                    if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) {
56
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
57
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
58
-                        if (file_exists($oldFile)) {
59
-                            unlink($oldFile);
60
-                        }
61
-                    }
62
-                    if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
64
-                        $smartObj->setVar($key, '');
65
-                        if (file_exists($oldFile)) {
66
-                            unlink($oldFile);
67
-                        }
68
-                    }
69
-                    break;
70
-
71
-                case XOBJ_DTYPE_URLLINK:
72
-                    $linkObj = $smartObj->getUrlLinkObj($key);
73
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
74
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
75
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
76
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
77
-                    if ('' !== $linkObj->getVar('url')) {
78
-                        $smartObj->storeUrlLinkObj($linkObj);
79
-                    }
80
-                    //todo: catch errors
81
-                    $smartObj->setVar($key, $linkObj->getVar('urllinkid'));
82
-                    break;
83
-
84
-                case XOBJ_DTYPE_FILE:
85
-                    if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
86
-                        $fileObj = $smartObj->getFileObj($key);
87
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
88
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
89
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
90
-                        if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91
-                              && '' === $fileObj->getVar('url'))) {
92
-                            $res = $smartObj->storeFileObj($fileObj);
93
-                            if ($res) {
94
-                                $smartObj->setVar($key, $fileObj->getVar('fileid'));
95
-                            } else {
96
-                                //error setted, but no error message (to be improved)
97
-                                $smartObj->setErrors($fileObj->getErrors());
98
-                            }
99
-                        }
100
-                    }
101
-                    break;
102
-
103
-                case XOBJ_DTYPE_STIME:
104
-                case XOBJ_DTYPE_MTIME:
105
-                case XOBJ_DTYPE_LTIME:
106
-                    // check if this field's value is available in the POST array
107
-                    if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
108
-                        $value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
109
-                    } else {
110
-                        $value = strtotime($_POST[$key]);
111
-                        //if strtotime returns false, the value is already a time stamp
112
-                        if (!$value) {
113
-                            $value = (int)$_POST[$key];
114
-                        }
115
-                    }
116
-                    $smartObj->setVar($key, $value);
117
-
118
-                    break;
119
-
120
-                default:
121
-                    $smartObj->setVar($key, $_POST[$key]);
122
-                    break;
123
-            }
124
-        }
125
-    }
126
-
127
-    /**
128
-     * @param        $smartObj
129
-     * @param        $objectid
130
-     * @param        $created_success_msg
131
-     * @param        $modified_success_msg
132
-     * @param  bool  $redirect_page
133
-     * @param  bool  $debug
134
-     * @return mixed
135
-     */
136
-    public function doStoreFromDefaultForm(
137
-        &$smartObj,
138
-        $objectid,
139
-        $created_success_msg,
140
-        $modified_success_msg,
141
-        $redirect_page = false,
142
-        $debug = false
143
-    ) {
144
-        global $smart_previous_page;
145
-
146
-        $this->postDataToObject($smartObj);
147
-
148
-        if ($smartObj->isNew()) {
149
-            $redirect_msg = $created_success_msg;
150
-        } else {
151
-            $redirect_msg = $modified_success_msg;
152
-        }
153
-
154
-        // Check if there were uploaded files
155
-        if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
36
+	public $handler;
37
+
38
+	/**
39
+	 * SmartObjectController constructor.
40
+	 * @param $handler
41
+	 */
42
+	public function __construct($handler)
43
+	{
44
+		$this->handler = $handler;
45
+	}
46
+
47
+	/**
48
+	 * @param $smartObj
49
+	 */
50
+	public function postDataToObject(&$smartObj)
51
+	{
52
+		foreach (array_keys($smartObj->vars) as $key) {
53
+			switch ($smartObj->vars[$key]['data_type']) {
54
+				case XOBJ_DTYPE_IMAGE:
55
+					if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) {
56
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
57
+						$smartObj->setVar($key, $_POST['url_' . $key]);
58
+						if (file_exists($oldFile)) {
59
+							unlink($oldFile);
60
+						}
61
+					}
62
+					if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
+						$oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
64
+						$smartObj->setVar($key, '');
65
+						if (file_exists($oldFile)) {
66
+							unlink($oldFile);
67
+						}
68
+					}
69
+					break;
70
+
71
+				case XOBJ_DTYPE_URLLINK:
72
+					$linkObj = $smartObj->getUrlLinkObj($key);
73
+					$linkObj->setVar('caption', $_POST['caption_' . $key]);
74
+					$linkObj->setVar('description', $_POST['desc_' . $key]);
75
+					$linkObj->setVar('target', $_POST['target_' . $key]);
76
+					$linkObj->setVar('url', $_POST['url_' . $key]);
77
+					if ('' !== $linkObj->getVar('url')) {
78
+						$smartObj->storeUrlLinkObj($linkObj);
79
+					}
80
+					//todo: catch errors
81
+					$smartObj->setVar($key, $linkObj->getVar('urllinkid'));
82
+					break;
83
+
84
+				case XOBJ_DTYPE_FILE:
85
+					if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
86
+						$fileObj = $smartObj->getFileObj($key);
87
+						$fileObj->setVar('caption', $_POST['caption_' . $key]);
88
+						$fileObj->setVar('description', $_POST['desc_' . $key]);
89
+						$fileObj->setVar('url', $_POST['url_' . $key]);
90
+						if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91
+							  && '' === $fileObj->getVar('url'))) {
92
+							$res = $smartObj->storeFileObj($fileObj);
93
+							if ($res) {
94
+								$smartObj->setVar($key, $fileObj->getVar('fileid'));
95
+							} else {
96
+								//error setted, but no error message (to be improved)
97
+								$smartObj->setErrors($fileObj->getErrors());
98
+							}
99
+						}
100
+					}
101
+					break;
102
+
103
+				case XOBJ_DTYPE_STIME:
104
+				case XOBJ_DTYPE_MTIME:
105
+				case XOBJ_DTYPE_LTIME:
106
+					// check if this field's value is available in the POST array
107
+					if (is_array($_POST[$key]) && isset($_POST[$key]['date'])) {
108
+						$value = strtotime($_POST[$key]['date']) + $_POST[$key]['time'];
109
+					} else {
110
+						$value = strtotime($_POST[$key]);
111
+						//if strtotime returns false, the value is already a time stamp
112
+						if (!$value) {
113
+							$value = (int)$_POST[$key];
114
+						}
115
+					}
116
+					$smartObj->setVar($key, $value);
117
+
118
+					break;
119
+
120
+				default:
121
+					$smartObj->setVar($key, $_POST[$key]);
122
+					break;
123
+			}
124
+		}
125
+	}
126
+
127
+	/**
128
+	 * @param        $smartObj
129
+	 * @param        $objectid
130
+	 * @param        $created_success_msg
131
+	 * @param        $modified_success_msg
132
+	 * @param  bool  $redirect_page
133
+	 * @param  bool  $debug
134
+	 * @return mixed
135
+	 */
136
+	public function doStoreFromDefaultForm(
137
+		&$smartObj,
138
+		$objectid,
139
+		$created_success_msg,
140
+		$modified_success_msg,
141
+		$redirect_page = false,
142
+		$debug = false
143
+	) {
144
+		global $smart_previous_page;
145
+
146
+		$this->postDataToObject($smartObj);
147
+
148
+		if ($smartObj->isNew()) {
149
+			$redirect_msg = $created_success_msg;
150
+		} else {
151
+			$redirect_msg = $modified_success_msg;
152
+		}
153
+
154
+		// Check if there were uploaded files
155
+		if (isset($_POST['smart_upload_image']) || isset($_POST['smart_upload_file'])) {
156 156
 //            require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartuploader.php';
157
-            $uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
158
-            foreach ($_FILES as $name => $file_array) {
159
-                if (isset($file_array['name']) && '' !== $file_array['name']
160
-                    && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161
-                    if ($uploaderObj->fetchMedia($name)) {
162
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
163
-                        if ($uploaderObj->upload()) {
164
-                            // Find the related field in the SmartObject
165
-                            $related_field   = str_replace('upload_', '', $name);
166
-                            $uploadedArray[] = $related_field;
167
-                            //si c'est un fichier Rich
168
-                            if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169
-                                $object_fileurl = $smartObj->getUploadDir();
170
-                                $fileObj        = $smartObj->getFileObj($related_field);
171
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
172
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
173
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
174
-                                $smartObj->storeFileObj($fileObj);
175
-                                //todo: catch errors
176
-                                $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177
-                            } else {
178
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
179
-                                unlink($old_file);
180
-                                $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181
-                            }
182
-                        } else {
183
-                            $smartObj->setErrors($uploaderObj->getErrors(false));
184
-                        }
185
-                    } else {
186
-                        $smartObj->setErrors($uploaderObj->getErrors(false));
187
-                    }
188
-                }
189
-            }
190
-        }
191
-
192
-        if ($debug) {
193
-            $storeResult = $this->handler->insertD($smartObj);
194
-        } else {
195
-            $storeResult = $this->handler->insert($smartObj);
196
-        }
197
-
198
-        if ($storeResult) {
199
-            if ($this->handler->getPermissions()) {
200
-                $smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
201
-                $smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
202
-            }
203
-        }
204
-
205
-        if (null === $redirect_page) {
206
-            return $smartObj;
207
-        } else {
208
-            if (!$storeResult) {
209
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
210
-            }
211
-
212
-            $redirect_page = $redirect_page ?: smart_get_page_before_form();
213
-
214
-            redirect_header($redirect_page, 2, $redirect_msg);
215
-        }
216
-    }
217
-
218
-    /**
219
-     * Store the object in the database autmatically from a form sending POST data
220
-     *
221
-     * @param  string      $created_success_msg  message to display if new object was created
222
-     * @param  string      $modified_success_msg message to display if object was successfully edited
223
-     * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
224
-     * @param  bool        $debug
225
-     * @param  bool        $x_param
226
-     * @return bool
227
-     * @internal param string $created_redir_page redirect page after creating the object
228
-     * @internal param string $modified_redir_page redirect page after editing the object
229
-     * @internal param bool $exit if set to TRUE then the script ends
230
-     */
231
-    public function storeFromDefaultForm(
232
-        $created_success_msg,
233
-        $modified_success_msg,
234
-        $redirect_page = false,
235
-        $debug = false,
236
-        $x_param = false
237
-    ) {
238
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
239
-        if ($debug) {
240
-            if ($x_param) {
241
-                $smartObj = $this->handler->getD($objectid, true, $x_param);
242
-            } else {
243
-                $smartObj = $this->handler->getD($objectid);
244
-            }
245
-        } else {
246
-            if ($x_param) {
247
-                $smartObj = $this->handler->get($objectid, true, false, false, $x_param);
248
-            } else {
249
-                $smartObj = $this->handler->get($objectid);
250
-            }
251
-        }
252
-
253
-        // if handler is the Multilanguage handler, we will need to treat this for multilanguage
254
-        if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
255
-            if ($smartObj->isNew()) {
256
-                // This is a new object. We need to store the meta data and then the language data
257
-                // First, we will get rid of the multilanguage data to only store the meta data
258
-                $smartObj->stripMultilanguageFields();
259
-                $newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
260
-                /**
261
-                 * @todo we need to trap potential errors here
262
-                 */
263
-
264
-                // ok, the meta daa is stored. Let's recreate the object and then
265
-                // get rid of anything not multilanguage
266
-                unset($smartObj);
267
-                $smartObj = $this->handler->get($objectid);
268
-                $smartObj->stripNonMultilanguageFields();
269
-
270
-                $smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
271
-                $this->handler->changeTableNameForML();
272
-                $ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
273
-
274
-                return $ret;
275
-            }
276
-        } else {
277
-            return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
278
-        }
279
-    }
280
-
281
-    /**
282
-     * @return bool
283
-     */
284
-    public function storeSmartObjectD()
285
-    {
286
-        return $this->storeSmartObject(true);
287
-    }
288
-
289
-    /**
290
-     * @param  bool $debug
291
-     * @param  bool $xparam
292
-     * @return bool
293
-     */
294
-    public function storeSmartObject($debug = false, $xparam = false)
295
-    {
296
-        $ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
297
-
298
-        return $ret;
299
-    }
300
-
301
-    /**
302
-     * Handles deletion of an object which keyid is passed as a GET param
303
-     *
304
-     * @param  bool   $confirm_msg
305
-     * @param  string $op
306
-     * @param  bool   $userSide
307
-     * @return void
308
-     * @internal param string $redir_page redirect page after deleting the object
309
-     */
310
-    public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
311
-    {
312
-        global $smart_previous_page;
313
-
314
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
315
-        $smartObj = $this->handler->get($objectid);
316
-
317
-        if ($smartObj->isNew()) {
318
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
319
-        }
320
-
321
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
322
-        if ($confirm) {
323
-            if (!$this->handler->delete($smartObj)) {
324
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
325
-            }
326
-
327
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
328
-        } else {
329
-            // no confirm: show deletion condition
330
-
331
-            xoops_cp_header();
332
-
333
-            if (!$confirm_msg) {
334
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
335
-            }
336
-
337
-            xoops_confirm([
338
-                              'op'                    => $op,
339
-                              $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
340
-                              'confirm'               => 1,
341
-                              'redirect_page'         => $smart_previous_page
342
-                          ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
343
-
344
-            xoops_cp_footer();
345
-        }
346
-        exit();
347
-    }
348
-
349
-    /**
350
-     * @param bool   $confirm_msg
351
-     * @param string $op
352
-     */
353
-    public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
354
-    {
355
-        global $smart_previous_page, $xoopsTpl;
356
-
357
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
358
-        $smartObj = $this->handler->get($objectid);
359
-
360
-        if ($smartObj->isNew()) {
361
-            redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
362
-        }
363
-
364
-        $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
365
-        if ($confirm) {
366
-            if (!$this->handler->delete($smartObj)) {
367
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
368
-            }
369
-
370
-            redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
371
-        } else {
372
-            // no confirm: show deletion condition
373
-            if (!$confirm_msg) {
374
-                $confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
375
-            }
376
-
377
-            ob_start();
378
-            xoops_confirm([
379
-                              'op'                    => $op,
380
-                              $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
381
-                              'confirm'               => 1,
382
-                              'redirect_page'         => $smart_previous_page
383
-                          ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
384
-            $smartobjectDeleteConfirm = ob_get_clean();
385
-            $xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
386
-        }
387
-    }
388
-
389
-    /**
390
-     * Retreive the object admin side link for a {@link SmartObjectSingleView} page
391
-     *
392
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
393
-     * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
394
-     * @param  bool        $withimage
395
-     * @return string      admin side link to the object
396
-     */
397
-    public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398
-    {
399
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
400
-        if ($onlyUrl) {
401
-            return $ret;
402
-        } elseif ($withimage) {
403
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>";
404
-        }
405
-
406
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
407
-    }
408
-
409
-    /**
410
-     * Retreive the object user side link
411
-     *
412
-     * @param  SmartObject $smartObj reference to the object from which we want the user side link
413
-     * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
414
-     * @return string      user side link to the object
415
-     */
416
-    public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
417
-    {
418
-        $seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
419
-        $seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
420
-
421
-        /**
422
-         * $seoIncludeId feature is not finished yet, so let's put it always to true
423
-         */
424
-        //$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
425
-        $seoIncludeId = true;
426
-
427
-        if ('rewrite' === $seoMode) {
428
-            $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
429
-        } elseif ('pathinfo' === $seoMode) {
430
-            $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
431
-        } else {
432
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
433
-        }
434
-
435
-        if (!$onlyUrl) {
436
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
437
-        }
438
-
439
-        return $ret;
440
-    }
441
-
442
-    /**
443
-     * @param         $smartObj
444
-     * @param  bool   $onlyUrl
445
-     * @param  bool   $withimage
446
-     * @return string
447
-     */
448
-    public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449
-    {
450
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
451
-        if ($onlyUrl) {
452
-            return $ret;
453
-        } elseif ($withimage) {
454
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>";
455
-        }
456
-
457
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
458
-    }
459
-
460
-    /**
461
-     * @param         $smartObj
462
-     * @param  bool   $onlyUrl
463
-     * @param  bool   $withimage
464
-     * @param  bool   $userSide
465
-     * @return string
466
-     */
467
-    public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468
-    {
469
-        $admin_side = $userSide ? '' : 'admin/';
470
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
471
-        if ($onlyUrl) {
472
-            return $ret;
473
-        } elseif ($withimage) {
474
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'></a>";
475
-        }
476
-
477
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
478
-    }
479
-
480
-    /**
481
-     * @param         $smartObj
482
-     * @param  bool   $onlyUrl
483
-     * @param  bool   $withimage
484
-     * @param  bool   $userSide
485
-     * @return string
486
-     */
487
-    public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488
-    {
489
-        $admin_side = $userSide ? '' : 'admin/';
490
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
491
-        if ($onlyUrl) {
492
-            return $ret;
493
-        } elseif ($withimage) {
494
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'></a>";
495
-        }
496
-
497
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
498
-    }
499
-
500
-    /**
501
-     * @param $smartObj
502
-     * @return string
503
-     */
504
-    public function getPrintAndMailLink($smartObj)
505
-    {
506
-        global $xoopsConfig;
507
-
508
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
509
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
510
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>';
511
-
512
-        $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
513
-        $link        = smart_getCurrentPage();
514
-        $mid         = $smartModule->getVar('mid');
515
-        $friendlink  = "<a href=\"javascript:openWithSelfMain('"
516
-                       . SMARTOBJECT_URL
517
-                       . 'sendlink.php?link='
518
-                       . $link
519
-                       . '&amp;mid='
520
-                       . $mid
521
-                       . "', ',',',',',','sendmessage', 674, 500);\"><img src=\""
522
-                       . SMARTOBJECT_IMAGES_ACTIONS_URL
523
-                       . 'mail_send.png"  alt="'
524
-                       . _CO_SOBJECT_EMAIL
525
-                       . '" title="'
526
-                       . _CO_SOBJECT_EMAIL
527
-                       . '" style="vertical-align: middle;"></a>';
528
-
529
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
530
-
531
-        return $ret;
532
-    }
533
-
534
-    /**
535
-     * @return string
536
-     */
537
-    public function getModuleItemString()
538
-    {
539
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
540
-
541
-        return $ret;
542
-    }
157
+			$uploaderObj = new SmartUploader($smartObj->getImageDir(true), $this->handler->_allowedMimeTypes, $this->handler->_maxFileSize, $this->handler->_maxWidth, $this->handler->_maxHeight);
158
+			foreach ($_FILES as $name => $file_array) {
159
+				if (isset($file_array['name']) && '' !== $file_array['name']
160
+					&& in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161
+					if ($uploaderObj->fetchMedia($name)) {
162
+						$uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
163
+						if ($uploaderObj->upload()) {
164
+							// Find the related field in the SmartObject
165
+							$related_field   = str_replace('upload_', '', $name);
166
+							$uploadedArray[] = $related_field;
167
+							//si c'est un fichier Rich
168
+							if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169
+								$object_fileurl = $smartObj->getUploadDir();
170
+								$fileObj        = $smartObj->getFileObj($related_field);
171
+								$fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
172
+								$fileObj->setVar('caption', $_POST['caption_' . $related_field]);
173
+								$fileObj->setVar('description', $_POST['desc_' . $related_field]);
174
+								$smartObj->storeFileObj($fileObj);
175
+								//todo: catch errors
176
+								$smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177
+							} else {
178
+								$old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
179
+								unlink($old_file);
180
+								$smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181
+							}
182
+						} else {
183
+							$smartObj->setErrors($uploaderObj->getErrors(false));
184
+						}
185
+					} else {
186
+						$smartObj->setErrors($uploaderObj->getErrors(false));
187
+					}
188
+				}
189
+			}
190
+		}
191
+
192
+		if ($debug) {
193
+			$storeResult = $this->handler->insertD($smartObj);
194
+		} else {
195
+			$storeResult = $this->handler->insert($smartObj);
196
+		}
197
+
198
+		if ($storeResult) {
199
+			if ($this->handler->getPermissions()) {
200
+				$smartPermissionsHandler = new SmartobjectPermissionHandler($this->handler);
201
+				$smartPermissionsHandler->storeAllPermissionsForId($smartObj->id());
202
+			}
203
+		}
204
+
205
+		if (null === $redirect_page) {
206
+			return $smartObj;
207
+		} else {
208
+			if (!$storeResult) {
209
+				redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
210
+			}
211
+
212
+			$redirect_page = $redirect_page ?: smart_get_page_before_form();
213
+
214
+			redirect_header($redirect_page, 2, $redirect_msg);
215
+		}
216
+	}
217
+
218
+	/**
219
+	 * Store the object in the database autmatically from a form sending POST data
220
+	 *
221
+	 * @param  string      $created_success_msg  message to display if new object was created
222
+	 * @param  string      $modified_success_msg message to display if object was successfully edited
223
+	 * @param  bool|string $redirect_page        redirect page, if not set, then we backup once
224
+	 * @param  bool        $debug
225
+	 * @param  bool        $x_param
226
+	 * @return bool
227
+	 * @internal param string $created_redir_page redirect page after creating the object
228
+	 * @internal param string $modified_redir_page redirect page after editing the object
229
+	 * @internal param bool $exit if set to TRUE then the script ends
230
+	 */
231
+	public function storeFromDefaultForm(
232
+		$created_success_msg,
233
+		$modified_success_msg,
234
+		$redirect_page = false,
235
+		$debug = false,
236
+		$x_param = false
237
+	) {
238
+		$objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
239
+		if ($debug) {
240
+			if ($x_param) {
241
+				$smartObj = $this->handler->getD($objectid, true, $x_param);
242
+			} else {
243
+				$smartObj = $this->handler->getD($objectid);
244
+			}
245
+		} else {
246
+			if ($x_param) {
247
+				$smartObj = $this->handler->get($objectid, true, false, false, $x_param);
248
+			} else {
249
+				$smartObj = $this->handler->get($objectid);
250
+			}
251
+		}
252
+
253
+		// if handler is the Multilanguage handler, we will need to treat this for multilanguage
254
+		if (is_subclass_of($this->handler, 'smartpersistablemlobjecthandler')) {
255
+			if ($smartObj->isNew()) {
256
+				// This is a new object. We need to store the meta data and then the language data
257
+				// First, we will get rid of the multilanguage data to only store the meta data
258
+				$smartObj->stripMultilanguageFields();
259
+				$newObject = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
260
+				/**
261
+				 * @todo we need to trap potential errors here
262
+				 */
263
+
264
+				// ok, the meta daa is stored. Let's recreate the object and then
265
+				// get rid of anything not multilanguage
266
+				unset($smartObj);
267
+				$smartObj = $this->handler->get($objectid);
268
+				$smartObj->stripNonMultilanguageFields();
269
+
270
+				$smartObj->setVar($this->handler->keyName, $newObject->getVar($this->handler->keyName));
271
+				$this->handler->changeTableNameForML();
272
+				$ret = $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
273
+
274
+				return $ret;
275
+			}
276
+		} else {
277
+			return $this->doStoreFromDefaultForm($smartObj, $objectid, $created_success_msg, $modified_success_msg, $redirect_page, $debug);
278
+		}
279
+	}
280
+
281
+	/**
282
+	 * @return bool
283
+	 */
284
+	public function storeSmartObjectD()
285
+	{
286
+		return $this->storeSmartObject(true);
287
+	}
288
+
289
+	/**
290
+	 * @param  bool $debug
291
+	 * @param  bool $xparam
292
+	 * @return bool
293
+	 */
294
+	public function storeSmartObject($debug = false, $xparam = false)
295
+	{
296
+		$ret = $this->storeFromDefaultForm('', '', null, $debug, $xparam);
297
+
298
+		return $ret;
299
+	}
300
+
301
+	/**
302
+	 * Handles deletion of an object which keyid is passed as a GET param
303
+	 *
304
+	 * @param  bool   $confirm_msg
305
+	 * @param  string $op
306
+	 * @param  bool   $userSide
307
+	 * @return void
308
+	 * @internal param string $redir_page redirect page after deleting the object
309
+	 */
310
+	public function handleObjectDeletion($confirm_msg = false, $op = 'del', $userSide = false)
311
+	{
312
+		global $smart_previous_page;
313
+
314
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
315
+		$smartObj = $this->handler->get($objectid);
316
+
317
+		if ($smartObj->isNew()) {
318
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
319
+		}
320
+
321
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
322
+		if ($confirm) {
323
+			if (!$this->handler->delete($smartObj)) {
324
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
325
+			}
326
+
327
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
328
+		} else {
329
+			// no confirm: show deletion condition
330
+
331
+			xoops_cp_header();
332
+
333
+			if (!$confirm_msg) {
334
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
335
+			}
336
+
337
+			xoops_confirm([
338
+							  'op'                    => $op,
339
+							  $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
340
+							  'confirm'               => 1,
341
+							  'redirect_page'         => $smart_previous_page
342
+						  ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
343
+
344
+			xoops_cp_footer();
345
+		}
346
+		exit();
347
+	}
348
+
349
+	/**
350
+	 * @param bool   $confirm_msg
351
+	 * @param string $op
352
+	 */
353
+	public function handleObjectDeletionFromUserSide($confirm_msg = false, $op = 'del')
354
+	{
355
+		global $smart_previous_page, $xoopsTpl;
356
+
357
+		$objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
358
+		$smartObj = $this->handler->get($objectid);
359
+
360
+		if ($smartObj->isNew()) {
361
+			redirect_header('javascript:history.go(-1)', 3, _CO_SOBJECT_NOT_SELECTED);
362
+		}
363
+
364
+		$confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
365
+		if ($confirm) {
366
+			if (!$this->handler->delete($smartObj)) {
367
+				redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
368
+			}
369
+
370
+			redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
371
+		} else {
372
+			// no confirm: show deletion condition
373
+			if (!$confirm_msg) {
374
+				$confirm_msg = _CO_SOBJECT_DELETE_CONFIRM;
375
+			}
376
+
377
+			ob_start();
378
+			xoops_confirm([
379
+							  'op'                    => $op,
380
+							  $this->handler->keyName => $smartObj->getVar($this->handler->keyName),
381
+							  'confirm'               => 1,
382
+							  'redirect_page'         => $smart_previous_page
383
+						  ], xoops_getenv('PHP_SELF'), sprintf($confirm_msg, $smartObj->getVar($this->handler->identifierName)), _CO_SOBJECT_DELETE);
384
+			$smartobjectDeleteConfirm = ob_get_clean();
385
+			$xoopsTpl->assign('smartobject_delete_confirm', $smartobjectDeleteConfirm);
386
+		}
387
+	}
388
+
389
+	/**
390
+	 * Retreive the object admin side link for a {@link SmartObjectSingleView} page
391
+	 *
392
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
393
+	 * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
394
+	 * @param  bool        $withimage
395
+	 * @return string      admin side link to the object
396
+	 */
397
+	public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398
+	{
399
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
400
+		if ($onlyUrl) {
401
+			return $ret;
402
+		} elseif ($withimage) {
403
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>";
404
+		}
405
+
406
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
407
+	}
408
+
409
+	/**
410
+	 * Retreive the object user side link
411
+	 *
412
+	 * @param  SmartObject $smartObj reference to the object from which we want the user side link
413
+	 * @param  bool        $onlyUrl  wether or not to return a simple URL or a full <a> link
414
+	 * @return string      user side link to the object
415
+	 */
416
+	public function getItemLink(SmartObject $smartObj, $onlyUrl = false)
417
+	{
418
+		$seoMode       = smart_getModuleModeSEO($this->handler->_moduleName);
419
+		$seoModuleName = smart_getModuleNameForSEO($this->handler->_moduleName);
420
+
421
+		/**
422
+		 * $seoIncludeId feature is not finished yet, so let's put it always to true
423
+		 */
424
+		//$seoIncludeId = smart_getModuleIncludeIdSEO($this->handler->_moduleName);
425
+		$seoIncludeId = true;
426
+
427
+		if ('rewrite' === $seoMode) {
428
+			$ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
429
+		} elseif ('pathinfo' === $seoMode) {
430
+			$ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
431
+		} else {
432
+			$ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
433
+		}
434
+
435
+		if (!$onlyUrl) {
436
+			$ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
437
+		}
438
+
439
+		return $ret;
440
+	}
441
+
442
+	/**
443
+	 * @param         $smartObj
444
+	 * @param  bool   $onlyUrl
445
+	 * @param  bool   $withimage
446
+	 * @return string
447
+	 */
448
+	public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449
+	{
450
+		$ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
451
+		if ($onlyUrl) {
452
+			return $ret;
453
+		} elseif ($withimage) {
454
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>";
455
+		}
456
+
457
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
458
+	}
459
+
460
+	/**
461
+	 * @param         $smartObj
462
+	 * @param  bool   $onlyUrl
463
+	 * @param  bool   $withimage
464
+	 * @param  bool   $userSide
465
+	 * @return string
466
+	 */
467
+	public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468
+	{
469
+		$admin_side = $userSide ? '' : 'admin/';
470
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
471
+		if ($onlyUrl) {
472
+			return $ret;
473
+		} elseif ($withimage) {
474
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'></a>";
475
+		}
476
+
477
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
478
+	}
479
+
480
+	/**
481
+	 * @param         $smartObj
482
+	 * @param  bool   $onlyUrl
483
+	 * @param  bool   $withimage
484
+	 * @param  bool   $userSide
485
+	 * @return string
486
+	 */
487
+	public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488
+	{
489
+		$admin_side = $userSide ? '' : 'admin/';
490
+		$ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
491
+		if ($onlyUrl) {
492
+			return $ret;
493
+		} elseif ($withimage) {
494
+			return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'></a>";
495
+		}
496
+
497
+		return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
498
+	}
499
+
500
+	/**
501
+	 * @param $smartObj
502
+	 * @return string
503
+	 */
504
+	public function getPrintAndMailLink($smartObj)
505
+	{
506
+		global $xoopsConfig;
507
+
508
+		$printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
509
+		$js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
510
+		$printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>';
511
+
512
+		$smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
513
+		$link        = smart_getCurrentPage();
514
+		$mid         = $smartModule->getVar('mid');
515
+		$friendlink  = "<a href=\"javascript:openWithSelfMain('"
516
+					   . SMARTOBJECT_URL
517
+					   . 'sendlink.php?link='
518
+					   . $link
519
+					   . '&amp;mid='
520
+					   . $mid
521
+					   . "', ',',',',',','sendmessage', 674, 500);\"><img src=\""
522
+					   . SMARTOBJECT_IMAGES_ACTIONS_URL
523
+					   . 'mail_send.png"  alt="'
524
+					   . _CO_SOBJECT_EMAIL
525
+					   . '" title="'
526
+					   . _CO_SOBJECT_EMAIL
527
+					   . '" style="vertical-align: middle;"></a>';
528
+
529
+		$ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
530
+
531
+		return $ret;
532
+	}
533
+
534
+	/**
535
+	 * @return string
536
+	 */
537
+	public function getModuleItemString()
538
+	{
539
+		$ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
540
+
541
+		return $ret;
542
+	}
543 543
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -52,15 +52,15 @@  discard block
 block discarded – undo
52 52
         foreach (array_keys($smartObj->vars) as $key) {
53 53
             switch ($smartObj->vars[$key]['data_type']) {
54 54
                 case XOBJ_DTYPE_IMAGE:
55
-                    if (isset($_POST['url_' . $key]) && '' !== $_POST['url_' . $key]) {
56
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
57
-                        $smartObj->setVar($key, $_POST['url_' . $key]);
55
+                    if (isset($_POST['url_'.$key]) && '' !== $_POST['url_'.$key]) {
56
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
57
+                        $smartObj->setVar($key, $_POST['url_'.$key]);
58 58
                         if (file_exists($oldFile)) {
59 59
                             unlink($oldFile);
60 60
                         }
61 61
                     }
62
-                    if (isset($_POST['delete_' . $key]) && '1' == $_POST['delete_' . $key]) {
63
-                        $oldFile = $smartObj->getUploadDir(true) . $smartObj->getVar($key, 'e');
62
+                    if (isset($_POST['delete_'.$key]) && '1' == $_POST['delete_'.$key]) {
63
+                        $oldFile = $smartObj->getUploadDir(true).$smartObj->getVar($key, 'e');
64 64
                         $smartObj->setVar($key, '');
65 65
                         if (file_exists($oldFile)) {
66 66
                             unlink($oldFile);
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 
71 71
                 case XOBJ_DTYPE_URLLINK:
72 72
                     $linkObj = $smartObj->getUrlLinkObj($key);
73
-                    $linkObj->setVar('caption', $_POST['caption_' . $key]);
74
-                    $linkObj->setVar('description', $_POST['desc_' . $key]);
75
-                    $linkObj->setVar('target', $_POST['target_' . $key]);
76
-                    $linkObj->setVar('url', $_POST['url_' . $key]);
73
+                    $linkObj->setVar('caption', $_POST['caption_'.$key]);
74
+                    $linkObj->setVar('description', $_POST['desc_'.$key]);
75
+                    $linkObj->setVar('target', $_POST['target_'.$key]);
76
+                    $linkObj->setVar('url', $_POST['url_'.$key]);
77 77
                     if ('' !== $linkObj->getVar('url')) {
78 78
                         $smartObj->storeUrlLinkObj($linkObj);
79 79
                     }
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
                     break;
83 83
 
84 84
                 case XOBJ_DTYPE_FILE:
85
-                    if (!isset($_FILES['upload_' . $key]['name']) || '' === $_FILES['upload_' . $key]['name']) {
85
+                    if (!isset($_FILES['upload_'.$key]['name']) || '' === $_FILES['upload_'.$key]['name']) {
86 86
                         $fileObj = $smartObj->getFileObj($key);
87
-                        $fileObj->setVar('caption', $_POST['caption_' . $key]);
88
-                        $fileObj->setVar('description', $_POST['desc_' . $key]);
89
-                        $fileObj->setVar('url', $_POST['url_' . $key]);
87
+                        $fileObj->setVar('caption', $_POST['caption_'.$key]);
88
+                        $fileObj->setVar('description', $_POST['desc_'.$key]);
89
+                        $fileObj->setVar('url', $_POST['url_'.$key]);
90 90
                         if (!('' === $fileObj->getVar('url') && '' === $fileObj->getVar('url')
91 91
                               && '' === $fileObj->getVar('url'))) {
92 92
                             $res = $smartObj->storeFileObj($fileObj);
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
                         $value = strtotime($_POST[$key]);
111 111
                         //if strtotime returns false, the value is already a time stamp
112 112
                         if (!$value) {
113
-                            $value = (int)$_POST[$key];
113
+                            $value = (int) $_POST[$key];
114 114
                         }
115 115
                     }
116 116
                     $smartObj->setVar($key, $value);
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
                 if (isset($file_array['name']) && '' !== $file_array['name']
160 160
                     && in_array(str_replace('upload_', '', $name), array_keys($smartObj->vars))) {
161 161
                     if ($uploaderObj->fetchMedia($name)) {
162
-                        $uploaderObj->setTargetFileName(time() . '_' . $uploaderObj->getMediaName());
162
+                        $uploaderObj->setTargetFileName(time().'_'.$uploaderObj->getMediaName());
163 163
                         if ($uploaderObj->upload()) {
164 164
                             // Find the related field in the SmartObject
165 165
                             $related_field   = str_replace('upload_', '', $name);
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
                             if (XOBJ_DTYPE_FILE === $smartObj->vars[$related_field]['data_type']) {
169 169
                                 $object_fileurl = $smartObj->getUploadDir();
170 170
                                 $fileObj        = $smartObj->getFileObj($related_field);
171
-                                $fileObj->setVar('url', $object_fileurl . $uploaderObj->getSavedFileName());
172
-                                $fileObj->setVar('caption', $_POST['caption_' . $related_field]);
173
-                                $fileObj->setVar('description', $_POST['desc_' . $related_field]);
171
+                                $fileObj->setVar('url', $object_fileurl.$uploaderObj->getSavedFileName());
172
+                                $fileObj->setVar('caption', $_POST['caption_'.$related_field]);
173
+                                $fileObj->setVar('description', $_POST['desc_'.$related_field]);
174 174
                                 $smartObj->storeFileObj($fileObj);
175 175
                                 //todo: catch errors
176 176
                                 $smartObj->setVar($related_field, $fileObj->getVar('fileid'));
177 177
                             } else {
178
-                                $old_file = $smartObj->getUploadDir(true) . $smartObj->getVar($related_field);
178
+                                $old_file = $smartObj->getUploadDir(true).$smartObj->getVar($related_field);
179 179
                                 unlink($old_file);
180 180
                                 $smartObj->setVar($related_field, $uploaderObj->getSavedFileName());
181 181
                             }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             return $smartObj;
207 207
         } else {
208 208
             if (!$storeResult) {
209
-                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $smartObj->getHtmlErrors());
209
+                redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR.$smartObj->getHtmlErrors());
210 210
             }
211 211
 
212 212
             $redirect_page = $redirect_page ?: smart_get_page_before_form();
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         $debug = false,
236 236
         $x_param = false
237 237
     ) {
238
-        $objectid = isset($_POST[$this->handler->keyName]) ? (int)$_POST[$this->handler->keyName] : 0;
238
+        $objectid = isset($_POST[$this->handler->keyName]) ? (int) $_POST[$this->handler->keyName] : 0;
239 239
         if ($debug) {
240 240
             if ($x_param) {
241 241
                 $smartObj = $this->handler->getD($objectid, true, $x_param);
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     {
312 312
         global $smart_previous_page;
313 313
 
314
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
314
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
315 315
         $smartObj = $this->handler->get($objectid);
316 316
 
317 317
         if ($smartObj->isNew()) {
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
322 322
         if ($confirm) {
323 323
             if (!$this->handler->delete($smartObj)) {
324
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
324
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
325 325
             }
326 326
 
327 327
             redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
     {
355 355
         global $smart_previous_page, $xoopsTpl;
356 356
 
357
-        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int)$_REQUEST[$this->handler->keyName] : 0;
357
+        $objectid = isset($_REQUEST[$this->handler->keyName]) ? (int) $_REQUEST[$this->handler->keyName] : 0;
358 358
         $smartObj = $this->handler->get($objectid);
359 359
 
360 360
         if ($smartObj->isNew()) {
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
         $confirm = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
365 365
         if ($confirm) {
366 366
             if (!$this->handler->delete($smartObj)) {
367
-                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR . $smartObj->getHtmlErrors());
367
+                redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_ERROR.$smartObj->getHtmlErrors());
368 368
             }
369 369
 
370 370
             redirect_header($_POST['redirect_page'], 3, _CO_SOBJECT_DELETE_SUCCESS);
@@ -396,14 +396,14 @@  discard block
 block discarded – undo
396 396
      */
397 397
     public function getAdminViewItemLink(SmartObject $smartObj, $onlyUrl = false, $withimage = false)
398 398
     {
399
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=view&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
399
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=view&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
400 400
         if ($onlyUrl) {
401 401
             return $ret;
402 402
         } elseif ($withimage) {
403
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "viewmag.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_ADMIN_VIEW . "'  title='" . _CO_SOBJECT_ADMIN_VIEW . "'></a>";
403
+            return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."viewmag.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_ADMIN_VIEW."'  title='"._CO_SOBJECT_ADMIN_VIEW."'></a>";
404 404
         }
405 405
 
406
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
406
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
407 407
     }
408 408
 
409 409
     /**
@@ -425,15 +425,15 @@  discard block
 block discarded – undo
425 425
         $seoIncludeId = true;
426 426
 
427 427
         if ('rewrite' === $seoMode) {
428
-            $ret = XOOPS_URL . '/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
428
+            $ret = XOOPS_URL.'/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html';
429 429
         } elseif ('pathinfo' === $seoMode) {
430
-            $ret = SMARTOBJECT_URL . 'seo.php/' . $seoModuleName . '.' . $this->handler->_itemname . ($seoIncludeId ? '.' . $smartObj->getVar($this->handler->keyName) : '') . '/' . $smartObj->getVar('short_url') . '.html';
430
+            $ret = SMARTOBJECT_URL.'seo.php/'.$seoModuleName.'.'.$this->handler->_itemname.($seoIncludeId ? '.'.$smartObj->getVar($this->handler->keyName) : '').'/'.$smartObj->getVar('short_url').'.html';
431 431
         } else {
432
-            $ret = $this->handler->_moduleUrl . $this->handler->_page . '?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
432
+            $ret = $this->handler->_moduleUrl.$this->handler->_page.'?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
433 433
         }
434 434
 
435 435
         if (!$onlyUrl) {
436
-            $ret = "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
436
+            $ret = "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
437 437
         }
438 438
 
439 439
         return $ret;
@@ -447,14 +447,14 @@  discard block
 block discarded – undo
447 447
      */
448 448
     public function getEditLanguageLink($smartObj, $onlyUrl = false, $withimage = true)
449 449
     {
450
-        $ret = $this->handler->_moduleUrl . 'admin/' . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName) . '&language=' . $smartObj->getVar('language');
450
+        $ret = $this->handler->_moduleUrl.'admin/'.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName).'&language='.$smartObj->getVar('language');
451 451
         if ($onlyUrl) {
452 452
             return $ret;
453 453
         } elseif ($withimage) {
454
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "wizard.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'  title='" . _CO_SOBJECT_LANGUAGE_MODIFY . "'></a>";
454
+            return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."wizard.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_LANGUAGE_MODIFY."'  title='"._CO_SOBJECT_LANGUAGE_MODIFY."'></a>";
455 455
         }
456 456
 
457
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
457
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
458 458
     }
459 459
 
460 460
     /**
@@ -467,14 +467,14 @@  discard block
 block discarded – undo
467 467
     public function getEditItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
468 468
     {
469 469
         $admin_side = $userSide ? '' : 'admin/';
470
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=mod&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
470
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=mod&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
471 471
         if ($onlyUrl) {
472 472
             return $ret;
473 473
         } elseif ($withimage) {
474
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "edit.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_MODIFY . "'  title='" . _CO_SOBJECT_MODIFY . "'></a>";
474
+            return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."edit.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_MODIFY."'  title='"._CO_SOBJECT_MODIFY."'></a>";
475 475
         }
476 476
 
477
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
477
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
478 478
     }
479 479
 
480 480
     /**
@@ -487,14 +487,14 @@  discard block
 block discarded – undo
487 487
     public function getDeleteItemLink($smartObj, $onlyUrl = false, $withimage = true, $userSide = false)
488 488
     {
489 489
         $admin_side = $userSide ? '' : 'admin/';
490
-        $ret        = $this->handler->_moduleUrl . $admin_side . $this->handler->_page . '?op=del&' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
490
+        $ret        = $this->handler->_moduleUrl.$admin_side.$this->handler->_page.'?op=del&'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
491 491
         if ($onlyUrl) {
492 492
             return $ret;
493 493
         } elseif ($withimage) {
494
-            return "<a href='" . $ret . "'><img src='" . SMARTOBJECT_IMAGES_ACTIONS_URL . "editdelete.png' style='vertical-align: middle;' alt='" . _CO_SOBJECT_DELETE . "'  title='" . _CO_SOBJECT_DELETE . "'></a>";
494
+            return "<a href='".$ret."'><img src='".SMARTOBJECT_IMAGES_ACTIONS_URL."editdelete.png' style='vertical-align: middle;' alt='"._CO_SOBJECT_DELETE."'  title='"._CO_SOBJECT_DELETE."'></a>";
495 495
         }
496 496
 
497
-        return "<a href='" . $ret . "'>" . $smartObj->getVar($this->handler->identifierName) . '</a>';
497
+        return "<a href='".$ret."'>".$smartObj->getVar($this->handler->identifierName).'</a>';
498 498
     }
499 499
 
500 500
     /**
@@ -505,9 +505,9 @@  discard block
 block discarded – undo
505 505
     {
506 506
         global $xoopsConfig;
507 507
 
508
-        $printlink = $this->handler->_moduleUrl . 'print.php?' . $this->handler->keyName . '=' . $smartObj->getVar($this->handler->keyName);
509
-        $js        = "javascript:openWithSelfMain('" . $printlink . "', 'smartpopup', 700, 519);";
510
-        $printlink = '<a href="' . $js . '"><img  src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'fileprint.png" alt="" style="vertical-align: middle;"></a>';
508
+        $printlink = $this->handler->_moduleUrl.'print.php?'.$this->handler->keyName.'='.$smartObj->getVar($this->handler->keyName);
509
+        $js        = "javascript:openWithSelfMain('".$printlink."', 'smartpopup', 700, 519);";
510
+        $printlink = '<a href="'.$js.'"><img  src="'.SMARTOBJECT_IMAGES_ACTIONS_URL.'fileprint.png" alt="" style="vertical-align: middle;"></a>';
511 511
 
512 512
         $smartModule = smart_getModuleInfo($smartObj->handler->_moduleName);
513 513
         $link        = smart_getCurrentPage();
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
                        . _CO_SOBJECT_EMAIL
527 527
                        . '" style="vertical-align: middle;"></a>';
528 528
 
529
-        $ret = '<span id="smartobject_print_button">' . $printlink . '&nbsp;</span>' . '<span id="smartobject_mail_button">' . $friendlink . '</span>';
529
+        $ret = '<span id="smartobject_print_button">'.$printlink.'&nbsp;</span>'.'<span id="smartobject_mail_button">'.$friendlink.'</span>';
530 530
 
531 531
         return $ret;
532 532
     }
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
      */
537 537
     public function getModuleItemString()
538 538
     {
539
-        $ret = $this->handler->_moduleName . '_' . $this->handler->_itemname;
539
+        $ret = $this->handler->_moduleName.'_'.$this->handler->_itemname;
540 540
 
541 541
         return $ret;
542 542
     }
Please login to merge, or discard this patch.
class/SmartobjectDbupdater.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     /**
144 144
      * Use to update a table
145 145
      *
146
-     * @param object $table {@link SmartDbTable} that will be updated
146
+     * @param SmartDbTable $table {@link SmartDbTable} that will be updated
147 147
      *
148 148
      * @see SmartDbTable
149 149
      *
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
     /**
246 246
      * @param $module
247 247
      * @param $item
248
-     * @return bool
248
+     * @return false|null
249 249
      */
250 250
     public function upgradeObjectItem($module, $item)
251 251
     {
Please login to merge, or discard this patch.
Indentation   +320 added lines, -321 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@  discard block
 block discarded – undo
25 25
  * Contains the classes for updating database tables
26 26
  *
27 27
  * @license GNU
28
-
29 28
  */
30 29
 /**
31 30
  * SmartDbTable class
@@ -38,7 +37,7 @@  discard block
 block discarded – undo
38 37
  */
39 38
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
40 39
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
41
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
40
+	require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
42 41
 }
43 42
 /**
44 43
  * Include the language constants for the SmartObjectDBUpdater
@@ -46,7 +45,7 @@  discard block
 block discarded – undo
46 45
 global $xoopsConfig;
47 46
 $common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
48 47
 if (!file_exists($common_file)) {
49
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
48
+	$common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
50 49
 }
51 50
 include $common_file;
52 51
 
@@ -62,328 +61,328 @@  discard block
 block discarded – undo
62 61
  */
63 62
 class SmartobjectDbupdater
64 63
 {
65
-    public $_dbTypesArray;
66
-
67
-    /**
68
-     * SmartobjectDbupdater constructor.
69
-     */
70
-    public function __construct()
71
-    {
72
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
73
-        $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
74
-        $this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
75
-        $this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
76
-        $this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
77
-        $this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
78
-        $this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
79
-        $this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
80
-        $this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
81
-        $this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
82
-        $this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
83
-        $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
84
-        $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
85
-        $this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
86
-        $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
87
-        $this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
88
-        $this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
89
-        $this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
90
-    }
91
-
92
-    /**
93
-     * Use to execute a general query
94
-     *
95
-     * @param string $query   query that will be executed
96
-     * @param string $goodmsg message displayed on success
97
-     * @param string $badmsg  message displayed on error
98
-     *
99
-     * @return bool true if success, false if an error occured
100
-     *
101
-     */
102
-    public function runQuery($query, $goodmsg, $badmsg)
103
-    {
104
-        global $xoopsDB;
105
-        $ret = $xoopsDB->query($query);
106
-        if (!$ret) {
107
-            echo "&nbsp;&nbsp;$badmsg<br>";
108
-
109
-            return false;
110
-        } else {
111
-            echo "&nbsp;&nbsp;$goodmsg<br>";
112
-
113
-            return true;
114
-        }
115
-    }
116
-
117
-    /**
118
-     * Use to rename a table
119
-     *
120
-     * @param string $from name of the table to rename
121
-     * @param string $to   new name of the renamed table
122
-     *
123
-     * @return bool true if success, false if an error occured
124
-     */
125
-    public function renameTable($from, $to)
126
-    {
127
-        global $xoopsDB;
128
-        $from  = $xoopsDB->prefix($from);
129
-        $to    = $xoopsDB->prefix($to);
130
-        $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
131
-        $ret   = $xoopsDB->query($query);
132
-        if (!$ret) {
133
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
134
-
135
-            return false;
136
-        } else {
137
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
138
-
139
-            return true;
140
-        }
141
-    }
142
-
143
-    /**
144
-     * Use to update a table
145
-     *
146
-     * @param object $table {@link SmartDbTable} that will be updated
147
-     *
148
-     * @see SmartDbTable
149
-     *
150
-     * @return bool true if success, false if an error occured
151
-     */
152
-    public function updateTable($table)
153
-    {
154
-        global $xoopsDB;
155
-        $ret = true;
156
-        // If table has a structure, create the table
157
-        if ($table->getStructure()) {
158
-            $ret = $table->createTable() && $ret;
159
-        }
160
-        // If table is flag for drop, drop it
161
-        if ($table->_flagForDrop) {
162
-            $ret = $table->dropTable() && $ret;
163
-        }
164
-        // If table has data, insert it
165
-        if ($table->getData()) {
166
-            $ret = $table->addData() && $ret;
167
-        }
168
-        // If table has new fields to be added, add them
169
-        if ($table->getNewFields()) {
170
-            $ret = $table->addNewFields() && $ret;
171
-        }
172
-        // If table has altered field, alter the table
173
-        if ($table->getAlteredFields()) {
174
-            $ret = $table->alterTable() && $ret;
175
-        }
176
-        // If table has updated field values, update the table
177
-        if ($table->getUpdatedFields()) {
178
-            $ret = $table->updateFieldsValues($table) && $ret;
179
-        }
180
-        // If table has dropped field, alter the table
181
-        if ($table->getDroppedFields()) {
182
-            $ret = $table->dropFields($table) && $ret;
183
-        }
184
-        //felix
185
-        // If table has updated field values, update the table
186
-        if ($table->getUpdatedWhere()) {
187
-            $ret = $table->UpdateWhereValues($table) && $ret;
188
-        }
189
-
190
-        return $ret;
191
-    }
192
-
193
-    /**
194
-     * @param $module
195
-     * @param $item
196
-     */
197
-    public function automaticUpgrade($module, $item)
198
-    {
199
-        if (is_array($item)) {
200
-            foreach ($item as $v) {
201
-                $this->upgradeObjectItem($module, $v);
202
-            }
203
-        } else {
204
-            $this->upgradeObjectItem($module, $item);
205
-        }
206
-    }
207
-
208
-    /**
209
-     * @param $var
210
-     * @return string
211
-     */
212
-    public function getFieldTypeFromVar($var)
213
-    {
214
-        $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
215
-
216
-        return $ret;
217
-    }
218
-
219
-    /**
220
-     * @param         $var
221
-     * @param  bool   $key
222
-     * @return string
223
-     */
224
-    public function getFieldDefaultFromVar($var, $key = false)
225
-    {
226
-        if ($var['value']) {
227
-            return $var['value'];
228
-        } else {
229
-            if (in_array($var['data_type'], [
230
-                XOBJ_DTYPE_INT,
231
-                XOBJ_DTYPE_STIME,
232
-                XOBJ_DTYPE_MTIME,
233
-                XOBJ_DTYPE_LTIME,
234
-                XOBJ_DTYPE_TIME_ONLY,
235
-                XOBJ_DTYPE_URLLINK,
236
-                XOBJ_DTYPE_FILE
237
-            ])) {
238
-                return '0';
239
-            } else {
240
-                return '';
241
-            }
242
-        }
243
-    }
244
-
245
-    /**
246
-     * @param $module
247
-     * @param $item
248
-     * @return bool
249
-     */
250
-    public function upgradeObjectItem($module, $item)
251
-    {
252
-        $moduleHandler = xoops_getModuleHandler($item, $module);
253
-        if (!$moduleHandler) {
254
-            return false;
255
-        }
256
-
257
-        $table      = new SmartDbTable($module . '_' . $item);
258
-        $object     = $moduleHandler->create();
259
-        $objectVars = $object->getVars();
260
-
261
-        if (!$table->exists()) {
262
-            // table was never created, let's do it
263
-            $structure = '';
264
-            foreach ($objectVars as $key => $var) {
265
-                if ($var['persistent']) {
266
-                    $type = $this->getFieldTypeFromVar($var);
267
-                    if ($key == $moduleHandler->keyName) {
268
-                        $extra = 'auto_increment';
269
-                    } else {
270
-                        $default = $this->getFieldDefaultFromVar($var);
271
-                        $extra   = "default '$default'
64
+	public $_dbTypesArray;
65
+
66
+	/**
67
+	 * SmartobjectDbupdater constructor.
68
+	 */
69
+	public function __construct()
70
+	{
71
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTBOX]       = 'varchar(255)';
72
+		$this->_dbTypesArray[XOBJ_DTYPE_TXTAREA]      = 'text';
73
+		$this->_dbTypesArray[XOBJ_DTYPE_INT]          = 'int(11)';
74
+		$this->_dbTypesArray[XOBJ_DTYPE_URL]          = 'varchar(255)';
75
+		$this->_dbTypesArray[XOBJ_DTYPE_EMAIL]        = 'varchar(255)';
76
+		$this->_dbTypesArray[XOBJ_DTYPE_ARRAY]        = 'text';
77
+		$this->_dbTypesArray[XOBJ_DTYPE_OTHER]        = 'text';
78
+		$this->_dbTypesArray[XOBJ_DTYPE_SOURCE]       = 'text';
79
+		$this->_dbTypesArray[XOBJ_DTYPE_STIME]        = 'int(11)';
80
+		$this->_dbTypesArray[XOBJ_DTYPE_MTIME]        = 'int(11)';
81
+		$this->_dbTypesArray[XOBJ_DTYPE_LTIME]        = 'int(11)';
82
+		$this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text';
83
+		$this->_dbTypesArray[XOBJ_DTYPE_CURRENCY]     = 'text';
84
+		$this->_dbTypesArray[XOBJ_DTYPE_FLOAT]        = 'float';
85
+		$this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY]    = 'int(11)';
86
+		$this->_dbTypesArray[XOBJ_DTYPE_URLLINK]      = 'int(11)';
87
+		$this->_dbTypesArray[XOBJ_DTYPE_FILE]         = 'int(11)';
88
+		$this->_dbTypesArray[XOBJ_DTYPE_IMAGE]        = 'varchar(255)';
89
+	}
90
+
91
+	/**
92
+	 * Use to execute a general query
93
+	 *
94
+	 * @param string $query   query that will be executed
95
+	 * @param string $goodmsg message displayed on success
96
+	 * @param string $badmsg  message displayed on error
97
+	 *
98
+	 * @return bool true if success, false if an error occured
99
+	 *
100
+	 */
101
+	public function runQuery($query, $goodmsg, $badmsg)
102
+	{
103
+		global $xoopsDB;
104
+		$ret = $xoopsDB->query($query);
105
+		if (!$ret) {
106
+			echo "&nbsp;&nbsp;$badmsg<br>";
107
+
108
+			return false;
109
+		} else {
110
+			echo "&nbsp;&nbsp;$goodmsg<br>";
111
+
112
+			return true;
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * Use to rename a table
118
+	 *
119
+	 * @param string $from name of the table to rename
120
+	 * @param string $to   new name of the renamed table
121
+	 *
122
+	 * @return bool true if success, false if an error occured
123
+	 */
124
+	public function renameTable($from, $to)
125
+	{
126
+		global $xoopsDB;
127
+		$from  = $xoopsDB->prefix($from);
128
+		$to    = $xoopsDB->prefix($to);
129
+		$query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
130
+		$ret   = $xoopsDB->query($query);
131
+		if (!$ret) {
132
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
133
+
134
+			return false;
135
+		} else {
136
+			echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
137
+
138
+			return true;
139
+		}
140
+	}
141
+
142
+	/**
143
+	 * Use to update a table
144
+	 *
145
+	 * @param object $table {@link SmartDbTable} that will be updated
146
+	 *
147
+	 * @see SmartDbTable
148
+	 *
149
+	 * @return bool true if success, false if an error occured
150
+	 */
151
+	public function updateTable($table)
152
+	{
153
+		global $xoopsDB;
154
+		$ret = true;
155
+		// If table has a structure, create the table
156
+		if ($table->getStructure()) {
157
+			$ret = $table->createTable() && $ret;
158
+		}
159
+		// If table is flag for drop, drop it
160
+		if ($table->_flagForDrop) {
161
+			$ret = $table->dropTable() && $ret;
162
+		}
163
+		// If table has data, insert it
164
+		if ($table->getData()) {
165
+			$ret = $table->addData() && $ret;
166
+		}
167
+		// If table has new fields to be added, add them
168
+		if ($table->getNewFields()) {
169
+			$ret = $table->addNewFields() && $ret;
170
+		}
171
+		// If table has altered field, alter the table
172
+		if ($table->getAlteredFields()) {
173
+			$ret = $table->alterTable() && $ret;
174
+		}
175
+		// If table has updated field values, update the table
176
+		if ($table->getUpdatedFields()) {
177
+			$ret = $table->updateFieldsValues($table) && $ret;
178
+		}
179
+		// If table has dropped field, alter the table
180
+		if ($table->getDroppedFields()) {
181
+			$ret = $table->dropFields($table) && $ret;
182
+		}
183
+		//felix
184
+		// If table has updated field values, update the table
185
+		if ($table->getUpdatedWhere()) {
186
+			$ret = $table->UpdateWhereValues($table) && $ret;
187
+		}
188
+
189
+		return $ret;
190
+	}
191
+
192
+	/**
193
+	 * @param $module
194
+	 * @param $item
195
+	 */
196
+	public function automaticUpgrade($module, $item)
197
+	{
198
+		if (is_array($item)) {
199
+			foreach ($item as $v) {
200
+				$this->upgradeObjectItem($module, $v);
201
+			}
202
+		} else {
203
+			$this->upgradeObjectItem($module, $item);
204
+		}
205
+	}
206
+
207
+	/**
208
+	 * @param $var
209
+	 * @return string
210
+	 */
211
+	public function getFieldTypeFromVar($var)
212
+	{
213
+		$ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text';
214
+
215
+		return $ret;
216
+	}
217
+
218
+	/**
219
+	 * @param         $var
220
+	 * @param  bool   $key
221
+	 * @return string
222
+	 */
223
+	public function getFieldDefaultFromVar($var, $key = false)
224
+	{
225
+		if ($var['value']) {
226
+			return $var['value'];
227
+		} else {
228
+			if (in_array($var['data_type'], [
229
+				XOBJ_DTYPE_INT,
230
+				XOBJ_DTYPE_STIME,
231
+				XOBJ_DTYPE_MTIME,
232
+				XOBJ_DTYPE_LTIME,
233
+				XOBJ_DTYPE_TIME_ONLY,
234
+				XOBJ_DTYPE_URLLINK,
235
+				XOBJ_DTYPE_FILE
236
+			])) {
237
+				return '0';
238
+			} else {
239
+				return '';
240
+			}
241
+		}
242
+	}
243
+
244
+	/**
245
+	 * @param $module
246
+	 * @param $item
247
+	 * @return bool
248
+	 */
249
+	public function upgradeObjectItem($module, $item)
250
+	{
251
+		$moduleHandler = xoops_getModuleHandler($item, $module);
252
+		if (!$moduleHandler) {
253
+			return false;
254
+		}
255
+
256
+		$table      = new SmartDbTable($module . '_' . $item);
257
+		$object     = $moduleHandler->create();
258
+		$objectVars = $object->getVars();
259
+
260
+		if (!$table->exists()) {
261
+			// table was never created, let's do it
262
+			$structure = '';
263
+			foreach ($objectVars as $key => $var) {
264
+				if ($var['persistent']) {
265
+					$type = $this->getFieldTypeFromVar($var);
266
+					if ($key == $moduleHandler->keyName) {
267
+						$extra = 'auto_increment';
268
+					} else {
269
+						$default = $this->getFieldDefaultFromVar($var);
270
+						$extra   = "default '$default'
272 271
 ";
273
-                    }
274
-                    $structure .= "`$key` $type not null $extra,
272
+					}
273
+					$structure .= "`$key` $type not null $extra,
275 274
 ";
276
-                }
277
-            }
278
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
275
+				}
276
+			}
277
+			$structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
279 278
 ';
280
-            $table->setStructure($structure);
281
-            if (!$this->updateTable($table)) {
282
-                /**
283
-                 * @todo trap the errors
284
-                 */
285
-            }
286
-        } else {
287
-            $existingFieldsArray = $table->getExistingFieldsArray();
288
-            foreach ($objectVars as $key => $var) {
289
-                if ($var['persistent']) {
290
-                    if (!isset($existingFieldsArray[$key])) {
291
-                        // the fiels does not exist, let's create it
292
-                        $type    = $this->getFieldTypeFromVar($var);
293
-                        $default = $this->getFieldDefaultFromVar($var);
294
-                        $table->addNewField($key, "$type not null default '$default'");
295
-                    } else {
296
-                        // if field already exists, let's check if the definition is correct
297
-                        $definition = strtolower($existingFieldsArray[$key]);
298
-                        $type       = $this->getFieldTypeFromVar($var);
299
-                        if ($key == $moduleHandler->keyName) {
300
-                            $extra = 'auto_increment';
301
-                        } else {
302
-                            $default = $this->getFieldDefaultFromVar($var, $key);
303
-                            $extra   = "default '$default'";
304
-                        }
305
-                        $actual_definition = "$type not null $extra";
306
-                        if ($definition != $actual_definition) {
307
-                            $table->addAlteredField($key, $actual_definition);
308
-                        }
309
-                    }
310
-                }
311
-            }
312
-
313
-            // check to see if there are some unused fields left in the table
314
-            foreach ($existingFieldsArray as $key => $v) {
315
-                if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
316
-                    $table->addDroppedField($key);
317
-                }
318
-            }
319
-
320
-            if (!$this->updateTable($table)) {
321
-                /**
322
-                 * @todo trap the errors
323
-                 */
324
-            }
325
-        }
326
-    }
327
-
328
-    /**
329
-     * @param $module
330
-     * @return bool
331
-     */
332
-    public function moduleUpgrade(\XoopsModule $module)
333
-    {
334
-        $dirname = $module->getVar('dirname');
335
-
336
-        ob_start();
337
-
338
-        $table = new SmartDbTable($dirname . '_meta');
339
-        if (!$table->exists()) {
340
-            $table->setStructure("
279
+			$table->setStructure($structure);
280
+			if (!$this->updateTable($table)) {
281
+				/**
282
+				 * @todo trap the errors
283
+				 */
284
+			}
285
+		} else {
286
+			$existingFieldsArray = $table->getExistingFieldsArray();
287
+			foreach ($objectVars as $key => $var) {
288
+				if ($var['persistent']) {
289
+					if (!isset($existingFieldsArray[$key])) {
290
+						// the fiels does not exist, let's create it
291
+						$type    = $this->getFieldTypeFromVar($var);
292
+						$default = $this->getFieldDefaultFromVar($var);
293
+						$table->addNewField($key, "$type not null default '$default'");
294
+					} else {
295
+						// if field already exists, let's check if the definition is correct
296
+						$definition = strtolower($existingFieldsArray[$key]);
297
+						$type       = $this->getFieldTypeFromVar($var);
298
+						if ($key == $moduleHandler->keyName) {
299
+							$extra = 'auto_increment';
300
+						} else {
301
+							$default = $this->getFieldDefaultFromVar($var, $key);
302
+							$extra   = "default '$default'";
303
+						}
304
+						$actual_definition = "$type not null $extra";
305
+						if ($definition != $actual_definition) {
306
+							$table->addAlteredField($key, $actual_definition);
307
+						}
308
+					}
309
+				}
310
+			}
311
+
312
+			// check to see if there are some unused fields left in the table
313
+			foreach ($existingFieldsArray as $key => $v) {
314
+				if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) {
315
+					$table->addDroppedField($key);
316
+				}
317
+			}
318
+
319
+			if (!$this->updateTable($table)) {
320
+				/**
321
+				 * @todo trap the errors
322
+				 */
323
+			}
324
+		}
325
+	}
326
+
327
+	/**
328
+	 * @param $module
329
+	 * @return bool
330
+	 */
331
+	public function moduleUpgrade(\XoopsModule $module)
332
+	{
333
+		$dirname = $module->getVar('dirname');
334
+
335
+		ob_start();
336
+
337
+		$table = new SmartDbTable($dirname . '_meta');
338
+		if (!$table->exists()) {
339
+			$table->setStructure("
341 340
               `metakey` varchar(50) NOT NULL default '',
342 341
               `metavalue` varchar(255) NOT NULL default '',
343 342
               PRIMARY KEY (`metakey`)");
344
-            $table->setData("'version',0");
345
-            if (!$this->updateTable($table)) {
346
-                /**
347
-                 * @todo trap the errors
348
-                 */
349
-            }
350
-        }
351
-
352
-        $dbVersion = smart_GetMeta('version', $dirname);
353
-        if (!$dbVersion) {
354
-            $dbVersion = 0;
355
-        }
356
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
357
-        echo 'Database version: ' . $dbVersion . '<br>';
358
-        echo 'New database version: ' . $newDbVersion . '<br>';
359
-
360
-        if ($newDbVersion > $dbVersion) {
361
-            for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
362
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
363
-                if (function_exists($upgrade_function)) {
364
-                    $upgrade_function();
365
-                }
366
-            }
367
-        }
368
-
369
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
370
-
371
-        // if there is a function to execute for this DB version, let's do it
372
-        //$function_
373
-
374
-        $module_info = smart_getModuleInfo($dirname);
375
-        $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
376
-
377
-        echo '</code>';
378
-
379
-        $feedback = ob_get_clean();
380
-        if (method_exists($module, 'setMessage')) {
381
-            $module->setMessage($feedback);
382
-        } else {
383
-            echo $feedback;
384
-        }
385
-        smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
386
-
387
-        return true;
388
-    }
343
+			$table->setData("'version',0");
344
+			if (!$this->updateTable($table)) {
345
+				/**
346
+				 * @todo trap the errors
347
+				 */
348
+			}
349
+		}
350
+
351
+		$dbVersion = smart_GetMeta('version', $dirname);
352
+		if (!$dbVersion) {
353
+			$dbVersion = 0;
354
+		}
355
+		$newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
356
+		echo 'Database version: ' . $dbVersion . '<br>';
357
+		echo 'New database version: ' . $newDbVersion . '<br>';
358
+
359
+		if ($newDbVersion > $dbVersion) {
360
+			for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
361
+				$upgrade_function = $dirname . '_db_upgrade_' . $i;
362
+				if (function_exists($upgrade_function)) {
363
+					$upgrade_function();
364
+				}
365
+			}
366
+		}
367
+
368
+		echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
369
+
370
+		// if there is a function to execute for this DB version, let's do it
371
+		//$function_
372
+
373
+		$module_info = smart_getModuleInfo($dirname);
374
+		$this->automaticUpgrade($dirname, $module_info->modinfo['object_items']);
375
+
376
+		echo '</code>';
377
+
378
+		$feedback = ob_get_clean();
379
+		if (method_exists($module, 'setMessage')) {
380
+			$module->setMessage($feedback);
381
+		} else {
382
+			echo $feedback;
383
+		}
384
+		smart_SetMeta('version', $newDbVersion, $dirname); //Set meta version to current
385
+
386
+		return true;
387
+	}
389 388
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
  */
39 39
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
40 40
 if (!defined('SMARTOBJECT_ROOT_PATH')) {
41
-    require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
41
+    require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
42 42
 }
43 43
 /**
44 44
  * Include the language constants for the SmartObjectDBUpdater
45 45
  */
46 46
 global $xoopsConfig;
47
-$common_file = SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/smartdbupdater.php';
47
+$common_file = SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/smartdbupdater.php';
48 48
 if (!file_exists($common_file)) {
49
-    $common_file = SMARTOBJECT_ROOT_PATH . 'language/english/smartdbupdater.php';
49
+    $common_file = SMARTOBJECT_ROOT_PATH.'language/english/smartdbupdater.php';
50 50
 }
51 51
 include $common_file;
52 52
 
@@ -130,11 +130,11 @@  discard block
 block discarded – undo
130 130
         $query = sprintf('ALTER TABLE %s RENAME %s', $from, $to);
131 131
         $ret   = $xoopsDB->query($query);
132 132
         if (!$ret) {
133
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . '<br>';
133
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from).'<br>';
134 134
 
135 135
             return false;
136 136
         } else {
137
-            echo '&nbsp;&nbsp;' . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . '<br>';
137
+            echo '&nbsp;&nbsp;'.sprintf(_SDU_MSG_RENAME_TABLE, $from, $to).'<br>';
138 138
 
139 139
             return true;
140 140
         }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
             return false;
255 255
         }
256 256
 
257
-        $table      = new SmartDbTable($module . '_' . $item);
257
+        $table      = new SmartDbTable($module.'_'.$item);
258 258
         $object     = $moduleHandler->create();
259 259
         $objectVars = $object->getVars();
260 260
 
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 ";
276 276
                 }
277 277
             }
278
-            $structure .= 'PRIMARY KEY  (`' . $moduleHandler->keyName . '`)
278
+            $structure .= 'PRIMARY KEY  (`'.$moduleHandler->keyName.'`)
279 279
 ';
280 280
             $table->setStructure($structure);
281 281
             if (!$this->updateTable($table)) {
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 
336 336
         ob_start();
337 337
 
338
-        $table = new SmartDbTable($dirname . '_meta');
338
+        $table = new SmartDbTable($dirname.'_meta');
339 339
         if (!$table->exists()) {
340 340
             $table->setStructure("
341 341
               `metakey` varchar(50) NOT NULL default '',
@@ -353,20 +353,20 @@  discard block
 block discarded – undo
353 353
         if (!$dbVersion) {
354 354
             $dbVersion = 0;
355 355
         }
356
-        $newDbVersion = constant(strtoupper($dirname . '_db_version')) ?: 0;
357
-        echo 'Database version: ' . $dbVersion . '<br>';
358
-        echo 'New database version: ' . $newDbVersion . '<br>';
356
+        $newDbVersion = constant(strtoupper($dirname.'_db_version')) ?: 0;
357
+        echo 'Database version: '.$dbVersion.'<br>';
358
+        echo 'New database version: '.$newDbVersion.'<br>';
359 359
 
360 360
         if ($newDbVersion > $dbVersion) {
361 361
             for ($i = $dbVersion + 1; $i <= $newDbVersion; ++$i) {
362
-                $upgrade_function = $dirname . '_db_upgrade_' . $i;
362
+                $upgrade_function = $dirname.'_db_upgrade_'.$i;
363 363
                 if (function_exists($upgrade_function)) {
364 364
                     $upgrade_function();
365 365
                 }
366 366
             }
367 367
         }
368 368
 
369
-        echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>';
369
+        echo '<code>'._SDU_UPDATE_UPDATING_DATABASE.'<br>';
370 370
 
371 371
         // if there is a function to execute for this DB version, let's do it
372 372
         //$function_
Please login to merge, or discard this patch.
class/SmartobjectMemberHandler.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -228,7 +228,7 @@
 block discarded – undo
228 228
      * Creates a random number with a specified number of $digits
229 229
      *
230 230
      * @param  int $digits number of digits
231
-     * @return int random number
231
+     * @return string random number
232 232
      * @author xHelp Team
233 233
      *
234 234
      * @access public
Please login to merge, or discard this patch.
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -37,227 +37,227 @@
 block discarded – undo
37 37
  */
38 38
 class SmartobjectMemberHandler extends \XoopsMemberHandler
39 39
 {
40
-    /**
41
-     * constructor
42
-     * @param \XoopsDatabase $db
43
-     */
44
-    public function __construct(\XoopsDatabase $db)
45
-    {
46
-        parent::__construct($db);
47
-        $this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
48
-    }
40
+	/**
41
+	 * constructor
42
+	 * @param \XoopsDatabase $db
43
+	 */
44
+	public function __construct(\XoopsDatabase $db)
45
+	{
46
+		parent::__construct($db);
47
+		$this->_uHandler = xoops_getModuleHandler('user', 'smartobject');
48
+	}
49 49
 
50
-    /**
51
-     * @param       $userObj
52
-     * @param  bool $groups
53
-     * @param  bool $notifyUser
54
-     * @param  bool $password
55
-     * @return bool
56
-     */
57
-    public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
58
-    {
59
-        $email = $userObj->getVar('email');
60
-        if (!$userObj->getVar('email') || '' === $email) {
61
-            $userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
50
+	/**
51
+	 * @param       $userObj
52
+	 * @param  bool $groups
53
+	 * @param  bool $notifyUser
54
+	 * @param  bool $password
55
+	 * @return bool
56
+	 */
57
+	public function addAndActivateUser($userObj, $groups = false, $notifyUser = true, &$password = false)
58
+	{
59
+		$email = $userObj->getVar('email');
60
+		if (!$userObj->getVar('email') || '' === $email) {
61
+			$userObj->setErrors(_CO_SOBJECT_USER_NEED_EMAIL);
62 62
 
63
-            return false;
64
-        }
63
+			return false;
64
+		}
65 65
 
66
-        $password = $userObj->getVar('pass');
67
-        // randomly generating the password if not already set
68
-        if ('' === $password) {
69
-            $password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
70
-        }
71
-        $userObj->setVar('pass', md5($password));
66
+		$password = $userObj->getVar('pass');
67
+		// randomly generating the password if not already set
68
+		if ('' === $password) {
69
+			$password = substr(md5(uniqid(mt_rand(), 1)), 0, 6);
70
+		}
71
+		$userObj->setVar('pass', md5($password));
72 72
 
73
-        // if no username is set, let's generate one
74
-        $unamecount = 20;
75
-        $uname      = $userObj->getVar('uname');
76
-        if (!$uname || '' === $uname) {
77
-            $usernames = $this->genUserNames($email, $unamecount);
78
-            $newuser   = false;
79
-            $i         = 0;
80
-            while (false === $newuser) {
81
-                $crit  = new \Criteria('uname', $usernames[$i]);
82
-                $count = $this->getUserCount($crit);
83
-                if (0 == $count) {
84
-                    $newuser = true;
85
-                } else {
86
-                    //Move to next username
87
-                    ++$i;
88
-                    if ($i == $unamecount) {
89
-                        //Get next batch of usernames to try, reset counter
90
-                        $usernames = $this->genUserNames($email, $unamecount);
91
-                        $i         = 0;
92
-                    }
93
-                }
94
-            }
95
-        }
73
+		// if no username is set, let's generate one
74
+		$unamecount = 20;
75
+		$uname      = $userObj->getVar('uname');
76
+		if (!$uname || '' === $uname) {
77
+			$usernames = $this->genUserNames($email, $unamecount);
78
+			$newuser   = false;
79
+			$i         = 0;
80
+			while (false === $newuser) {
81
+				$crit  = new \Criteria('uname', $usernames[$i]);
82
+				$count = $this->getUserCount($crit);
83
+				if (0 == $count) {
84
+					$newuser = true;
85
+				} else {
86
+					//Move to next username
87
+					++$i;
88
+					if ($i == $unamecount) {
89
+						//Get next batch of usernames to try, reset counter
90
+						$usernames = $this->genUserNames($email, $unamecount);
91
+						$i         = 0;
92
+					}
93
+				}
94
+			}
95
+		}
96 96
 
97
-        global $xoopsConfig;
97
+		global $xoopsConfig;
98 98
 
99
-        $configHandler   = xoops_getHandler('config');
100
-        $xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
101
-        switch ($xoopsConfigUser['activation_type']) {
102
-            case 0:
103
-                $level           = 0;
104
-                $mailtemplate    = 'smartmail_activate_user.tpl';
105
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
106
-                break;
107
-            case 1:
108
-                $level           = 1;
109
-                $mailtemplate    = 'smartmail_auto_activate_user.tpl';
110
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
111
-                break;
112
-            case 2:
113
-            default:
114
-                $level           = 0;
115
-                $mailtemplate    = 'smartmail_admin_activate_user.tpl';
116
-                $aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
117
-        }
99
+		$configHandler   = xoops_getHandler('config');
100
+		$xoopsConfigUser = $configHandler->getConfigsByCat(XOOPS_CONF_USER);
101
+		switch ($xoopsConfigUser['activation_type']) {
102
+			case 0:
103
+				$level           = 0;
104
+				$mailtemplate    = 'smartmail_activate_user.tpl';
105
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_NEED_ACT, $user_email);
106
+				break;
107
+			case 1:
108
+				$level           = 1;
109
+				$mailtemplate    = 'smartmail_auto_activate_user.tpl';
110
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_AUTO_ACT, $user_email);
111
+				break;
112
+			case 2:
113
+			default:
114
+				$level           = 0;
115
+				$mailtemplate    = 'smartmail_admin_activate_user.tpl';
116
+				$aInfoMessages[] = sprintf(_NL_MA_NEW_USER_ADMIN_ACT, $user_email);
117
+		}
118 118
 
119
-        $userObj->setVar('uname', $usernames[$i]);
120
-        $userObj->setVar('user_avatar', 'blank.gif');
121
-        $userObj->setVar('user_regdate', time());
122
-        $userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
123
-        $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
124
-        $userObj->setVar('actkey', $actkey);
125
-        $userObj->setVar('email', $email);
126
-        $userObj->setVar('notify_method', 2);
127
-        $userObj->setVar('level', $userObj);
119
+		$userObj->setVar('uname', $usernames[$i]);
120
+		$userObj->setVar('user_avatar', 'blank.gif');
121
+		$userObj->setVar('user_regdate', time());
122
+		$userObj->setVar('timezone_offset', $xoopsConfig['default_TZ']);
123
+		$actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
124
+		$userObj->setVar('actkey', $actkey);
125
+		$userObj->setVar('email', $email);
126
+		$userObj->setVar('notify_method', 2);
127
+		$userObj->setVar('level', $userObj);
128 128
 
129
-        if ($this->insertUser($userObj)) {
129
+		if ($this->insertUser($userObj)) {
130 130
 
131
-            // if $groups=false, Add the user to Registered Users group
132
-            if (!$groups) {
133
-                $this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
134
-            } else {
135
-                foreach ($groups as $groupid) {
136
-                    $this->addUserToGroup($groupid, $userObj->getVar('uid'));
137
-                }
138
-            }
139
-        } else {
140
-            return false;
141
-        }
131
+			// if $groups=false, Add the user to Registered Users group
132
+			if (!$groups) {
133
+				$this->addUserToGroup(XOOPS_GROUP_USERS, $userObj->getVar('uid'));
134
+			} else {
135
+				foreach ($groups as $groupid) {
136
+					$this->addUserToGroup($groupid, $userObj->getVar('uid'));
137
+				}
138
+			}
139
+		} else {
140
+			return false;
141
+		}
142 142
 
143
-        if ($notifyUser) {
144
-            // send some notifications
145
-            $xoopsMailer = xoops_getMailer();
146
-            $xoopsMailer->useMail();
147
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
148
-            $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
149
-            $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
150
-            $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
151
-            $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
152
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
153
-            $xoopsMailer->assign('NAME', $userObj->getVar('name'));
154
-            $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
155
-            $xoopsMailer->setToUsers($userObj);
156
-            $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
157
-            $xoopsMailer->setFromName($xoopsConfig['sitename']);
158
-            $xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
143
+		if ($notifyUser) {
144
+			// send some notifications
145
+			$xoopsMailer = xoops_getMailer();
146
+			$xoopsMailer->useMail();
147
+			$xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
148
+			$xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
149
+			$xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
150
+			$xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
151
+			$xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
152
+			$xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
153
+			$xoopsMailer->assign('NAME', $userObj->getVar('name'));
154
+			$xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
155
+			$xoopsMailer->setToUsers($userObj);
156
+			$xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
157
+			$xoopsMailer->setFromName($xoopsConfig['sitename']);
158
+			$xoopsMailer->setSubject(sprintf(_CO_SOBJECT_NEW_USER_NOTIFICATION_SUBJECT, $xoopsConfig['sitename']));
159 159
 
160
-            if (!$xoopsMailer->send(true)) {
161
-                /**
162
-                 * @todo trap error if email was not sent
163
-                 */
164
-                $xoopsMailer->getErrors(true);
165
-            }
166
-        }
160
+			if (!$xoopsMailer->send(true)) {
161
+				/**
162
+				 * @todo trap error if email was not sent
163
+				 */
164
+				$xoopsMailer->getErrors(true);
165
+			}
166
+		}
167 167
 
168
-        return true;
169
-    }
168
+		return true;
169
+	}
170 170
 
171
-    /**
172
-     * Generates an array of usernames
173
-     *
174
-     * @param  string $email email of user
175
-     * @param  int    $count number of names to generate
176
-     * @return array  $names
177
-     * @internal param string $name name of user
178
-     * @author   xHelp Team
179
-     *
180
-     * @access   public
181
-     */
182
-    public function genUserNames($email, $count = 20)
183
-    {
184
-        $name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
171
+	/**
172
+	 * Generates an array of usernames
173
+	 *
174
+	 * @param  string $email email of user
175
+	 * @param  int    $count number of names to generate
176
+	 * @return array  $names
177
+	 * @internal param string $name name of user
178
+	 * @author   xHelp Team
179
+	 *
180
+	 * @access   public
181
+	 */
182
+	public function genUserNames($email, $count = 20)
183
+	{
184
+		$name = substr($email, 0, strpos($email, '@')); //Take the email adress without domain as username
185 185
 
186
-        $names  = [];
187
-        $userid = explode('@', $email);
186
+		$names  = [];
187
+		$userid = explode('@', $email);
188 188
 
189
-        $basename    = '';
190
-        $hasbasename = false;
191
-        $emailname   = $userid[0];
189
+		$basename    = '';
190
+		$hasbasename = false;
191
+		$emailname   = $userid[0];
192 192
 
193
-        $names[] = $emailname;
193
+		$names[] = $emailname;
194 194
 
195
-        if (strlen($name) > 0) {
196
-            $name = explode(' ', trim($name));
197
-            if (count($name) > 1) {
198
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
199
-            } else {
200
-                $basename = strtolower($name[0]);
201
-            }
202
-            $basename = xoops_substr($basename, 0, 60, '');
203
-            //Prevent Duplication of Email Username and Name
204
-            if (!in_array($basename, $names)) {
205
-                $names[]     = $basename;
206
-                $hasbasename = true;
207
-            }
208
-        }
195
+		if (strlen($name) > 0) {
196
+			$name = explode(' ', trim($name));
197
+			if (count($name) > 1) {
198
+				$basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
199
+			} else {
200
+				$basename = strtolower($name[0]);
201
+			}
202
+			$basename = xoops_substr($basename, 0, 60, '');
203
+			//Prevent Duplication of Email Username and Name
204
+			if (!in_array($basename, $names)) {
205
+				$names[]     = $basename;
206
+				$hasbasename = true;
207
+			}
208
+		}
209 209
 
210
-        $i          = count($names);
211
-        $onbasename = 1;
212
-        while ($i < $count) {
213
-            $num = $this->genRandNumber();
214
-            if ($onbasename < 0 && $hasbasename) {
215
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
216
-            } else {
217
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
218
-            }
219
-            $i          = count($names);
220
-            $onbasename = ~$onbasename;
221
-            $num        = '';
222
-        }
210
+		$i          = count($names);
211
+		$onbasename = 1;
212
+		while ($i < $count) {
213
+			$num = $this->genRandNumber();
214
+			if ($onbasename < 0 && $hasbasename) {
215
+				$names[] = xoops_substr($basename, 0, 58, '') . $num;
216
+			} else {
217
+				$names[] = xoops_substr($emailname, 0, 58, '') . $num;
218
+			}
219
+			$i          = count($names);
220
+			$onbasename = ~$onbasename;
221
+			$num        = '';
222
+		}
223 223
 
224
-        return $names;
225
-    }
224
+		return $names;
225
+	}
226 226
 
227
-    /**
228
-     * Creates a random number with a specified number of $digits
229
-     *
230
-     * @param  int $digits number of digits
231
-     * @return int random number
232
-     * @author xHelp Team
233
-     *
234
-     * @access public
235
-     */
236
-    public function genRandNumber($digits = 2)
237
-    {
238
-        $this->initRand();
239
-        $tmp = [];
227
+	/**
228
+	 * Creates a random number with a specified number of $digits
229
+	 *
230
+	 * @param  int $digits number of digits
231
+	 * @return int random number
232
+	 * @author xHelp Team
233
+	 *
234
+	 * @access public
235
+	 */
236
+	public function genRandNumber($digits = 2)
237
+	{
238
+		$this->initRand();
239
+		$tmp = [];
240 240
 
241
-        for ($i = 0; $i < $digits; ++$i) {
242
-            $tmp[$i] = (mt_rand() % 9);
243
-        }
241
+		for ($i = 0; $i < $digits; ++$i) {
242
+			$tmp[$i] = (mt_rand() % 9);
243
+		}
244 244
 
245
-        return implode('', $tmp);
246
-    }
245
+		return implode('', $tmp);
246
+	}
247 247
 
248
-    /**
249
-     * Gives the random number generator a seed to start from
250
-     *
251
-     * @return void
252
-     *
253
-     * @access public
254
-     */
255
-    public function initRand()
256
-    {
257
-        static $randCalled = false;
258
-        if (!$randCalled) {
259
-            mt_srand((double)microtime() * 1000000);
260
-            $randCalled = true;
261
-        }
262
-    }
248
+	/**
249
+	 * Gives the random number generator a seed to start from
250
+	 *
251
+	 * @return void
252
+	 *
253
+	 * @access public
254
+	 */
255
+	public function initRand()
256
+	{
257
+		static $randCalled = false;
258
+		if (!$randCalled) {
259
+			mt_srand((double)microtime() * 1000000);
260
+			$randCalled = true;
261
+		}
262
+	}
263 263
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 use XoopsModules\Smartobject;
22 22
 
23 23
 // defined('XOOPS_ROOT_PATH') || die('Restricted access');
24
-require_once XOOPS_ROOT_PATH . '/kernel/user.php';
25
-require_once XOOPS_ROOT_PATH . '/kernel/group.php';
26
-require_once XOOPS_ROOT_PATH . '/kernel/member.php';
24
+require_once XOOPS_ROOT_PATH.'/kernel/user.php';
25
+require_once XOOPS_ROOT_PATH.'/kernel/group.php';
26
+require_once XOOPS_ROOT_PATH.'/kernel/member.php';
27 27
 
28 28
 /**
29 29
  * XOOPS member handler class.
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
             // send some notifications
145 145
             $xoopsMailer = xoops_getMailer();
146 146
             $xoopsMailer->useMail();
147
-            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH . 'language/' . $xoopsConfig['language'] . '/mail_template');
147
+            $xoopsMailer->setTemplateDir(SMARTOBJECT_ROOT_PATH.'language/'.$xoopsConfig['language'].'/mail_template');
148 148
             $xoopsMailer->setTemplate('smartobject_notify_user_added_by_admin.tpl');
149 149
             $xoopsMailer->assign('XOOPS_USER_PASSWORD', $password);
150 150
             $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
151 151
             $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
152
-            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
152
+            $xoopsMailer->assign('SITEURL', XOOPS_URL.'/');
153 153
             $xoopsMailer->assign('NAME', $userObj->getVar('name'));
154 154
             $xoopsMailer->assign('UNAME', $userObj->getVar('uname'));
155 155
             $xoopsMailer->setToUsers($userObj);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
         if (strlen($name) > 0) {
196 196
             $name = explode(' ', trim($name));
197 197
             if (count($name) > 1) {
198
-                $basename = strtolower(substr($name[0], 0, 1) . $name[count($name) - 1]);
198
+                $basename = strtolower(substr($name[0], 0, 1).$name[count($name) - 1]);
199 199
             } else {
200 200
                 $basename = strtolower($name[0]);
201 201
             }
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
         while ($i < $count) {
213 213
             $num = $this->genRandNumber();
214 214
             if ($onbasename < 0 && $hasbasename) {
215
-                $names[] = xoops_substr($basename, 0, 58, '') . $num;
215
+                $names[] = xoops_substr($basename, 0, 58, '').$num;
216 216
             } else {
217
-                $names[] = xoops_substr($emailname, 0, 58, '') . $num;
217
+                $names[] = xoops_substr($emailname, 0, 58, '').$num;
218 218
             }
219 219
             $i          = count($names);
220 220
             $onbasename = ~$onbasename;
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         static $randCalled = false;
258 258
         if (!$randCalled) {
259
-            mt_srand((double)microtime() * 1000000);
259
+            mt_srand((double) microtime() * 1000000);
260 260
             $randCalled = true;
261 261
         }
262 262
     }
Please login to merge, or discard this patch.
class/SmartObjectSingleView.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 
33 33
     /**
34 34
      * Constructor
35
-     * @param       $object
35
+     * @param       BaseSmartObject $object
36 36
      * @param bool  $userSide
37 37
      * @param array $actions
38 38
      * @param bool  $headerAsRow
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-     * @param $rowObj
49
+     * @param SmartObjectRow $rowObj
50 50
      */
51 51
     public function addRow($rowObj)
52 52
     {
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -23,94 +23,94 @@
 block discarded – undo
23 23
  */
24 24
 class SmartObjectSingleView
25 25
 {
26
-    public $_object;
27
-    public $_userSide;
28
-    public $_tpl;
29
-    public $_rows;
30
-    public $_actions;
31
-    public $_headerAsRow = true;
26
+	public $_object;
27
+	public $_userSide;
28
+	public $_tpl;
29
+	public $_rows;
30
+	public $_actions;
31
+	public $_headerAsRow = true;
32 32
 
33
-    /**
34
-     * Constructor
35
-     * @param       $object
36
-     * @param bool  $userSide
37
-     * @param array $actions
38
-     * @param bool  $headerAsRow
39
-     */
40
-    public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true)
41
-    {
42
-        $this->_object      = $object;
43
-        $this->_userSide    = $userSide;
44
-        $this->_actions     = $actions;
45
-        $this->_headerAsRow = $headerAsRow;
46
-    }
33
+	/**
34
+	 * Constructor
35
+	 * @param       $object
36
+	 * @param bool  $userSide
37
+	 * @param array $actions
38
+	 * @param bool  $headerAsRow
39
+	 */
40
+	public function __construct($object, $userSide = false, $actions = [], $headerAsRow = true)
41
+	{
42
+		$this->_object      = $object;
43
+		$this->_userSide    = $userSide;
44
+		$this->_actions     = $actions;
45
+		$this->_headerAsRow = $headerAsRow;
46
+	}
47 47
 
48
-    /**
49
-     * @param $rowObj
50
-     */
51
-    public function addRow($rowObj)
52
-    {
53
-        $this->_rows[] = $rowObj;
54
-    }
48
+	/**
49
+	 * @param $rowObj
50
+	 */
51
+	public function addRow($rowObj)
52
+	{
53
+		$this->_rows[] = $rowObj;
54
+	}
55 55
 
56
-    /**
57
-     * @param  bool $fetchOnly
58
-     * @param  bool $debug
59
-     * @return mixed|string|void
60
-     */
61
-    public function render($fetchOnly = false, $debug = false)
62
-    {
63
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
56
+	/**
57
+	 * @param  bool $fetchOnly
58
+	 * @param  bool $debug
59
+	 * @return mixed|string|void
60
+	 */
61
+	public function render($fetchOnly = false, $debug = false)
62
+	{
63
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
64 64
 
65
-        $this->_tpl             = new \XoopsTpl();
66
-        $vars                   = $this->_object->vars;
67
-        $smartobjectObjectArray = [];
65
+		$this->_tpl             = new \XoopsTpl();
66
+		$vars                   = $this->_object->vars;
67
+		$smartobjectObjectArray = [];
68 68
 
69
-        foreach ($this->_rows as $row) {
70
-            $key = $row->getKeyName();
71
-            if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) {
72
-                $method = $row->_customMethodForValue;
73
-                $value  = $this->_object->$method();
74
-            } else {
75
-                $value = $this->_object->getVar($row->getKeyName());
76
-            }
77
-            if ($row->isHeader()) {
78
-                $this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']);
79
-                $this->_tpl->assign('smartobject_single_view_header_value', $value);
80
-            } else {
81
-                $smartobjectObjectArray[$key]['value']   = $value;
82
-                $smartobjectObjectArray[$key]['header']  = $row->isHeader();
83
-                $smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption'];
84
-            }
85
-        }
86
-        $action_row = '';
87
-        if (in_array('edit', $this->_actions)) {
88
-            $action_row .= $this->_object->getEditItemLink(false, true, true);
89
-        }
90
-        if (in_array('delete', $this->_actions)) {
91
-            $action_row .= $this->_object->getDeleteItemLink(false, true, true);
92
-        }
93
-        if ($action_row) {
94
-            $smartobjectObjectArray['zaction']['value']   = $action_row;
95
-            $smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS;
96
-        }
69
+		foreach ($this->_rows as $row) {
70
+			$key = $row->getKeyName();
71
+			if ($row->_customMethodForValue && method_exists($this->_object, $row->_customMethodForValue)) {
72
+				$method = $row->_customMethodForValue;
73
+				$value  = $this->_object->$method();
74
+			} else {
75
+				$value = $this->_object->getVar($row->getKeyName());
76
+			}
77
+			if ($row->isHeader()) {
78
+				$this->_tpl->assign('smartobject_single_view_header_caption', $this->_object->vars[$key]['form_caption']);
79
+				$this->_tpl->assign('smartobject_single_view_header_value', $value);
80
+			} else {
81
+				$smartobjectObjectArray[$key]['value']   = $value;
82
+				$smartobjectObjectArray[$key]['header']  = $row->isHeader();
83
+				$smartobjectObjectArray[$key]['caption'] = $this->_object->vars[$key]['form_caption'];
84
+			}
85
+		}
86
+		$action_row = '';
87
+		if (in_array('edit', $this->_actions)) {
88
+			$action_row .= $this->_object->getEditItemLink(false, true, true);
89
+		}
90
+		if (in_array('delete', $this->_actions)) {
91
+			$action_row .= $this->_object->getDeleteItemLink(false, true, true);
92
+		}
93
+		if ($action_row) {
94
+			$smartobjectObjectArray['zaction']['value']   = $action_row;
95
+			$smartobjectObjectArray['zaction']['caption'] = _CO_SOBJECT_ACTIONS;
96
+		}
97 97
 
98
-        $this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow);
99
-        $this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray);
98
+		$this->_tpl->assign('smartobject_header_as_row', $this->_headerAsRow);
99
+		$this->_tpl->assign('smartobject_object_array', $smartobjectObjectArray);
100 100
 
101
-        if ($fetchOnly) {
102
-            return $this->_tpl->fetch('db:smartobject_singleview_display.tpl');
103
-        } else {
104
-            $this->_tpl->display('db:smartobject_singleview_display.tpl');
105
-        }
106
-    }
101
+		if ($fetchOnly) {
102
+			return $this->_tpl->fetch('db:smartobject_singleview_display.tpl');
103
+		} else {
104
+			$this->_tpl->display('db:smartobject_singleview_display.tpl');
105
+		}
106
+	}
107 107
 
108
-    /**
109
-     * @param  bool $debug
110
-     * @return mixed|string|void
111
-     */
112
-    public function fetch($debug = false)
113
-    {
114
-        return $this->render(true, $debug);
115
-    }
108
+	/**
109
+	 * @param  bool $debug
110
+	 * @return mixed|string|void
111
+	 */
112
+	public function fetch($debug = false)
113
+	{
114
+		return $this->render(true, $debug);
115
+	}
116 116
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
      */
61 61
     public function render($fetchOnly = false, $debug = false)
62 62
     {
63
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
63
+        require_once XOOPS_ROOT_PATH.'/class/template.php';
64 64
 
65 65
         $this->_tpl             = new \XoopsTpl();
66 66
         $vars                   = $this->_object->vars;
Please login to merge, or discard this patch.
class/SmartObjectTable.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
     }
107 107
 
108 108
     /**
109
-     * @param $columnObj
109
+     * @param SmartObjectColumn $columnObj
110 110
      */
111 111
     public function addColumn($columnObj)
112 112
     {
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
     }
115 115
 
116 116
     /**
117
-     * @param $name
118
-     * @param $location
117
+     * @param string $name
118
+     * @param string $location
119 119
      * @param $value
120 120
      */
121 121
     public function addIntroButton($name, $location, $value)
Please login to merge, or discard this patch.
Indentation   +801 added lines, -801 removed lines patch added patch discarded remove patch
@@ -25,805 +25,805 @@
 block discarded – undo
25 25
  */
26 26
 class SmartObjectTable
27 27
 {
28
-    public $_id;
29
-    public $_objectHandler;
30
-    public $_columns;
31
-    public $_criteria;
32
-    public $_actions;
33
-    public $_objects = false;
34
-    public $_aObjects;
35
-    public $_custom_actions;
36
-    public $_sortsel;
37
-    public $_ordersel;
38
-    public $_limitsel;
39
-    public $_filtersel;
40
-    public $_filterseloptions;
41
-    public $_filtersel2;
42
-    public $_filtersel2options;
43
-    public $_filtersel2optionsDefault;
44
-
45
-    public $_tempObject;
46
-    public $_tpl;
47
-    public $_introButtons;
48
-    public $_quickSearch            = false;
49
-    public $_actionButtons          = false;
50
-    public $_head_css_class         = 'bg3';
51
-    public $_hasActions             = false;
52
-    public $_userSide               = false;
53
-    public $_printerFriendlyPage    = false;
54
-    public $_tableHeader            = false;
55
-    public $_tableFooter            = false;
56
-    public $_showActionsColumnTitle = true;
57
-    public $_isTree                 = false;
58
-    public $_showFilterAndLimit     = true;
59
-    public $_enableColumnsSorting   = true;
60
-    public $_customTemplate         = false;
61
-    public $_withSelectedActions    = [];
62
-
63
-    /**
64
-     * Constructor
65
-     *
66
-     * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler}
67
-     * @param CriteriaElement               $criteria
68
-     * @param array                         $actions       array representing the actions to offer
69
-     *
70
-     * @param bool                          $userSide
71
-     */
72
-    public function __construct(
73
-        SmartPersistableObjectHandler $objectHandler,
74
-        CriteriaElement $criteria = null,
75
-        $actions = ['edit', 'delete'],
76
-        $userSide = false
77
-    ) {
78
-        $this->_id            = $objectHandler->className;
79
-        $this->_objectHandler = $objectHandler;
80
-
81
-        if (!$criteria) {
82
-            $criteria = new \CriteriaCompo();
83
-        }
84
-        $this->_criteria       = $criteria;
85
-        $this->_actions        = $actions;
86
-        $this->_custom_actions = [];
87
-        $this->_userSide       = $userSide;
88
-        if ($userSide) {
89
-            $this->_head_css_class = 'head';
90
-        }
91
-    }
92
-
93
-    /**
94
-     * @param      $op
95
-     * @param bool $caption
96
-     * @param bool $text
97
-     */
98
-    public function addActionButton($op, $caption = false, $text = false)
99
-    {
100
-        $action                 = [
101
-            'op'      => $op,
102
-            'caption' => $caption,
103
-            'text'    => $text
104
-        ];
105
-        $this->_actionButtons[] = $action;
106
-    }
107
-
108
-    /**
109
-     * @param $columnObj
110
-     */
111
-    public function addColumn($columnObj)
112
-    {
113
-        $this->_columns[] = $columnObj;
114
-    }
115
-
116
-    /**
117
-     * @param $name
118
-     * @param $location
119
-     * @param $value
120
-     */
121
-    public function addIntroButton($name, $location, $value)
122
-    {
123
-        $introButton             = [];
124
-        $introButton['name']     = $name;
125
-        $introButton['location'] = $location;
126
-        $introButton['value']    = $value;
127
-        $this->_introButtons[]   = $introButton;
128
-        unset($introButton);
129
-    }
130
-
131
-    public function addPrinterFriendlyLink()
132
-    {
133
-        $current_urls               = smart_getCurrentUrls();
134
-        $current_url                = $current_urls['full'];
135
-        $this->_printerFriendlyPage = $current_url . '&print';
136
-    }
137
-
138
-    /**
139
-     * @param        $fields
140
-     * @param string $caption
141
-     */
142
-    public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH)
143
-    {
144
-        $this->_quickSearch = ['fields' => $fields, 'caption' => $caption];
145
-    }
146
-
147
-    /**
148
-     * @param $content
149
-     */
150
-    public function addHeader($content)
151
-    {
152
-        $this->_tableHeader = $content;
153
-    }
154
-
155
-    /**
156
-     * @param $content
157
-     */
158
-    public function addFooter($content)
159
-    {
160
-        $this->_tableFooter = $content;
161
-    }
162
-
163
-    /**
164
-     * @param $caption
165
-     */
166
-    public function addDefaultIntroButton($caption)
167
-    {
168
-        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
169
-    }
170
-
171
-    /**
172
-     * @param $method
173
-     */
174
-    public function addCustomAction($method)
175
-    {
176
-        $this->_custom_actions[] = $method;
177
-    }
178
-
179
-    /**
180
-     * @param $default_sort
181
-     */
182
-    public function setDefaultSort($default_sort)
183
-    {
184
-        $this->_sortsel = $default_sort;
185
-    }
186
-
187
-    /**
188
-     * @return string
189
-     */
190
-    public function getDefaultSort()
191
-    {
192
-        if ($this->_sortsel) {
193
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
194
-        } else {
195
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
196
-        }
197
-    }
198
-
199
-    /**
200
-     * @param $default_order
201
-     */
202
-    public function setDefaultOrder($default_order)
203
-    {
204
-        $this->_ordersel = $default_order;
205
-    }
206
-
207
-    /**
208
-     * @return string
209
-     */
210
-    public function getDefaultOrder()
211
-    {
212
-        if ($this->_ordersel) {
213
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
214
-        } else {
215
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
216
-        }
217
-    }
218
-
219
-    /**
220
-     * @param array $actions
221
-     */
222
-    public function addWithSelectedActions($actions = [])
223
-    {
224
-        $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, '&nbsp;'));
225
-        $this->_withSelectedActions = $actions;
226
-    }
227
-
228
-    /**
229
-     * Adding a filter in the table
230
-     *
231
-     * @param string $key    key to the field that will be used for sorting
232
-     * @param string $method method of the handler that will be called to populate the options when this filter is selected
233
-     * @param bool   $default
234
-     */
235
-    public function addFilter($key, $method, $default = false)
236
-    {
237
-        $this->_filterseloptions[$key]   = $method;
238
-        $this->_filtersel2optionsDefault = $default;
239
-    }
240
-
241
-    /**
242
-     * @param $default_filter
243
-     */
244
-    public function setDefaultFilter($default_filter)
245
-    {
246
-        $this->_filtersel = $default_filter;
247
-    }
248
-
249
-    public function isForUserSide()
250
-    {
251
-        $this->_userSide = true;
252
-    }
253
-
254
-    /**
255
-     * @param $template
256
-     */
257
-    public function setCustomTemplate($template)
258
-    {
259
-        $this->_customTemplate = $template;
260
-    }
261
-
262
-    public function setSortOrder()
263
-    {
264
-        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
265
-        //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
266
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
267
-        $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
268
-
269
-        if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
270
-            && $this->_tempObject->vars[$this->_sortsel]['itemName']) {
271
-            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
272
-        } else {
273
-            $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
274
-        }
275
-
276
-        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
277
-        //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
278
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
279
-        $ordersArray = $this->getOrdersArray();
280
-        $this->_criteria->setOrder($this->_ordersel);
281
-    }
282
-
283
-    /**
284
-     * @param $id
285
-     */
286
-    public function setTableId($id)
287
-    {
288
-        $this->_id = $id;
289
-    }
290
-
291
-    /**
292
-     * @param $objects
293
-     */
294
-    public function setObjects($objects)
295
-    {
296
-        $this->_objects = $objects;
297
-    }
298
-
299
-    public function createTableRows()
300
-    {
301
-        $this->_aObjects = [];
302
-
303
-        $doWeHaveActions = false;
304
-
305
-        $objectclass = 'odd';
306
-        if (count($this->_objects) > 0) {
307
-            foreach ($this->_objects as $object) {
308
-                $aObject = [];
309
-
310
-                $i = 0;
311
-
312
-                $aColumns = [];
313
-
314
-                foreach ($this->_columns as $column) {
315
-                    $aColumn = [];
316
-
317
-                    if (0 == $i) {
318
-                        $class = 'head';
319
-                    } elseif (0 == $i % 2) {
320
-                        $class = 'even';
321
-                    } else {
322
-                        $class = 'odd';
323
-                    }
324
-                    if (method_exists($object, 'initiateCustomFields')) {
325
-                        //$object->initiateCustomFields();
326
-                    }
327
-                    if ('checked' === $column->_keyname) {
328
-                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
329
-                    } elseif ($column->_customMethodForValue
330
-                              && method_exists($object, $column->_customMethodForValue)) {
331
-                        $method = $column->_customMethodForValue;
332
-                        if ($column->_param) {
333
-                            $value = $object->$method($column->_param);
334
-                        } else {
335
-                            $value = $object->$method();
336
-                        }
337
-                    } else {
338
-                        /**
339
-                         * If the column is the identifier, then put a link on it
340
-                         */
341
-                        if ($column->getKeyName() == $this->_objectHandler->identifierName) {
342
-                            $value = $object->getItemLink();
343
-                        } else {
344
-                            $value = $object->getVar($column->getKeyName());
345
-                        }
346
-                    }
347
-
348
-                    $aColumn['value'] = $value;
349
-                    $aColumn['class'] = $class;
350
-                    $aColumn['width'] = $column->getWidth();
351
-                    $aColumn['align'] = $column->getAlign();
352
-
353
-                    $aColumns[] = $aColumn;
354
-                    ++$i;
355
-                }
356
-
357
-                $aObject['columns'] = $aColumns;
358
-                $aObject['id']      = $object->id();
359
-
360
-                $objectclass = ('even' === $objectclass) ? 'odd' : 'even';
361
-
362
-                $aObject['class'] = $objectclass;
363
-
364
-                $actions = [];
365
-
366
-                // Adding the custom actions if any
367
-                foreach ($this->_custom_actions as $action) {
368
-                    if (method_exists($object, $action)) {
369
-                        $actions[] = $object->$action();
370
-                    }
371
-                }
372
-
373
-                require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
374
-                $controller = new SmartObjectController($this->_objectHandler);
375
-
376
-                if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
377
-                    $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide);
378
-                }
379
-                if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) {
380
-                    $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide);
381
-                }
382
-                $aObject['actions'] = $actions;
383
-
384
-                $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
385
-
386
-                $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0;
387
-
388
-                $this->_aObjects[] = $aObject;
389
-            }
390
-            $this->_tpl->assign('smartobject_objects', $this->_aObjects);
391
-        } else {
392
-            $colspan = count($this->_columns) + 1;
393
-            $this->_tpl->assign('smartobject_colspan', $colspan);
394
-        }
395
-        $this->_hasActions = $doWeHaveActions;
396
-    }
397
-
398
-    /**
399
-     * @param  bool $debug
400
-     * @return mixed
401
-     */
402
-    public function fetchObjects($debug = false)
403
-    {
404
-        return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug);
405
-    }
406
-
407
-    /**
408
-     * @return string
409
-     */
410
-    public function getDefaultFilter()
411
-    {
412
-        if ($this->_filtersel) {
413
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
414
-        } else {
415
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
416
-        }
417
-    }
418
-
419
-    /**
420
-     * @return array|bool
421
-     */
422
-    public function getFiltersArray()
423
-    {
424
-        $ret               = [];
425
-        $field             = [];
426
-        $field['caption']  = _CO_OBJ_NONE;
427
-        $field['selected'] = '';
428
-        $ret['default']    = $field;
429
-        unset($field);
430
-
431
-        if ($this->_filterseloptions) {
432
-            foreach ($this->_filterseloptions as $key => $value) {
433
-                $field = [];
434
-                if (is_array($value)) {
435
-                    $field['caption']  = $key;
436
-                    $field['selected'] = $this->_filtersel == $key ? 'selected' : '';
437
-                } else {
438
-                    $field['caption']  = $this->_tempObject->vars[$key]['form_caption'];
439
-                    $field['selected'] = $this->_filtersel == $key ? 'selected' : '';
440
-                }
441
-                $ret[$key] = $field;
442
-                unset($field);
443
-            }
444
-        } else {
445
-            $ret = false;
446
-        }
447
-
448
-        return $ret;
449
-    }
450
-
451
-    /**
452
-     * @param $default_filter2
453
-     */
454
-    public function setDefaultFilter2($default_filter2)
455
-    {
456
-        $this->_filtersel2 = $default_filter2;
457
-    }
458
-
459
-    /**
460
-     * @return string
461
-     */
462
-    public function getDefaultFilter2()
463
-    {
464
-        if ($this->_filtersel2) {
465
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
466
-        } else {
467
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
468
-        }
469
-    }
470
-
471
-    /**
472
-     * @return array
473
-     */
474
-    public function getFilters2Array()
475
-    {
476
-        $ret = [];
477
-
478
-        foreach ($this->_filtersel2options as $key => $value) {
479
-            $field             = [];
480
-            $field['caption']  = $value;
481
-            $field['selected'] = $this->_filtersel2 == $key ? 'selected' : '';
482
-            $ret[$key]         = $field;
483
-            unset($field);
484
-        }
485
-
486
-        return $ret;
487
-    }
488
-
489
-    /**
490
-     * @param $limitsArray
491
-     * @param $params_of_the_options_sel
492
-     */
493
-    public function renderOptionSelection($limitsArray, $params_of_the_options_sel)
494
-    {
495
-        // Rendering the form to select options on the table
496
-        $current_urls = smart_getCurrentUrls();
497
-        $current_url  = $current_urls['full'];
498
-
499
-        /**
500
-         * What was $params_of_the_options_sel doing again ?
501
-         */
502
-        //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel));
503
-        $this->_tpl->assign('smartobject_optionssel_action', $current_url);
504
-        $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray);
505
-    }
506
-
507
-    /**
508
-     * @return array
509
-     */
510
-    public function getLimitsArray()
511
-    {
512
-        $ret                    = [];
513
-        $ret['all']['caption']  = _CO_SOBJECT_LIMIT_ALL;
514
-        $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : '';
515
-
516
-        $ret['5']['caption']  = '5';
517
-        $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : '';
518
-
519
-        $ret['10']['caption']  = '10';
520
-        $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : '';
521
-
522
-        $ret['15']['caption']  = '15';
523
-        $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : '';
524
-
525
-        $ret['20']['caption']  = '20';
526
-        $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : '';
527
-
528
-        $ret['25']['caption']  = '25';
529
-        $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : '';
530
-
531
-        $ret['30']['caption']  = '30';
532
-        $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : '';
533
-
534
-        $ret['35']['caption']  = '35';
535
-        $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : '';
536
-
537
-        $ret['40']['caption']  = '40';
538
-        $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : '';
539
-
540
-        return $ret;
541
-    }
542
-
543
-    /**
544
-     * @return bool
545
-     */
546
-    public function getObjects()
547
-    {
548
-        return $this->_objects;
549
-    }
550
-
551
-    public function hideActionColumnTitle()
552
-    {
553
-        $this->_showActionsColumnTitle = false;
554
-    }
555
-
556
-    public function hideFilterAndLimit()
557
-    {
558
-        $this->_showFilterAndLimit = false;
559
-    }
560
-
561
-    /**
562
-     * @return array
563
-     */
564
-    public function getOrdersArray()
565
-    {
566
-        $ret                    = [];
567
-        $ret['ASC']['caption']  = _CO_SOBJECT_SORT_ASC;
568
-        $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : '';
569
-
570
-        $ret['DESC']['caption']  = _CO_SOBJECT_SORT_DESC;
571
-        $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : '';
572
-
573
-        return $ret;
574
-    }
575
-
576
-    /**
577
-     * @return mixed|string|void
578
-     */
579
-    public function renderD()
580
-    {
581
-        return $this->render(false, true);
582
-    }
583
-
584
-    public function renderForPrint()
585
-    {
586
-    }
587
-
588
-    /**
589
-     * @param  bool $fetchOnly
590
-     * @param  bool $debug
591
-     * @return mixed|string|void
592
-     */
593
-    public function render($fetchOnly = false, $debug = false)
594
-    {
595
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
596
-
597
-        $this->_tpl = new \XoopsTpl();
598
-
599
-        /**
600
-         * We need access to the vars of the SmartObject for a few things in the table creation.
601
-         * Since we may not have a SmartObject to look into now, let's create one for this purpose
602
-         * and we will free it after
603
-         */
604
-        $this->_tempObject = $this->_objectHandler->create();
605
-
606
-        $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
607
-
608
-        $this->setSortOrder();
609
-
610
-        if (!$this->_isTree) {
611
-            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
612
-        } else {
613
-            $this->_limitsel = 'all';
614
-        }
615
-
616
-        $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
617
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
618
-        $limitsArray = $this->getLimitsArray();
619
-        $this->_criteria->setLimit($this->_limitsel);
620
-
621
-        $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
622
-        $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
623
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
624
-        $filtersArray = $this->getFiltersArray();
625
-
626
-        if ($filtersArray) {
627
-            $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray);
628
-        }
629
-
630
-        // Check if the selected filter is defined and if so, create the selfilter2
631
-        if (isset($this->_filterseloptions[$this->_filtersel])) {
632
-            // check if method associate with this filter exists in the handler
633
-            if (is_array($this->_filterseloptions[$this->_filtersel])) {
634
-                $filter = $this->_filterseloptions[$this->_filtersel];
635
-                $this->_criteria->add($filter['criteria']);
636
-            } else {
637
-                if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) {
638
-
639
-                    // then we will create the selfilter2 options by calling this method
640
-                    $method                   = $this->_filterseloptions[$this->_filtersel];
641
-                    $this->_filtersel2options = $this->_objectHandler->$method();
642
-
643
-                    $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2();
644
-                    $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2;
645
-
646
-                    $filters2Array = $this->getFilters2Array();
647
-                    $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
648
-
649
-                    smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
650
-                    if ('default' !== $this->_filtersel2) {
651
-                        $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2));
652
-                    }
653
-                }
654
-            }
655
-        }
656
-        // Check if we have a quicksearch
657
-
658
-        if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
659
-            $quicksearch_criteria = new \CriteriaCompo();
660
-            if (is_array($this->_quickSearch['fields'])) {
661
-                foreach ($this->_quickSearch['fields'] as $v) {
662
-                    $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
663
-                }
664
-            } else {
665
-                $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
666
-            }
667
-            $this->_criteria->add($quicksearch_criteria);
668
-        }
669
-
670
-        $this->_objects = $this->fetchObjects($debug);
671
-
672
-        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
673
-        if ($this->_criteria->getLimit() > 0) {
674
-
675
-            /**
676
-             * Geeting rid of the old params
677
-             * $new_get_array is an array containing the new GET parameters
678
-             */
679
-            $new_get_array = [];
680
-
681
-            /**
682
-             * $params_of_the_options_sel is an array with all the parameters of the page
683
-             * but without the pagenave parameters. This array will be used in the
684
-             * OptionsSelection
685
-             */
686
-            $params_of_the_options_sel = [];
687
-
688
-            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
689
-            foreach ($_GET as $k => $v) {
690
-                if (!in_array($k, $not_needed_params)) {
691
-                    $new_get_array[]             = "$k=$v";
692
-                    $params_of_the_options_sel[] = "$k=$v";
693
-                }
694
-            }
695
-
696
-            /**
697
-             * Adding the new params of the pagenav
698
-             */
699
-            $new_get_array[] = 'sortsel=' . $this->_sortsel;
700
-            $new_get_array[] = 'ordersel=' . $this->_ordersel;
701
-            $new_get_array[] = 'limitsel=' . $this->_limitsel;
702
-            $otherParams     = implode('&', $new_get_array);
703
-
704
-            $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
705
-            $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
706
-        }
707
-        $this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
708
-
709
-        // retreive the current url and the query string
710
-        $current_urls = smart_getCurrentUrls();
711
-        $current_url  = $current_urls['full_phpself'];
712
-        $query_string = $current_urls['querystring'];
713
-        if ($query_string) {
714
-            $query_string = str_replace('?', '', $query_string);
715
-        }
716
-        $query_stringArray     = explode('&', $query_string);
717
-        $new_query_stringArray = [];
718
-        foreach ($query_stringArray as $query_string) {
719
-            if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) {
720
-                $new_query_stringArray[] = $query_string;
721
-            }
722
-        }
723
-        $new_query_string = implode('&', $new_query_stringArray);
724
-
725
-        $orderArray                     = [];
726
-        $orderArray['ASC']['image']     = 'desc.png';
727
-        $orderArray['ASC']['neworder']  = 'DESC';
728
-        $orderArray['DESC']['image']    = 'asc.png';
729
-        $orderArray['DESC']['neworder'] = 'ASC';
730
-
731
-        $aColumns = [];
732
-
733
-        foreach ($this->_columns as $column) {
734
-            $qs_param         = '';
735
-            $aColumn          = [];
736
-            $aColumn['width'] = $column->getWidth();
737
-            $aColumn['align'] = $column->getAlign();
738
-            $aColumn['key']   = $column->getKeyName();
739
-            if ('checked' === $column->_keyname) {
740
-                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
741
-            } elseif ($column->getCustomCaption()) {
742
-                $aColumn['caption'] = $column->getCustomCaption();
743
-            } else {
744
-                $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
745
-            }
746
-            // Are we doing a GET sort on this column ?
747
-            $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
748
-                        && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
749
-                       || ($this->_sortsel == $column->getKeyName());
750
-            $order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
751
-
752
-            if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
753
-                $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
754
-            }
755
-            if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
756
-                $aColumn['caption'] = $aColumn['caption'];
757
-            } elseif ($getSort) {
758
-                $aColumn['caption'] = '<a href="'
759
-                                      . $current_url
760
-                                      . '?'
761
-                                      . $this->_objectHandler->_itemname
762
-                                      . '_'
763
-                                      . 'sortsel='
764
-                                      . $column->getKeyName()
765
-                                      . '&'
766
-                                      . $this->_objectHandler->_itemname
767
-                                      . '_'
768
-                                      . 'ordersel='
769
-                                      . $orderArray[$order]['neworder']
770
-                                      . $qs_param
771
-                                      . '&'
772
-                                      . $new_query_string
773
-                                      . '">'
774
-                                      . $aColumn['caption']
775
-                                      . ' <img src="'
776
-                                      . SMARTOBJECT_IMAGES_ACTIONS_URL
777
-                                      . $orderArray[$order]['image']
778
-                                      . '" alt="ASC"></a>';
779
-            } else {
780
-                $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
781
-            }
782
-            $aColumns[] = $aColumn;
783
-        }
784
-        $this->_tpl->assign('smartobject_columns', $aColumns);
785
-
786
-        if ($this->_quickSearch) {
787
-            $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']);
788
-        }
789
-
790
-        $this->createTableRows();
791
-
792
-        $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit);
793
-        $this->_tpl->assign('smartobject_isTree', $this->_isTree);
794
-        $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle);
795
-        $this->_tpl->assign('smartobject_table_header', $this->_tableHeader);
796
-        $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter);
797
-        $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage);
798
-        $this->_tpl->assign('smartobject_user_side', $this->_userSide);
799
-        $this->_tpl->assign('smartobject_has_actions', $this->_hasActions);
800
-        $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class);
801
-        $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons);
802
-        $this->_tpl->assign('smartobject_introButtons', $this->_introButtons);
803
-        $this->_tpl->assign('smartobject_id', $this->_id);
804
-        if (!empty($this->_withSelectedActions)) {
805
-            $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions);
806
-        }
807
-
808
-        $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
809
-        if ($fetchOnly) {
810
-            return $this->_tpl->fetch('db:' . $smartobjectTable_template);
811
-        } else {
812
-            $this->_tpl->display('db:' . $smartobjectTable_template);
813
-        }
814
-    }
815
-
816
-    public function disableColumnsSorting()
817
-    {
818
-        $this->_enableColumnsSorting = false;
819
-    }
820
-
821
-    /**
822
-     * @param  bool $debug
823
-     * @return mixed|string|void
824
-     */
825
-    public function fetch($debug = false)
826
-    {
827
-        return $this->render(true, $debug);
828
-    }
28
+	public $_id;
29
+	public $_objectHandler;
30
+	public $_columns;
31
+	public $_criteria;
32
+	public $_actions;
33
+	public $_objects = false;
34
+	public $_aObjects;
35
+	public $_custom_actions;
36
+	public $_sortsel;
37
+	public $_ordersel;
38
+	public $_limitsel;
39
+	public $_filtersel;
40
+	public $_filterseloptions;
41
+	public $_filtersel2;
42
+	public $_filtersel2options;
43
+	public $_filtersel2optionsDefault;
44
+
45
+	public $_tempObject;
46
+	public $_tpl;
47
+	public $_introButtons;
48
+	public $_quickSearch            = false;
49
+	public $_actionButtons          = false;
50
+	public $_head_css_class         = 'bg3';
51
+	public $_hasActions             = false;
52
+	public $_userSide               = false;
53
+	public $_printerFriendlyPage    = false;
54
+	public $_tableHeader            = false;
55
+	public $_tableFooter            = false;
56
+	public $_showActionsColumnTitle = true;
57
+	public $_isTree                 = false;
58
+	public $_showFilterAndLimit     = true;
59
+	public $_enableColumnsSorting   = true;
60
+	public $_customTemplate         = false;
61
+	public $_withSelectedActions    = [];
62
+
63
+	/**
64
+	 * Constructor
65
+	 *
66
+	 * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler}
67
+	 * @param CriteriaElement               $criteria
68
+	 * @param array                         $actions       array representing the actions to offer
69
+	 *
70
+	 * @param bool                          $userSide
71
+	 */
72
+	public function __construct(
73
+		SmartPersistableObjectHandler $objectHandler,
74
+		CriteriaElement $criteria = null,
75
+		$actions = ['edit', 'delete'],
76
+		$userSide = false
77
+	) {
78
+		$this->_id            = $objectHandler->className;
79
+		$this->_objectHandler = $objectHandler;
80
+
81
+		if (!$criteria) {
82
+			$criteria = new \CriteriaCompo();
83
+		}
84
+		$this->_criteria       = $criteria;
85
+		$this->_actions        = $actions;
86
+		$this->_custom_actions = [];
87
+		$this->_userSide       = $userSide;
88
+		if ($userSide) {
89
+			$this->_head_css_class = 'head';
90
+		}
91
+	}
92
+
93
+	/**
94
+	 * @param      $op
95
+	 * @param bool $caption
96
+	 * @param bool $text
97
+	 */
98
+	public function addActionButton($op, $caption = false, $text = false)
99
+	{
100
+		$action                 = [
101
+			'op'      => $op,
102
+			'caption' => $caption,
103
+			'text'    => $text
104
+		];
105
+		$this->_actionButtons[] = $action;
106
+	}
107
+
108
+	/**
109
+	 * @param $columnObj
110
+	 */
111
+	public function addColumn($columnObj)
112
+	{
113
+		$this->_columns[] = $columnObj;
114
+	}
115
+
116
+	/**
117
+	 * @param $name
118
+	 * @param $location
119
+	 * @param $value
120
+	 */
121
+	public function addIntroButton($name, $location, $value)
122
+	{
123
+		$introButton             = [];
124
+		$introButton['name']     = $name;
125
+		$introButton['location'] = $location;
126
+		$introButton['value']    = $value;
127
+		$this->_introButtons[]   = $introButton;
128
+		unset($introButton);
129
+	}
130
+
131
+	public function addPrinterFriendlyLink()
132
+	{
133
+		$current_urls               = smart_getCurrentUrls();
134
+		$current_url                = $current_urls['full'];
135
+		$this->_printerFriendlyPage = $current_url . '&print';
136
+	}
137
+
138
+	/**
139
+	 * @param        $fields
140
+	 * @param string $caption
141
+	 */
142
+	public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH)
143
+	{
144
+		$this->_quickSearch = ['fields' => $fields, 'caption' => $caption];
145
+	}
146
+
147
+	/**
148
+	 * @param $content
149
+	 */
150
+	public function addHeader($content)
151
+	{
152
+		$this->_tableHeader = $content;
153
+	}
154
+
155
+	/**
156
+	 * @param $content
157
+	 */
158
+	public function addFooter($content)
159
+	{
160
+		$this->_tableFooter = $content;
161
+	}
162
+
163
+	/**
164
+	 * @param $caption
165
+	 */
166
+	public function addDefaultIntroButton($caption)
167
+	{
168
+		$this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
169
+	}
170
+
171
+	/**
172
+	 * @param $method
173
+	 */
174
+	public function addCustomAction($method)
175
+	{
176
+		$this->_custom_actions[] = $method;
177
+	}
178
+
179
+	/**
180
+	 * @param $default_sort
181
+	 */
182
+	public function setDefaultSort($default_sort)
183
+	{
184
+		$this->_sortsel = $default_sort;
185
+	}
186
+
187
+	/**
188
+	 * @return string
189
+	 */
190
+	public function getDefaultSort()
191
+	{
192
+		if ($this->_sortsel) {
193
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
194
+		} else {
195
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
196
+		}
197
+	}
198
+
199
+	/**
200
+	 * @param $default_order
201
+	 */
202
+	public function setDefaultOrder($default_order)
203
+	{
204
+		$this->_ordersel = $default_order;
205
+	}
206
+
207
+	/**
208
+	 * @return string
209
+	 */
210
+	public function getDefaultOrder()
211
+	{
212
+		if ($this->_ordersel) {
213
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
214
+		} else {
215
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
216
+		}
217
+	}
218
+
219
+	/**
220
+	 * @param array $actions
221
+	 */
222
+	public function addWithSelectedActions($actions = [])
223
+	{
224
+		$this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, '&nbsp;'));
225
+		$this->_withSelectedActions = $actions;
226
+	}
227
+
228
+	/**
229
+	 * Adding a filter in the table
230
+	 *
231
+	 * @param string $key    key to the field that will be used for sorting
232
+	 * @param string $method method of the handler that will be called to populate the options when this filter is selected
233
+	 * @param bool   $default
234
+	 */
235
+	public function addFilter($key, $method, $default = false)
236
+	{
237
+		$this->_filterseloptions[$key]   = $method;
238
+		$this->_filtersel2optionsDefault = $default;
239
+	}
240
+
241
+	/**
242
+	 * @param $default_filter
243
+	 */
244
+	public function setDefaultFilter($default_filter)
245
+	{
246
+		$this->_filtersel = $default_filter;
247
+	}
248
+
249
+	public function isForUserSide()
250
+	{
251
+		$this->_userSide = true;
252
+	}
253
+
254
+	/**
255
+	 * @param $template
256
+	 */
257
+	public function setCustomTemplate($template)
258
+	{
259
+		$this->_customTemplate = $template;
260
+	}
261
+
262
+	public function setSortOrder()
263
+	{
264
+		$this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
265
+		//$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
266
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
267
+		$fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
268
+
269
+		if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
270
+			&& $this->_tempObject->vars[$this->_sortsel]['itemName']) {
271
+			$this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
272
+		} else {
273
+			$this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
274
+		}
275
+
276
+		$this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
277
+		//$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
278
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
279
+		$ordersArray = $this->getOrdersArray();
280
+		$this->_criteria->setOrder($this->_ordersel);
281
+	}
282
+
283
+	/**
284
+	 * @param $id
285
+	 */
286
+	public function setTableId($id)
287
+	{
288
+		$this->_id = $id;
289
+	}
290
+
291
+	/**
292
+	 * @param $objects
293
+	 */
294
+	public function setObjects($objects)
295
+	{
296
+		$this->_objects = $objects;
297
+	}
298
+
299
+	public function createTableRows()
300
+	{
301
+		$this->_aObjects = [];
302
+
303
+		$doWeHaveActions = false;
304
+
305
+		$objectclass = 'odd';
306
+		if (count($this->_objects) > 0) {
307
+			foreach ($this->_objects as $object) {
308
+				$aObject = [];
309
+
310
+				$i = 0;
311
+
312
+				$aColumns = [];
313
+
314
+				foreach ($this->_columns as $column) {
315
+					$aColumn = [];
316
+
317
+					if (0 == $i) {
318
+						$class = 'head';
319
+					} elseif (0 == $i % 2) {
320
+						$class = 'even';
321
+					} else {
322
+						$class = 'odd';
323
+					}
324
+					if (method_exists($object, 'initiateCustomFields')) {
325
+						//$object->initiateCustomFields();
326
+					}
327
+					if ('checked' === $column->_keyname) {
328
+						$value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
329
+					} elseif ($column->_customMethodForValue
330
+							  && method_exists($object, $column->_customMethodForValue)) {
331
+						$method = $column->_customMethodForValue;
332
+						if ($column->_param) {
333
+							$value = $object->$method($column->_param);
334
+						} else {
335
+							$value = $object->$method();
336
+						}
337
+					} else {
338
+						/**
339
+						 * If the column is the identifier, then put a link on it
340
+						 */
341
+						if ($column->getKeyName() == $this->_objectHandler->identifierName) {
342
+							$value = $object->getItemLink();
343
+						} else {
344
+							$value = $object->getVar($column->getKeyName());
345
+						}
346
+					}
347
+
348
+					$aColumn['value'] = $value;
349
+					$aColumn['class'] = $class;
350
+					$aColumn['width'] = $column->getWidth();
351
+					$aColumn['align'] = $column->getAlign();
352
+
353
+					$aColumns[] = $aColumn;
354
+					++$i;
355
+				}
356
+
357
+				$aObject['columns'] = $aColumns;
358
+				$aObject['id']      = $object->id();
359
+
360
+				$objectclass = ('even' === $objectclass) ? 'odd' : 'even';
361
+
362
+				$aObject['class'] = $objectclass;
363
+
364
+				$actions = [];
365
+
366
+				// Adding the custom actions if any
367
+				foreach ($this->_custom_actions as $action) {
368
+					if (method_exists($object, $action)) {
369
+						$actions[] = $object->$action();
370
+					}
371
+				}
372
+
373
+				require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
374
+				$controller = new SmartObjectController($this->_objectHandler);
375
+
376
+				if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
377
+					$actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide);
378
+				}
379
+				if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) {
380
+					$actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide);
381
+				}
382
+				$aObject['actions'] = $actions;
383
+
384
+				$this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
385
+
386
+				$doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0;
387
+
388
+				$this->_aObjects[] = $aObject;
389
+			}
390
+			$this->_tpl->assign('smartobject_objects', $this->_aObjects);
391
+		} else {
392
+			$colspan = count($this->_columns) + 1;
393
+			$this->_tpl->assign('smartobject_colspan', $colspan);
394
+		}
395
+		$this->_hasActions = $doWeHaveActions;
396
+	}
397
+
398
+	/**
399
+	 * @param  bool $debug
400
+	 * @return mixed
401
+	 */
402
+	public function fetchObjects($debug = false)
403
+	{
404
+		return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug);
405
+	}
406
+
407
+	/**
408
+	 * @return string
409
+	 */
410
+	public function getDefaultFilter()
411
+	{
412
+		if ($this->_filtersel) {
413
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
414
+		} else {
415
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
416
+		}
417
+	}
418
+
419
+	/**
420
+	 * @return array|bool
421
+	 */
422
+	public function getFiltersArray()
423
+	{
424
+		$ret               = [];
425
+		$field             = [];
426
+		$field['caption']  = _CO_OBJ_NONE;
427
+		$field['selected'] = '';
428
+		$ret['default']    = $field;
429
+		unset($field);
430
+
431
+		if ($this->_filterseloptions) {
432
+			foreach ($this->_filterseloptions as $key => $value) {
433
+				$field = [];
434
+				if (is_array($value)) {
435
+					$field['caption']  = $key;
436
+					$field['selected'] = $this->_filtersel == $key ? 'selected' : '';
437
+				} else {
438
+					$field['caption']  = $this->_tempObject->vars[$key]['form_caption'];
439
+					$field['selected'] = $this->_filtersel == $key ? 'selected' : '';
440
+				}
441
+				$ret[$key] = $field;
442
+				unset($field);
443
+			}
444
+		} else {
445
+			$ret = false;
446
+		}
447
+
448
+		return $ret;
449
+	}
450
+
451
+	/**
452
+	 * @param $default_filter2
453
+	 */
454
+	public function setDefaultFilter2($default_filter2)
455
+	{
456
+		$this->_filtersel2 = $default_filter2;
457
+	}
458
+
459
+	/**
460
+	 * @return string
461
+	 */
462
+	public function getDefaultFilter2()
463
+	{
464
+		if ($this->_filtersel2) {
465
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
466
+		} else {
467
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
468
+		}
469
+	}
470
+
471
+	/**
472
+	 * @return array
473
+	 */
474
+	public function getFilters2Array()
475
+	{
476
+		$ret = [];
477
+
478
+		foreach ($this->_filtersel2options as $key => $value) {
479
+			$field             = [];
480
+			$field['caption']  = $value;
481
+			$field['selected'] = $this->_filtersel2 == $key ? 'selected' : '';
482
+			$ret[$key]         = $field;
483
+			unset($field);
484
+		}
485
+
486
+		return $ret;
487
+	}
488
+
489
+	/**
490
+	 * @param $limitsArray
491
+	 * @param $params_of_the_options_sel
492
+	 */
493
+	public function renderOptionSelection($limitsArray, $params_of_the_options_sel)
494
+	{
495
+		// Rendering the form to select options on the table
496
+		$current_urls = smart_getCurrentUrls();
497
+		$current_url  = $current_urls['full'];
498
+
499
+		/**
500
+		 * What was $params_of_the_options_sel doing again ?
501
+		 */
502
+		//$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel));
503
+		$this->_tpl->assign('smartobject_optionssel_action', $current_url);
504
+		$this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray);
505
+	}
506
+
507
+	/**
508
+	 * @return array
509
+	 */
510
+	public function getLimitsArray()
511
+	{
512
+		$ret                    = [];
513
+		$ret['all']['caption']  = _CO_SOBJECT_LIMIT_ALL;
514
+		$ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : '';
515
+
516
+		$ret['5']['caption']  = '5';
517
+		$ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : '';
518
+
519
+		$ret['10']['caption']  = '10';
520
+		$ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : '';
521
+
522
+		$ret['15']['caption']  = '15';
523
+		$ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : '';
524
+
525
+		$ret['20']['caption']  = '20';
526
+		$ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : '';
527
+
528
+		$ret['25']['caption']  = '25';
529
+		$ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : '';
530
+
531
+		$ret['30']['caption']  = '30';
532
+		$ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : '';
533
+
534
+		$ret['35']['caption']  = '35';
535
+		$ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : '';
536
+
537
+		$ret['40']['caption']  = '40';
538
+		$ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : '';
539
+
540
+		return $ret;
541
+	}
542
+
543
+	/**
544
+	 * @return bool
545
+	 */
546
+	public function getObjects()
547
+	{
548
+		return $this->_objects;
549
+	}
550
+
551
+	public function hideActionColumnTitle()
552
+	{
553
+		$this->_showActionsColumnTitle = false;
554
+	}
555
+
556
+	public function hideFilterAndLimit()
557
+	{
558
+		$this->_showFilterAndLimit = false;
559
+	}
560
+
561
+	/**
562
+	 * @return array
563
+	 */
564
+	public function getOrdersArray()
565
+	{
566
+		$ret                    = [];
567
+		$ret['ASC']['caption']  = _CO_SOBJECT_SORT_ASC;
568
+		$ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : '';
569
+
570
+		$ret['DESC']['caption']  = _CO_SOBJECT_SORT_DESC;
571
+		$ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : '';
572
+
573
+		return $ret;
574
+	}
575
+
576
+	/**
577
+	 * @return mixed|string|void
578
+	 */
579
+	public function renderD()
580
+	{
581
+		return $this->render(false, true);
582
+	}
583
+
584
+	public function renderForPrint()
585
+	{
586
+	}
587
+
588
+	/**
589
+	 * @param  bool $fetchOnly
590
+	 * @param  bool $debug
591
+	 * @return mixed|string|void
592
+	 */
593
+	public function render($fetchOnly = false, $debug = false)
594
+	{
595
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
596
+
597
+		$this->_tpl = new \XoopsTpl();
598
+
599
+		/**
600
+		 * We need access to the vars of the SmartObject for a few things in the table creation.
601
+		 * Since we may not have a SmartObject to look into now, let's create one for this purpose
602
+		 * and we will free it after
603
+		 */
604
+		$this->_tempObject = $this->_objectHandler->create();
605
+
606
+		$this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
607
+
608
+		$this->setSortOrder();
609
+
610
+		if (!$this->_isTree) {
611
+			$this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
612
+		} else {
613
+			$this->_limitsel = 'all';
614
+		}
615
+
616
+		$this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
617
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
618
+		$limitsArray = $this->getLimitsArray();
619
+		$this->_criteria->setLimit($this->_limitsel);
620
+
621
+		$this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
622
+		$this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
623
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
624
+		$filtersArray = $this->getFiltersArray();
625
+
626
+		if ($filtersArray) {
627
+			$this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray);
628
+		}
629
+
630
+		// Check if the selected filter is defined and if so, create the selfilter2
631
+		if (isset($this->_filterseloptions[$this->_filtersel])) {
632
+			// check if method associate with this filter exists in the handler
633
+			if (is_array($this->_filterseloptions[$this->_filtersel])) {
634
+				$filter = $this->_filterseloptions[$this->_filtersel];
635
+				$this->_criteria->add($filter['criteria']);
636
+			} else {
637
+				if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) {
638
+
639
+					// then we will create the selfilter2 options by calling this method
640
+					$method                   = $this->_filterseloptions[$this->_filtersel];
641
+					$this->_filtersel2options = $this->_objectHandler->$method();
642
+
643
+					$this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2();
644
+					$this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2;
645
+
646
+					$filters2Array = $this->getFilters2Array();
647
+					$this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
648
+
649
+					smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
650
+					if ('default' !== $this->_filtersel2) {
651
+						$this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2));
652
+					}
653
+				}
654
+			}
655
+		}
656
+		// Check if we have a quicksearch
657
+
658
+		if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
659
+			$quicksearch_criteria = new \CriteriaCompo();
660
+			if (is_array($this->_quickSearch['fields'])) {
661
+				foreach ($this->_quickSearch['fields'] as $v) {
662
+					$quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
663
+				}
664
+			} else {
665
+				$quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
666
+			}
667
+			$this->_criteria->add($quicksearch_criteria);
668
+		}
669
+
670
+		$this->_objects = $this->fetchObjects($debug);
671
+
672
+		require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
673
+		if ($this->_criteria->getLimit() > 0) {
674
+
675
+			/**
676
+			 * Geeting rid of the old params
677
+			 * $new_get_array is an array containing the new GET parameters
678
+			 */
679
+			$new_get_array = [];
680
+
681
+			/**
682
+			 * $params_of_the_options_sel is an array with all the parameters of the page
683
+			 * but without the pagenave parameters. This array will be used in the
684
+			 * OptionsSelection
685
+			 */
686
+			$params_of_the_options_sel = [];
687
+
688
+			$not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
689
+			foreach ($_GET as $k => $v) {
690
+				if (!in_array($k, $not_needed_params)) {
691
+					$new_get_array[]             = "$k=$v";
692
+					$params_of_the_options_sel[] = "$k=$v";
693
+				}
694
+			}
695
+
696
+			/**
697
+			 * Adding the new params of the pagenav
698
+			 */
699
+			$new_get_array[] = 'sortsel=' . $this->_sortsel;
700
+			$new_get_array[] = 'ordersel=' . $this->_ordersel;
701
+			$new_get_array[] = 'limitsel=' . $this->_limitsel;
702
+			$otherParams     = implode('&', $new_get_array);
703
+
704
+			$pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
705
+			$this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
706
+		}
707
+		$this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
708
+
709
+		// retreive the current url and the query string
710
+		$current_urls = smart_getCurrentUrls();
711
+		$current_url  = $current_urls['full_phpself'];
712
+		$query_string = $current_urls['querystring'];
713
+		if ($query_string) {
714
+			$query_string = str_replace('?', '', $query_string);
715
+		}
716
+		$query_stringArray     = explode('&', $query_string);
717
+		$new_query_stringArray = [];
718
+		foreach ($query_stringArray as $query_string) {
719
+			if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) {
720
+				$new_query_stringArray[] = $query_string;
721
+			}
722
+		}
723
+		$new_query_string = implode('&', $new_query_stringArray);
724
+
725
+		$orderArray                     = [];
726
+		$orderArray['ASC']['image']     = 'desc.png';
727
+		$orderArray['ASC']['neworder']  = 'DESC';
728
+		$orderArray['DESC']['image']    = 'asc.png';
729
+		$orderArray['DESC']['neworder'] = 'ASC';
730
+
731
+		$aColumns = [];
732
+
733
+		foreach ($this->_columns as $column) {
734
+			$qs_param         = '';
735
+			$aColumn          = [];
736
+			$aColumn['width'] = $column->getWidth();
737
+			$aColumn['align'] = $column->getAlign();
738
+			$aColumn['key']   = $column->getKeyName();
739
+			if ('checked' === $column->_keyname) {
740
+				$aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
741
+			} elseif ($column->getCustomCaption()) {
742
+				$aColumn['caption'] = $column->getCustomCaption();
743
+			} else {
744
+				$aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
745
+			}
746
+			// Are we doing a GET sort on this column ?
747
+			$getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
748
+						&& $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
749
+					   || ($this->_sortsel == $column->getKeyName());
750
+			$order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
751
+
752
+			if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
753
+				$qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
754
+			}
755
+			if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
756
+				$aColumn['caption'] = $aColumn['caption'];
757
+			} elseif ($getSort) {
758
+				$aColumn['caption'] = '<a href="'
759
+									  . $current_url
760
+									  . '?'
761
+									  . $this->_objectHandler->_itemname
762
+									  . '_'
763
+									  . 'sortsel='
764
+									  . $column->getKeyName()
765
+									  . '&'
766
+									  . $this->_objectHandler->_itemname
767
+									  . '_'
768
+									  . 'ordersel='
769
+									  . $orderArray[$order]['neworder']
770
+									  . $qs_param
771
+									  . '&'
772
+									  . $new_query_string
773
+									  . '">'
774
+									  . $aColumn['caption']
775
+									  . ' <img src="'
776
+									  . SMARTOBJECT_IMAGES_ACTIONS_URL
777
+									  . $orderArray[$order]['image']
778
+									  . '" alt="ASC"></a>';
779
+			} else {
780
+				$aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
781
+			}
782
+			$aColumns[] = $aColumn;
783
+		}
784
+		$this->_tpl->assign('smartobject_columns', $aColumns);
785
+
786
+		if ($this->_quickSearch) {
787
+			$this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']);
788
+		}
789
+
790
+		$this->createTableRows();
791
+
792
+		$this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit);
793
+		$this->_tpl->assign('smartobject_isTree', $this->_isTree);
794
+		$this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle);
795
+		$this->_tpl->assign('smartobject_table_header', $this->_tableHeader);
796
+		$this->_tpl->assign('smartobject_table_footer', $this->_tableFooter);
797
+		$this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage);
798
+		$this->_tpl->assign('smartobject_user_side', $this->_userSide);
799
+		$this->_tpl->assign('smartobject_has_actions', $this->_hasActions);
800
+		$this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class);
801
+		$this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons);
802
+		$this->_tpl->assign('smartobject_introButtons', $this->_introButtons);
803
+		$this->_tpl->assign('smartobject_id', $this->_id);
804
+		if (!empty($this->_withSelectedActions)) {
805
+			$this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions);
806
+		}
807
+
808
+		$smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
809
+		if ($fetchOnly) {
810
+			return $this->_tpl->fetch('db:' . $smartobjectTable_template);
811
+		} else {
812
+			$this->_tpl->display('db:' . $smartobjectTable_template);
813
+		}
814
+	}
815
+
816
+	public function disableColumnsSorting()
817
+	{
818
+		$this->_enableColumnsSorting = false;
819
+	}
820
+
821
+	/**
822
+	 * @param  bool $debug
823
+	 * @return mixed|string|void
824
+	 */
825
+	public function fetch($debug = false)
826
+	{
827
+		return $this->render(true, $debug);
828
+	}
829 829
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function addActionButton($op, $caption = false, $text = false)
99 99
     {
100
-        $action                 = [
100
+        $action = [
101 101
             'op'      => $op,
102 102
             'caption' => $caption,
103 103
             'text'    => $text
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     {
133 133
         $current_urls               = smart_getCurrentUrls();
134 134
         $current_url                = $current_urls['full'];
135
-        $this->_printerFriendlyPage = $current_url . '&print';
135
+        $this->_printerFriendlyPage = $current_url.'&print';
136 136
     }
137 137
 
138 138
     /**
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      */
166 166
     public function addDefaultIntroButton($caption)
167 167
     {
168
-        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
168
+        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption);
169 169
     }
170 170
 
171 171
     /**
@@ -190,9 +190,9 @@  discard block
 block discarded – undo
190 190
     public function getDefaultSort()
191 191
     {
192 192
         if ($this->_sortsel) {
193
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
193
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel);
194 194
         } else {
195
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
195
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName);
196 196
         }
197 197
     }
198 198
 
@@ -210,9 +210,9 @@  discard block
 block discarded – undo
210 210
     public function getDefaultOrder()
211 211
     {
212 212
         if ($this->_ordersel) {
213
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
213
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel);
214 214
         } else {
215
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
215
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC');
216 216
         }
217 217
     }
218 218
 
@@ -261,21 +261,21 @@  discard block
 block discarded – undo
261 261
 
262 262
     public function setSortOrder()
263 263
     {
264
-        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
264
+        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort();
265 265
         //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
266
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
266
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel);
267 267
         $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
268 268
 
269 269
         if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
270 270
             && $this->_tempObject->vars[$this->_sortsel]['itemName']) {
271
-            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
271
+            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel);
272 272
         } else {
273
-            $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
273
+            $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel);
274 274
         }
275 275
 
276
-        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
276
+        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder();
277 277
         //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
278
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
278
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel);
279 279
         $ordersArray = $this->getOrdersArray();
280 280
         $this->_criteria->setOrder($this->_ordersel);
281 281
     }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
                         //$object->initiateCustomFields();
326 326
                     }
327 327
                     if ('checked' === $column->_keyname) {
328
-                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
328
+                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">';
329 329
                     } elseif ($column->_customMethodForValue
330 330
                               && method_exists($object, $column->_customMethodForValue)) {
331 331
                         $method = $column->_customMethodForValue;
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
                     }
371 371
                 }
372 372
 
373
-                require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
373
+                require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
374 374
                 $controller = new SmartObjectController($this->_objectHandler);
375 375
 
376 376
                 if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
@@ -410,9 +410,9 @@  discard block
 block discarded – undo
410 410
     public function getDefaultFilter()
411 411
     {
412 412
         if ($this->_filtersel) {
413
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
413
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel);
414 414
         } else {
415
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
415
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default');
416 416
         }
417 417
     }
418 418
 
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
     public function getDefaultFilter2()
463 463
     {
464 464
         if ($this->_filtersel2) {
465
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
465
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2);
466 466
         } else {
467
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
467
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default');
468 468
         }
469 469
     }
470 470
 
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
      */
593 593
     public function render($fetchOnly = false, $debug = false)
594 594
     {
595
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
595
+        require_once XOOPS_ROOT_PATH.'/class/template.php';
596 596
 
597 597
         $this->_tpl = new \XoopsTpl();
598 598
 
@@ -603,24 +603,24 @@  discard block
 block discarded – undo
603 603
          */
604 604
         $this->_tempObject = $this->_objectHandler->create();
605 605
 
606
-        $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
606
+        $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0);
607 607
 
608 608
         $this->setSortOrder();
609 609
 
610 610
         if (!$this->_isTree) {
611
-            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
611
+            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15');
612 612
         } else {
613 613
             $this->_limitsel = 'all';
614 614
         }
615 615
 
616 616
         $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
617
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
617
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel);
618 618
         $limitsArray = $this->getLimitsArray();
619 619
         $this->_criteria->setLimit($this->_limitsel);
620 620
 
621 621
         $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
622 622
         $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
623
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
623
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel);
624 624
         $filtersArray = $this->getFiltersArray();
625 625
 
626 626
         if ($filtersArray) {
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
                     $filters2Array = $this->getFilters2Array();
647 647
                     $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
648 648
 
649
-                    smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
649
+                    smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2);
650 650
                     if ('default' !== $this->_filtersel2) {
651 651
                         $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2));
652 652
                     }
@@ -655,21 +655,21 @@  discard block
 block discarded – undo
655 655
         }
656 656
         // Check if we have a quicksearch
657 657
 
658
-        if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
658
+        if (isset($_POST['quicksearch_'.$this->_id]) && '' != $_POST['quicksearch_'.$this->_id]) {
659 659
             $quicksearch_criteria = new \CriteriaCompo();
660 660
             if (is_array($this->_quickSearch['fields'])) {
661 661
                 foreach ($this->_quickSearch['fields'] as $v) {
662
-                    $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
662
+                    $quicksearch_criteria->add(new \Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR');
663 663
                 }
664 664
             } else {
665
-                $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
665
+                $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'));
666 666
             }
667 667
             $this->_criteria->add($quicksearch_criteria);
668 668
         }
669 669
 
670 670
         $this->_objects = $this->fetchObjects($debug);
671 671
 
672
-        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
672
+        require_once XOOPS_ROOT_PATH.'/class/pagenav.php';
673 673
         if ($this->_criteria->getLimit() > 0) {
674 674
 
675 675
             /**
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
              */
686 686
             $params_of_the_options_sel = [];
687 687
 
688
-            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
688
+            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName];
689 689
             foreach ($_GET as $k => $v) {
690 690
                 if (!in_array($k, $not_needed_params)) {
691 691
                     $new_get_array[]             = "$k=$v";
@@ -696,12 +696,12 @@  discard block
 block discarded – undo
696 696
             /**
697 697
              * Adding the new params of the pagenav
698 698
              */
699
-            $new_get_array[] = 'sortsel=' . $this->_sortsel;
700
-            $new_get_array[] = 'ordersel=' . $this->_ordersel;
701
-            $new_get_array[] = 'limitsel=' . $this->_limitsel;
699
+            $new_get_array[] = 'sortsel='.$this->_sortsel;
700
+            $new_get_array[] = 'ordersel='.$this->_ordersel;
701
+            $new_get_array[] = 'limitsel='.$this->_limitsel;
702 702
             $otherParams     = implode('&', $new_get_array);
703 703
 
704
-            $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
704
+            $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams);
705 705
             $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
706 706
         }
707 707
         $this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
@@ -737,20 +737,20 @@  discard block
 block discarded – undo
737 737
             $aColumn['align'] = $column->getAlign();
738 738
             $aColumn['key']   = $column->getKeyName();
739 739
             if ('checked' === $column->_keyname) {
740
-                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
740
+                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">';
741 741
             } elseif ($column->getCustomCaption()) {
742 742
                 $aColumn['caption'] = $column->getCustomCaption();
743 743
             } else {
744 744
                 $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
745 745
             }
746 746
             // Are we doing a GET sort on this column ?
747
-            $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
748
-                        && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
747
+            $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel'])
748
+                        && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName())
749 749
                        || ($this->_sortsel == $column->getKeyName());
750
-            $order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
750
+            $order   = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC';
751 751
 
752
-            if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
753
-                $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
752
+            if (isset($_REQUEST['quicksearch_'.$this->_id]) && '' != $_REQUEST['quicksearch_'.$this->_id]) {
753
+                $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id];
754 754
             }
755 755
             if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
756 756
                 $aColumn['caption'] = $aColumn['caption'];
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
                                       . $orderArray[$order]['image']
778 778
                                       . '" alt="ASC"></a>';
779 779
             } else {
780
-                $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
780
+                $aColumn['caption'] = '<a href="'.$current_url.'?'.$this->_objectHandler->_itemname.'_'.'sortsel='.$column->getKeyName().'&'.$this->_objectHandler->_itemname.'_'.'ordersel=ASC'.$qs_param.'&'.$new_query_string.'">'.$aColumn['caption'].'</a>';
781 781
             }
782 782
             $aColumns[] = $aColumn;
783 783
         }
@@ -807,9 +807,9 @@  discard block
 block discarded – undo
807 807
 
808 808
         $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
809 809
         if ($fetchOnly) {
810
-            return $this->_tpl->fetch('db:' . $smartobjectTable_template);
810
+            return $this->_tpl->fetch('db:'.$smartobjectTable_template);
811 811
         } else {
812
-            $this->_tpl->display('db:' . $smartobjectTable_template);
812
+            $this->_tpl->display('db:'.$smartobjectTable_template);
813 813
         }
814 814
     }
815 815
 
Please login to merge, or discard this patch.
class/SmartPersistableObjectHandler.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 
194 194
     /**
195 195
      * @param $criteria
196
-     * @param $perm_name
196
+     * @param boolean $perm_name
197 197
      * @return bool
198 198
      */
199 199
     public function setGrantedObjectsCriteria($criteria, $perm_name)
@@ -387,7 +387,7 @@  discard block
 block discarded – undo
387 387
     }
388 388
 
389 389
     /**
390
-     * @param        $sql
390
+     * @param        string $sql
391 391
      * @param        $criteria
392 392
      * @param  bool  $force
393 393
      * @param  bool  $debug
Please login to merge, or discard this patch.
Indentation   +976 added lines, -976 removed lines patch added patch discarded remove patch
@@ -29,980 +29,980 @@
 block discarded – undo
29 29
 
30 30
 class SmartPersistableObjectHandler extends \XoopsObjectHandler
31 31
 {
32
-    public $_itemname;
33
-
34
-    /**
35
-     * Name of the table use to store this {@link SmartObject}
36
-     *
37
-     * Note that the name of the table needs to be free of the database prefix.
38
-     * For example "smartsection_categories"
39
-     * @var string
40
-     */
41
-    public $table;
42
-
43
-    /**
44
-     * Name of the table key that uniquely identify each {@link SmartObject}
45
-     *
46
-     * For example: "categoryid"
47
-     * @var string
48
-     */
49
-    public $keyName;
50
-
51
-    /**
52
-     * Name of the class derived from {@link SmartObject} and which this handler is handling
53
-     *
54
-     * Note that this string needs to be lowercase
55
-     *
56
-     * For example: "smartsectioncategory"
57
-     * @var string
58
-     */
59
-    public $className;
60
-
61
-    /**
62
-     * Name of the field which properly identify the {@link SmartObject}
63
-     *
64
-     * For example: "name" (this will be the category's name)
65
-     * @var string
66
-     */
67
-    public $identifierName;
68
-
69
-    /**
70
-     * Name of the field which will be use as a summary for the object
71
-     *
72
-     * For example: "summary"
73
-     * @var string
74
-     */
75
-    public $summaryName;
76
-
77
-    /**
78
-     * Page name use to basically manage and display the {@link SmartObject}
79
-     *
80
-     * This page needs to be the same in user side and admin side
81
-     *
82
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
83
-     * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
84
-     * @var string
85
-     */
86
-    public $_page;
87
-
88
-    /**
89
-     * Full path of the module using this {@link SmartObject}
90
-     *
91
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
92
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
93
-     * @var string
94
-     */
95
-    public $_modulePath;
96
-
97
-    public $_moduleUrl;
98
-
99
-    public $_moduleName;
100
-
101
-    public $_uploadUrl;
102
-
103
-    public $_uploadPath;
104
-
105
-    public $_allowedMimeTypes = 0;
106
-
107
-    public $_maxFileSize = 1000000;
108
-
109
-    public $_maxWidth = 500;
110
-
111
-    public $_maxHeight = 500;
112
-
113
-    public $highlightFields = [];
114
-
115
-    /**
116
-     * Array containing the events name and functions
117
-     *
118
-     * @var array
119
-     */
120
-    public $eventArray = [];
121
-
122
-    /**
123
-     * Array containing the permissions that this handler will manage on the objects
124
-     *
125
-     * @var array
126
-     */
127
-    public $permissionsArray = false;
128
-
129
-    public $generalSQL = false;
130
-
131
-    public $_eventHooks     = [];
132
-    public $_disabledEvents = [];
133
-
134
-    /**
135
-     * Constructor - called from child classes
136
-     *
137
-     * @param \XoopsDatabase $db           {@link XoopsDatabase}
138
-     * @param string         $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
139
-     * @param string         $keyname      Name of the table key that uniquely identify each {@link SmartObject}
140
-     * @param string         $idenfierName Name of the field which properly identify the {@link SmartObject}
141
-     * @param string         $summaryName
142
-     * @param string         $modulename
143
-     * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
144
-     * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
145
-     * @internal param string $moduleName name of the module
146
-     */
147
-    public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
148
-    {
149
-        parent::__construct($db);
150
-
151
-        $this->_itemname      = $itemname;
152
-        $this->_moduleName    = $modulename;
153
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
154
-        $this->keyName        = $keyname;
155
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
156
-        $this->identifierName = $idenfierName;
157
-        $this->summaryName    = $summaryName;
158
-        $this->_page          = $itemname . '.php';
159
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
160
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
161
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
162
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
163
-    }
164
-
165
-    /**
166
-     * @param $event
167
-     * @param $method
168
-     */
169
-    public function addEventHook($event, $method)
170
-    {
171
-        $this->_eventHooks[$event] = $method;
172
-    }
173
-
174
-    /**
175
-     * Add a permission that this handler will manage for its objects
176
-     *
177
-     * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
178
-     *
179
-     * @param string      $perm_name   name of the permission
180
-     * @param string      $caption     caption of the control that will be displayed in the form
181
-     * @param bool|string $description description of the control that will be displayed in the form
182
-     */
183
-    public function addPermission($perm_name, $caption, $description = false)
184
-    {
185
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
186
-
187
-        $this->permissionsArray[] = [
188
-            'perm_name'   => $perm_name,
189
-            'caption'     => $caption,
190
-            'description' => $description
191
-        ];
192
-    }
193
-
194
-    /**
195
-     * @param $criteria
196
-     * @param $perm_name
197
-     * @return bool
198
-     */
199
-    public function setGrantedObjectsCriteria($criteria, $perm_name)
200
-    {
201
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
202
-        $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
203
-        if (count($grantedItems) > 0) {
204
-            $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
205
-
206
-            return true;
207
-        } else {
208
-            return false;
209
-        }
210
-    }
211
-
212
-    /**
213
-     * @param bool $_uploadPath
214
-     * @param bool $_allowedMimeTypes
215
-     * @param bool $_maxFileSize
216
-     * @param bool $_maxWidth
217
-     * @param bool $_maxHeight
218
-     */
219
-    public function setUploaderConfig(
220
-        $_uploadPath = false,
221
-        $_allowedMimeTypes = false,
222
-        $_maxFileSize = false,
223
-        $_maxWidth = false,
224
-        $_maxHeight = false
225
-    ) {
226
-        $this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
227
-        $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
228
-        $this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
229
-        $this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
230
-        $this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
231
-    }
232
-
233
-    /**
234
-     * create a new {@link SmartObject}
235
-     *
236
-     * @param bool $isNew Flag the new objects as "new"?
237
-     *
238
-     * @return Smartobject\SmartObject {@link SmartObject}
239
-     */
240
-    public function create($isNew = true)
241
-    {
242
-        $obj = new $this->className($this);
243
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
244
-        if (!$obj->handler) {
245
-            $obj->Handler = $this;
246
-        }
247
-
248
-        if (true === $isNew) {
249
-            $obj->setNew();
250
-        }
251
-
252
-        return $obj;
253
-    }
254
-
255
-    /**
256
-     * @return string
257
-     */
258
-    public function getImageUrl()
259
-    {
260
-        return $this->_uploadUrl . $this->_itemname . '/';
261
-    }
262
-
263
-    /**
264
-     * @return string
265
-     */
266
-    public function getImagePath()
267
-    {
268
-        $dir = $this->_uploadPath . $this->_itemname;
269
-        if (!file_exists($dir)) {
270
-            smart_admin_mkdir($dir);
271
-        }
272
-
273
-        return $dir . '/';
274
-    }
275
-
276
-    /**
277
-     * retrieve a {@link SmartObject}
278
-     *
279
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
280
-     * @param  bool  $as_object whether to return an object or an array
281
-     * @param  bool  $debug
282
-     * @param  bool  $criteria
283
-     * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
284
-     *                          FALSE if failed
285
-     */
286
-    public function get($id, $as_object = true, $debug = false, $criteria = false)
287
-    {
288
-        if (!$criteria) {
289
-            $criteria = new \CriteriaCompo();
290
-        }
291
-        if (is_array($this->keyName)) {
292
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
293
-                /**
294
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
295
-                 * Is the fact that we removed the (int)() represents a security risk ?
296
-                 */
297
-                //$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
298
-                $criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
299
-            }
300
-        } else {
301
-            //$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname);
302
-            /**
303
-             * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
304
-             * Is the fact that we removed the (int)() represents a security risk ?
305
-             */
306
-            $criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname));
307
-        }
308
-        $criteria->setLimit(1);
309
-        if ($debug) {
310
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
311
-        } else {
312
-            $obj_array =& $this->getObjects($criteria, false, $as_object);
313
-            //patch: weird bug of indexing by id even if id_as_key = false;
314
-            if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
315
-                $obj_array[0] = $obj_array[$id];
316
-                unset($obj_array[$id]);
317
-                $obj_array[0]->unsetNew();
318
-            }
319
-        }
320
-
321
-        if (1 != count($obj_array)) {
322
-            $obj = $this->create();
323
-
324
-            return $obj;
325
-        }
326
-
327
-        return $obj_array[0];
328
-    }
329
-
330
-    /**
331
-     * retrieve a {@link SmartObject}
332
-     *
333
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
334
-     * @param  bool  $as_object whether to return an object or an array
335
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
336
-     */
337
-    public function &getD($id, $as_object = true)
338
-    {
339
-        return $this->get($id, $as_object, true);
340
-    }
341
-
342
-    /**
343
-     * retrieve objects from the database
344
-     *
345
-     * @param null|\CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
346
-     * @param bool            $id_as_key use the ID as key for the array?
347
-     * @param bool            $as_object return an array of objects?
348
-     *
349
-     * @param  bool           $sql
350
-     * @param  bool           $debug
351
-     * @return array
352
-     */
353
-    public function getObjects(
354
-        \CriteriaElement $criteria = null,
355
-        $id_as_key = false,
356
-        $as_object = true,
357
-        $sql = false,
358
-        $debug = false
359
-    ) {
360
-        $ret   = [];
361
-        $limit = $start = 0;
362
-
363
-        if ($this->generalSQL) {
364
-            $sql = $this->generalSQL;
365
-        } elseif (!$sql) {
366
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
367
-        }
368
-
369
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
370
-            $sql .= ' ' . $criteria->renderWhere();
371
-            if ('' !== $criteria->getSort()) {
372
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
373
-            }
374
-            $limit = $criteria->getLimit();
375
-            $start = $criteria->getStart();
376
-        }
377
-        if ($debug) {
378
-            xoops_debug($sql);
379
-        }
380
-
381
-        $result = $this->db->query($sql, $limit, $start);
382
-        if (!$result) {
383
-            return $ret;
384
-        }
385
-
386
-        return $this->convertResultSet($result, $id_as_key, $as_object);
387
-    }
388
-
389
-    /**
390
-     * @param        $sql
391
-     * @param        $criteria
392
-     * @param  bool  $force
393
-     * @param  bool  $debug
394
-     * @return array
395
-     */
396
-    public function query($sql, $criteria, $force = false, $debug = false)
397
-    {
398
-        $ret = [];
399
-
400
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
401
-            $sql .= ' ' . $criteria->renderWhere();
402
-            if ($criteria->groupby) {
403
-                $sql .= $criteria->getGroupby();
404
-            }
405
-            if ('' !== $criteria->getSort()) {
406
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
407
-            }
408
-        }
409
-        if ($debug) {
410
-            xoops_debug($sql);
411
-        }
412
-
413
-        if ($force) {
414
-            $result = $this->db->queryF($sql);
415
-        } else {
416
-            $result = $this->db->query($sql);
417
-        }
418
-
419
-        if (!$result) {
420
-            return $ret;
421
-        }
422
-
423
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
424
-            $ret[] = $myrow;
425
-        }
426
-
427
-        return $ret;
428
-    }
429
-
430
-    /**
431
-     * retrieve objects with debug mode - so will show the query
432
-     *
433
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
434
-     * @param bool            $id_as_key use the ID as key for the array?
435
-     * @param bool            $as_object return an array of objects?
436
-     *
437
-     * @param  bool           $sql
438
-     * @return array
439
-     */
440
-    public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
441
-    {
442
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
443
-    }
444
-
445
-    /**
446
-     * @param $arrayObjects
447
-     * @return array|bool
448
-     */
449
-    public function getObjectsAsArray($arrayObjects)
450
-    {
451
-        $ret = [];
452
-        foreach ($arrayObjects as $key => $object) {
453
-            $ret[$key] = $object->toArray();
454
-        }
455
-        if (count($ret > 0)) {
456
-            return $ret;
457
-        } else {
458
-            return false;
459
-        }
460
-    }
461
-
462
-    /**
463
-     * Convert a database resultset to a returnable array
464
-     *
465
-     * @param object $result    database resultset
466
-     * @param bool   $id_as_key - should NOT be used with joint keys
467
-     * @param bool   $as_object
468
-     *
469
-     * @return array
470
-     */
471
-    public function convertResultSet($result, $id_as_key = false, $as_object = true)
472
-    {
473
-        $ret = [];
474
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
475
-            $obj = $this->create(false);
476
-            $obj->assignVars($myrow);
477
-            if (!$id_as_key) {
478
-                if ($as_object) {
479
-                    $ret[] =& $obj;
480
-                } else {
481
-                    $ret[] = $obj->toArray();
482
-                }
483
-            } else {
484
-                if ($as_object) {
485
-                    $value =& $obj;
486
-                } else {
487
-                    $value = $obj->toArray();
488
-                }
489
-                if ('parentid' === $id_as_key) {
490
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
491
-                } else {
492
-                    $ret[$obj->getVar($this->keyName)] = $value;
493
-                }
494
-            }
495
-            unset($obj);
496
-        }
497
-
498
-        return $ret;
499
-    }
500
-
501
-    /**
502
-     * @param  null $criteria
503
-     * @param  int  $limit
504
-     * @param  int  $start
505
-     * @return array
506
-     */
507
-    public function getListD($criteria = null, $limit = 0, $start = 0)
508
-    {
509
-        return $this->getList($criteria, $limit, $start, true);
510
-    }
511
-
512
-    /**
513
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
514
-     *
515
-     * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
516
-     * @param int             $limit    Max number of objects to fetch
517
-     * @param int             $start    Which record to start at
518
-     *
519
-     * @param  bool           $debug
520
-     * @return array
521
-     */
522
-    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
523
-    {
524
-        $ret = [];
525
-        if (null === $criteria) {
526
-            $criteria = new \CriteriaCompo();
527
-        }
528
-
529
-        if ('' === $criteria->getSort()) {
530
-            $criteria->setSort($this->getIdentifierName());
531
-        }
532
-
533
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
534
-        if (!empty($this->identifierName)) {
535
-            $sql .= ', ' . $this->getIdentifierName();
536
-        }
537
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
538
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
539
-            $sql .= ' ' . $criteria->renderWhere();
540
-            if ('' !== $criteria->getSort()) {
541
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
542
-            }
543
-            $limit = $criteria->getLimit();
544
-            $start = $criteria->getStart();
545
-        }
546
-
547
-        if ($debug) {
548
-            xoops_debug($sql);
549
-        }
550
-
551
-        $result = $this->db->query($sql, $limit, $start);
552
-        if (!$result) {
553
-            return $ret;
554
-        }
555
-
556
-        $myts = \MyTextSanitizer::getInstance();
557
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
558
-            //identifiers should be textboxes, so sanitize them like that
559
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
560
-        }
561
-
562
-        return $ret;
563
-    }
564
-
565
-    /**
566
-     * count objects matching a condition
567
-     *
568
-     * @param  CriteriaElement $criteria {@link CriteriaElement} to match
569
-     * @return int             count of objects
570
-     */
571
-    public function getCount(CriteriaElement $criteria = null)
572
-    {
573
-        $field   = '';
574
-        $groupby = false;
575
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
576
-            if ('' !== $criteria->groupby) {
577
-                $groupby = true;
578
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
579
-            }
580
-        }
581
-        /**
582
-         * if we have a generalSQL, lets used this one.
583
-         * This needs to be improved...
584
-         */
585
-        if ($this->generalSQL) {
586
-            $sql = $this->generalSQL;
587
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
588
-        } else {
589
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
590
-        }
591
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
592
-            $sql .= ' ' . $criteria->renderWhere();
593
-            if ('' !== $criteria->groupby) {
594
-                $sql .= $criteria->getGroupby();
595
-            }
596
-        }
597
-
598
-        $result = $this->db->query($sql);
599
-        if (!$result) {
600
-            return 0;
601
-        }
602
-        if (false === $groupby) {
603
-            list($count) = $this->db->fetchRow($result);
604
-
605
-            return $count;
606
-        } else {
607
-            $ret = [];
608
-            while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
609
-                $ret[$id] = $count;
610
-            }
611
-
612
-            return $ret;
613
-        }
614
-    }
615
-
616
-    /**
617
-     * delete an object from the database
618
-     *
619
-     * @param \XoopsObject $obj reference to the object to delete
620
-     * @param  bool        $force
621
-     * @return bool        FALSE if failed.
622
-     */
623
-    public function delete(\XoopsObject $obj, $force = false)
624
-    {
625
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
626
-        if (!$eventResult) {
627
-            $obj->setErrors('An error occured during the BeforeDelete event');
628
-
629
-            return false;
630
-        }
631
-
632
-        if (is_array($this->keyName)) {
633
-            $clause = [];
634
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
635
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
636
-            }
637
-            $whereclause = implode(' AND ', $clause);
638
-        } else {
639
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
640
-        }
641
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
642
-        if (false !== $force) {
643
-            $result = $this->db->queryF($sql);
644
-        } else {
645
-            $result = $this->db->query($sql);
646
-        }
647
-        if (!$result) {
648
-            return false;
649
-        }
650
-
651
-        $eventResult = $this->executeEvent('afterDelete', $obj);
652
-        if (!$eventResult) {
653
-            $obj->setErrors('An error occured during the AfterDelete event');
654
-
655
-            return false;
656
-        }
657
-
658
-        return true;
659
-    }
660
-
661
-    /**
662
-     * @param $event
663
-     */
664
-    public function disableEvent($event)
665
-    {
666
-        if (is_array($event)) {
667
-            foreach ($event as $v) {
668
-                $this->_disabledEvents[] = $v;
669
-            }
670
-        } else {
671
-            $this->_disabledEvents[] = $event;
672
-        }
673
-    }
674
-
675
-    /**
676
-     * @return array
677
-     */
678
-    public function getPermissions()
679
-    {
680
-        return $this->permissionsArray;
681
-    }
682
-
683
-    /**
684
-     * insert a new object in the database
685
-     *
686
-     * @param \XoopsObject $obj         reference to the object
687
-     * @param  bool        $force       whether to force the query execution despite security settings
688
-     * @param  bool        $checkObject check if the object is dirty and clean the attributes
689
-     * @param  bool        $debug
690
-     * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
691
-     */
692
-    public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
693
-    {
694
-        if (false !== $checkObject) {
695
-            if (!is_object($obj)) {
696
-                return false;
697
-            }
698
-            /**
699
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
700
-             */
701
-            if (!is_a($obj, $this->className)) {
702
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
703
-
704
-                return false;
705
-            }
706
-            if (!$obj->isDirty()) {
707
-                $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
708
-
709
-                return true;
710
-            }
711
-        }
712
-
713
-        if ($obj->seoEnabled) {
714
-            // Auto create meta tags if empty
715
-            $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
716
-
717
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
718
-                if (!$obj->meta_keywords()) {
719
-                    $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
720
-                }
721
-
722
-                if (!$obj->meta_description()) {
723
-                    $obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
724
-                }
725
-            }
726
-
727
-            // Auto create short_url if empty
728
-            if (!$obj->short_url()) {
729
-                $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
730
-            }
731
-        }
732
-
733
-        $eventResult = $this->executeEvent('beforeSave', $obj);
734
-        if (!$eventResult) {
735
-            $obj->setErrors('An error occured during the BeforeSave event');
736
-
737
-            return false;
738
-        }
739
-
740
-        if ($obj->isNew()) {
741
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
742
-            if (!$eventResult) {
743
-                $obj->setErrors('An error occured during the BeforeInsert event');
744
-
745
-                return false;
746
-            }
747
-        } else {
748
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
749
-            if (!$eventResult) {
750
-                $obj->setErrors('An error occured during the BeforeUpdate event');
751
-
752
-                return false;
753
-            }
754
-        }
755
-        if (!$obj->cleanVars()) {
756
-            $obj->setErrors('Variables were not cleaned properly.');
757
-
758
-            return false;
759
-        }
760
-        $fieldsToStoreInDB = [];
761
-        foreach ($obj->cleanVars as $k => $v) {
762
-            if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
763
-                $cleanvars[$k] = (int)$v;
764
-            } elseif (is_array($v)) {
765
-                $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
766
-            } else {
767
-                $cleanvars[$k] = $this->db->quoteString($v);
768
-            }
769
-            if ($obj->vars[$k]['persistent']) {
770
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
771
-            }
772
-        }
773
-        if ($obj->isNew()) {
774
-            if (!is_array($this->keyName)) {
775
-                if ($cleanvars[$this->keyName] < 1) {
776
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
777
-                }
778
-            }
779
-
780
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
781
-        } else {
782
-            $sql = 'UPDATE ' . $this->table . ' SET';
783
-            foreach ($fieldsToStoreInDB as $key => $value) {
784
-                if ((!is_array($this->keyName) && $key == $this->keyName)
785
-                    || (is_array($this->keyName)
786
-                        && in_array($key, $this->keyName))) {
787
-                    continue;
788
-                }
789
-                if (isset($notfirst)) {
790
-                    $sql .= ',';
791
-                }
792
-                $sql      .= ' ' . $key . ' = ' . $value;
793
-                $notfirst = true;
794
-            }
795
-            if (is_array($this->keyName)) {
796
-                $whereclause = '';
797
-                for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
798
-                    if ($i > 0) {
799
-                        $whereclause .= ' AND ';
800
-                    }
801
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
802
-                }
803
-            } else {
804
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
805
-            }
806
-            $sql .= ' WHERE ' . $whereclause;
807
-        }
808
-
809
-        if ($debug) {
810
-            xoops_debug($sql);
811
-        }
812
-
813
-        if (false != $force) {
814
-            $result = $this->db->queryF($sql);
815
-        } else {
816
-            $result = $this->db->query($sql);
817
-        }
818
-
819
-        if (!$result) {
820
-            $obj->setErrors($this->db->error());
821
-
822
-            return false;
823
-        }
824
-
825
-        if ($obj->isNew() && !is_array($this->keyName)) {
826
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
827
-        }
828
-        $eventResult = $this->executeEvent('afterSave', $obj);
829
-        if (!$eventResult) {
830
-            $obj->setErrors('An error occured during the AfterSave event');
831
-
832
-            return false;
833
-        }
834
-
835
-        if ($obj->isNew()) {
836
-            $obj->unsetNew();
837
-            $eventResult = $this->executeEvent('afterInsert', $obj);
838
-            if (!$eventResult) {
839
-                $obj->setErrors('An error occured during the AfterInsert event');
840
-
841
-                return false;
842
-            }
843
-        } else {
844
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
845
-            if (!$eventResult) {
846
-                $obj->setErrors('An error occured during the AfterUpdate event');
847
-
848
-                return false;
849
-            }
850
-        }
851
-
852
-        return true;
853
-    }
854
-
855
-    /**
856
-     * @param       $obj
857
-     * @param  bool $force
858
-     * @param  bool $checkObject
859
-     * @param  bool $debug
860
-     * @return bool
861
-     */
862
-    public function insertD($obj, $force = false, $checkObject = true, $debug = false)
863
-    {
864
-        return $this->insert($obj, $force, $checkObject, true);
865
-    }
866
-
867
-    /**
868
-     * Change a value for objects with a certain criteria
869
-     *
870
-     * @param string          $fieldname  Name of the field
871
-     * @param string          $fieldvalue Value to write
872
-     * @param CriteriaElement $criteria   {@link CriteriaElement}
873
-     *
874
-     * @param  bool           $force
875
-     * @return bool
876
-     */
877
-    public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
878
-    {
879
-        $set_clause = $fieldname . ' = ';
880
-        if (is_numeric($fieldvalue)) {
881
-            $set_clause .= $fieldvalue;
882
-        } elseif (is_array($fieldvalue)) {
883
-            $set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
884
-        } else {
885
-            $set_clause .= $this->db->quoteString($fieldvalue);
886
-        }
887
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
888
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
889
-            $sql .= ' ' . $criteria->renderWhere();
890
-        }
891
-        if (false != $force) {
892
-            $result = $this->db->queryF($sql);
893
-        } else {
894
-            $result = $this->db->query($sql);
895
-        }
896
-        if (!$result) {
897
-            return false;
898
-        }
899
-
900
-        return true;
901
-    }
902
-
903
-    /**
904
-     * delete all objects meeting the conditions
905
-     *
906
-     * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
907
-     * @return bool
908
-     */
909
-
910
-    public function deleteAll(CriteriaElement $criteria = null)
911
-    {
912
-        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
913
-            $sql = 'DELETE FROM ' . $this->table;
914
-            $sql .= ' ' . $criteria->renderWhere();
915
-            if (!$this->db->query($sql)) {
916
-                return false;
917
-            }
918
-            $rows = $this->db->getAffectedRows();
919
-
920
-            return $rows > 0 ? $rows : true;
921
-        }
922
-
923
-        return false;
924
-    }
925
-
926
-    /**
927
-     * @return mixed
928
-     */
929
-    public function getModuleInfo()
930
-    {
931
-        return smart_getModuleInfo($this->_moduleName);
932
-    }
933
-
934
-    /**
935
-     * @return bool
936
-     */
937
-    public function getModuleConfig()
938
-    {
939
-        return smart_getModuleConfig($this->_moduleName);
940
-    }
941
-
942
-    /**
943
-     * @return string
944
-     */
945
-    public function getModuleItemString()
946
-    {
947
-        $ret = $this->_moduleName . '_' . $this->_itemname;
948
-
949
-        return $ret;
950
-    }
951
-
952
-    /**
953
-     * @param $object
954
-     */
955
-    public function updateCounter($object)
956
-    {
957
-        if (isset($object->vars['counter'])) {
958
-            $new_counter = $object->getVar('counter') + 1;
959
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
960
-            $this->query($sql, null, true);
961
-        }
962
-    }
963
-
964
-    /**
965
-     * Execute the function associated with an event
966
-     * This method will check if the function is available
967
-     *
968
-     * @param  string $event name of the event
969
-     * @param         $executeEventObj
970
-     * @return mixed  result of the execution of the function or FALSE if the function was not executed
971
-     * @internal param object $obj $object on which is performed the event
972
-     */
973
-    public function executeEvent($event, &$executeEventObj)
974
-    {
975
-        if (!in_array($event, $this->_disabledEvents)) {
976
-            if (method_exists($this, $event)) {
977
-                $ret = $this->$event($executeEventObj);
978
-            } else {
979
-                // check to see if there is a hook for this event
980
-                if (isset($this->_eventHooks[$event])) {
981
-                    $method = $this->_eventHooks[$event];
982
-                    // check to see if the method specified by this hook exists
983
-                    if (method_exists($this, $method)) {
984
-                        $ret = $this->$method($executeEventObj);
985
-                    }
986
-                }
987
-                $ret = true;
988
-            }
989
-
990
-            return $ret;
991
-        }
992
-
993
-        return true;
994
-    }
995
-
996
-    /**
997
-     * @param  bool $withprefix
998
-     * @return string
999
-     */
1000
-    public function getIdentifierName($withprefix = true)
1001
-    {
1002
-        if ($withprefix) {
1003
-            return $this->_itemname . '.' . $this->identifierName;
1004
-        } else {
1005
-            return $this->identifierName;
1006
-        }
1007
-    }
32
+	public $_itemname;
33
+
34
+	/**
35
+	 * Name of the table use to store this {@link SmartObject}
36
+	 *
37
+	 * Note that the name of the table needs to be free of the database prefix.
38
+	 * For example "smartsection_categories"
39
+	 * @var string
40
+	 */
41
+	public $table;
42
+
43
+	/**
44
+	 * Name of the table key that uniquely identify each {@link SmartObject}
45
+	 *
46
+	 * For example: "categoryid"
47
+	 * @var string
48
+	 */
49
+	public $keyName;
50
+
51
+	/**
52
+	 * Name of the class derived from {@link SmartObject} and which this handler is handling
53
+	 *
54
+	 * Note that this string needs to be lowercase
55
+	 *
56
+	 * For example: "smartsectioncategory"
57
+	 * @var string
58
+	 */
59
+	public $className;
60
+
61
+	/**
62
+	 * Name of the field which properly identify the {@link SmartObject}
63
+	 *
64
+	 * For example: "name" (this will be the category's name)
65
+	 * @var string
66
+	 */
67
+	public $identifierName;
68
+
69
+	/**
70
+	 * Name of the field which will be use as a summary for the object
71
+	 *
72
+	 * For example: "summary"
73
+	 * @var string
74
+	 */
75
+	public $summaryName;
76
+
77
+	/**
78
+	 * Page name use to basically manage and display the {@link SmartObject}
79
+	 *
80
+	 * This page needs to be the same in user side and admin side
81
+	 *
82
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
83
+	 * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
84
+	 * @var string
85
+	 */
86
+	public $_page;
87
+
88
+	/**
89
+	 * Full path of the module using this {@link SmartObject}
90
+	 *
91
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
92
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
93
+	 * @var string
94
+	 */
95
+	public $_modulePath;
96
+
97
+	public $_moduleUrl;
98
+
99
+	public $_moduleName;
100
+
101
+	public $_uploadUrl;
102
+
103
+	public $_uploadPath;
104
+
105
+	public $_allowedMimeTypes = 0;
106
+
107
+	public $_maxFileSize = 1000000;
108
+
109
+	public $_maxWidth = 500;
110
+
111
+	public $_maxHeight = 500;
112
+
113
+	public $highlightFields = [];
114
+
115
+	/**
116
+	 * Array containing the events name and functions
117
+	 *
118
+	 * @var array
119
+	 */
120
+	public $eventArray = [];
121
+
122
+	/**
123
+	 * Array containing the permissions that this handler will manage on the objects
124
+	 *
125
+	 * @var array
126
+	 */
127
+	public $permissionsArray = false;
128
+
129
+	public $generalSQL = false;
130
+
131
+	public $_eventHooks     = [];
132
+	public $_disabledEvents = [];
133
+
134
+	/**
135
+	 * Constructor - called from child classes
136
+	 *
137
+	 * @param \XoopsDatabase $db           {@link XoopsDatabase}
138
+	 * @param string         $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
139
+	 * @param string         $keyname      Name of the table key that uniquely identify each {@link SmartObject}
140
+	 * @param string         $idenfierName Name of the field which properly identify the {@link SmartObject}
141
+	 * @param string         $summaryName
142
+	 * @param string         $modulename
143
+	 * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
144
+	 * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
145
+	 * @internal param string $moduleName name of the module
146
+	 */
147
+	public function __construct(\XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
148
+	{
149
+		parent::__construct($db);
150
+
151
+		$this->_itemname      = $itemname;
152
+		$this->_moduleName    = $modulename;
153
+		$this->table          = $db->prefix($modulename . '_' . $itemname);
154
+		$this->keyName        = $keyname;
155
+		$this->className      = ucfirst($modulename) . ucfirst($itemname);
156
+		$this->identifierName = $idenfierName;
157
+		$this->summaryName    = $summaryName;
158
+		$this->_page          = $itemname . '.php';
159
+		$this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
160
+		$this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
161
+		$this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
162
+		$this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
163
+	}
164
+
165
+	/**
166
+	 * @param $event
167
+	 * @param $method
168
+	 */
169
+	public function addEventHook($event, $method)
170
+	{
171
+		$this->_eventHooks[$event] = $method;
172
+	}
173
+
174
+	/**
175
+	 * Add a permission that this handler will manage for its objects
176
+	 *
177
+	 * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
178
+	 *
179
+	 * @param string      $perm_name   name of the permission
180
+	 * @param string      $caption     caption of the control that will be displayed in the form
181
+	 * @param bool|string $description description of the control that will be displayed in the form
182
+	 */
183
+	public function addPermission($perm_name, $caption, $description = false)
184
+	{
185
+		require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
186
+
187
+		$this->permissionsArray[] = [
188
+			'perm_name'   => $perm_name,
189
+			'caption'     => $caption,
190
+			'description' => $description
191
+		];
192
+	}
193
+
194
+	/**
195
+	 * @param $criteria
196
+	 * @param $perm_name
197
+	 * @return bool
198
+	 */
199
+	public function setGrantedObjectsCriteria($criteria, $perm_name)
200
+	{
201
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this);
202
+		$grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
203
+		if (count($grantedItems) > 0) {
204
+			$criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
205
+
206
+			return true;
207
+		} else {
208
+			return false;
209
+		}
210
+	}
211
+
212
+	/**
213
+	 * @param bool $_uploadPath
214
+	 * @param bool $_allowedMimeTypes
215
+	 * @param bool $_maxFileSize
216
+	 * @param bool $_maxWidth
217
+	 * @param bool $_maxHeight
218
+	 */
219
+	public function setUploaderConfig(
220
+		$_uploadPath = false,
221
+		$_allowedMimeTypes = false,
222
+		$_maxFileSize = false,
223
+		$_maxWidth = false,
224
+		$_maxHeight = false
225
+	) {
226
+		$this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
227
+		$this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
228
+		$this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
229
+		$this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
230
+		$this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
231
+	}
232
+
233
+	/**
234
+	 * create a new {@link SmartObject}
235
+	 *
236
+	 * @param bool $isNew Flag the new objects as "new"?
237
+	 *
238
+	 * @return Smartobject\SmartObject {@link SmartObject}
239
+	 */
240
+	public function create($isNew = true)
241
+	{
242
+		$obj = new $this->className($this);
243
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
244
+		if (!$obj->handler) {
245
+			$obj->Handler = $this;
246
+		}
247
+
248
+		if (true === $isNew) {
249
+			$obj->setNew();
250
+		}
251
+
252
+		return $obj;
253
+	}
254
+
255
+	/**
256
+	 * @return string
257
+	 */
258
+	public function getImageUrl()
259
+	{
260
+		return $this->_uploadUrl . $this->_itemname . '/';
261
+	}
262
+
263
+	/**
264
+	 * @return string
265
+	 */
266
+	public function getImagePath()
267
+	{
268
+		$dir = $this->_uploadPath . $this->_itemname;
269
+		if (!file_exists($dir)) {
270
+			smart_admin_mkdir($dir);
271
+		}
272
+
273
+		return $dir . '/';
274
+	}
275
+
276
+	/**
277
+	 * retrieve a {@link SmartObject}
278
+	 *
279
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
280
+	 * @param  bool  $as_object whether to return an object or an array
281
+	 * @param  bool  $debug
282
+	 * @param  bool  $criteria
283
+	 * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
284
+	 *                          FALSE if failed
285
+	 */
286
+	public function get($id, $as_object = true, $debug = false, $criteria = false)
287
+	{
288
+		if (!$criteria) {
289
+			$criteria = new \CriteriaCompo();
290
+		}
291
+		if (is_array($this->keyName)) {
292
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
293
+				/**
294
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
295
+				 * Is the fact that we removed the (int)() represents a security risk ?
296
+				 */
297
+				//$criteria->add(new \Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
298
+				$criteria->add(new \Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
299
+			}
300
+		} else {
301
+			//$criteria = new \Criteria($this->keyName, (int)($id), '=', $this->_itemname);
302
+			/**
303
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
304
+			 * Is the fact that we removed the (int)() represents a security risk ?
305
+			 */
306
+			$criteria->add(new \Criteria($this->keyName, $id, '=', $this->_itemname));
307
+		}
308
+		$criteria->setLimit(1);
309
+		if ($debug) {
310
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
311
+		} else {
312
+			$obj_array =& $this->getObjects($criteria, false, $as_object);
313
+			//patch: weird bug of indexing by id even if id_as_key = false;
314
+			if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
315
+				$obj_array[0] = $obj_array[$id];
316
+				unset($obj_array[$id]);
317
+				$obj_array[0]->unsetNew();
318
+			}
319
+		}
320
+
321
+		if (1 != count($obj_array)) {
322
+			$obj = $this->create();
323
+
324
+			return $obj;
325
+		}
326
+
327
+		return $obj_array[0];
328
+	}
329
+
330
+	/**
331
+	 * retrieve a {@link SmartObject}
332
+	 *
333
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
334
+	 * @param  bool  $as_object whether to return an object or an array
335
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
336
+	 */
337
+	public function &getD($id, $as_object = true)
338
+	{
339
+		return $this->get($id, $as_object, true);
340
+	}
341
+
342
+	/**
343
+	 * retrieve objects from the database
344
+	 *
345
+	 * @param null|\CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
346
+	 * @param bool            $id_as_key use the ID as key for the array?
347
+	 * @param bool            $as_object return an array of objects?
348
+	 *
349
+	 * @param  bool           $sql
350
+	 * @param  bool           $debug
351
+	 * @return array
352
+	 */
353
+	public function getObjects(
354
+		\CriteriaElement $criteria = null,
355
+		$id_as_key = false,
356
+		$as_object = true,
357
+		$sql = false,
358
+		$debug = false
359
+	) {
360
+		$ret   = [];
361
+		$limit = $start = 0;
362
+
363
+		if ($this->generalSQL) {
364
+			$sql = $this->generalSQL;
365
+		} elseif (!$sql) {
366
+			$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
367
+		}
368
+
369
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
370
+			$sql .= ' ' . $criteria->renderWhere();
371
+			if ('' !== $criteria->getSort()) {
372
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
373
+			}
374
+			$limit = $criteria->getLimit();
375
+			$start = $criteria->getStart();
376
+		}
377
+		if ($debug) {
378
+			xoops_debug($sql);
379
+		}
380
+
381
+		$result = $this->db->query($sql, $limit, $start);
382
+		if (!$result) {
383
+			return $ret;
384
+		}
385
+
386
+		return $this->convertResultSet($result, $id_as_key, $as_object);
387
+	}
388
+
389
+	/**
390
+	 * @param        $sql
391
+	 * @param        $criteria
392
+	 * @param  bool  $force
393
+	 * @param  bool  $debug
394
+	 * @return array
395
+	 */
396
+	public function query($sql, $criteria, $force = false, $debug = false)
397
+	{
398
+		$ret = [];
399
+
400
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
401
+			$sql .= ' ' . $criteria->renderWhere();
402
+			if ($criteria->groupby) {
403
+				$sql .= $criteria->getGroupby();
404
+			}
405
+			if ('' !== $criteria->getSort()) {
406
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
407
+			}
408
+		}
409
+		if ($debug) {
410
+			xoops_debug($sql);
411
+		}
412
+
413
+		if ($force) {
414
+			$result = $this->db->queryF($sql);
415
+		} else {
416
+			$result = $this->db->query($sql);
417
+		}
418
+
419
+		if (!$result) {
420
+			return $ret;
421
+		}
422
+
423
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
424
+			$ret[] = $myrow;
425
+		}
426
+
427
+		return $ret;
428
+	}
429
+
430
+	/**
431
+	 * retrieve objects with debug mode - so will show the query
432
+	 *
433
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
434
+	 * @param bool            $id_as_key use the ID as key for the array?
435
+	 * @param bool            $as_object return an array of objects?
436
+	 *
437
+	 * @param  bool           $sql
438
+	 * @return array
439
+	 */
440
+	public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
441
+	{
442
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
443
+	}
444
+
445
+	/**
446
+	 * @param $arrayObjects
447
+	 * @return array|bool
448
+	 */
449
+	public function getObjectsAsArray($arrayObjects)
450
+	{
451
+		$ret = [];
452
+		foreach ($arrayObjects as $key => $object) {
453
+			$ret[$key] = $object->toArray();
454
+		}
455
+		if (count($ret > 0)) {
456
+			return $ret;
457
+		} else {
458
+			return false;
459
+		}
460
+	}
461
+
462
+	/**
463
+	 * Convert a database resultset to a returnable array
464
+	 *
465
+	 * @param object $result    database resultset
466
+	 * @param bool   $id_as_key - should NOT be used with joint keys
467
+	 * @param bool   $as_object
468
+	 *
469
+	 * @return array
470
+	 */
471
+	public function convertResultSet($result, $id_as_key = false, $as_object = true)
472
+	{
473
+		$ret = [];
474
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
475
+			$obj = $this->create(false);
476
+			$obj->assignVars($myrow);
477
+			if (!$id_as_key) {
478
+				if ($as_object) {
479
+					$ret[] =& $obj;
480
+				} else {
481
+					$ret[] = $obj->toArray();
482
+				}
483
+			} else {
484
+				if ($as_object) {
485
+					$value =& $obj;
486
+				} else {
487
+					$value = $obj->toArray();
488
+				}
489
+				if ('parentid' === $id_as_key) {
490
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
491
+				} else {
492
+					$ret[$obj->getVar($this->keyName)] = $value;
493
+				}
494
+			}
495
+			unset($obj);
496
+		}
497
+
498
+		return $ret;
499
+	}
500
+
501
+	/**
502
+	 * @param  null $criteria
503
+	 * @param  int  $limit
504
+	 * @param  int  $start
505
+	 * @return array
506
+	 */
507
+	public function getListD($criteria = null, $limit = 0, $start = 0)
508
+	{
509
+		return $this->getList($criteria, $limit, $start, true);
510
+	}
511
+
512
+	/**
513
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
514
+	 *
515
+	 * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
516
+	 * @param int             $limit    Max number of objects to fetch
517
+	 * @param int             $start    Which record to start at
518
+	 *
519
+	 * @param  bool           $debug
520
+	 * @return array
521
+	 */
522
+	public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
523
+	{
524
+		$ret = [];
525
+		if (null === $criteria) {
526
+			$criteria = new \CriteriaCompo();
527
+		}
528
+
529
+		if ('' === $criteria->getSort()) {
530
+			$criteria->setSort($this->getIdentifierName());
531
+		}
532
+
533
+		$sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
534
+		if (!empty($this->identifierName)) {
535
+			$sql .= ', ' . $this->getIdentifierName();
536
+		}
537
+		$sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
538
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
539
+			$sql .= ' ' . $criteria->renderWhere();
540
+			if ('' !== $criteria->getSort()) {
541
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
542
+			}
543
+			$limit = $criteria->getLimit();
544
+			$start = $criteria->getStart();
545
+		}
546
+
547
+		if ($debug) {
548
+			xoops_debug($sql);
549
+		}
550
+
551
+		$result = $this->db->query($sql, $limit, $start);
552
+		if (!$result) {
553
+			return $ret;
554
+		}
555
+
556
+		$myts = \MyTextSanitizer::getInstance();
557
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
558
+			//identifiers should be textboxes, so sanitize them like that
559
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
560
+		}
561
+
562
+		return $ret;
563
+	}
564
+
565
+	/**
566
+	 * count objects matching a condition
567
+	 *
568
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} to match
569
+	 * @return int             count of objects
570
+	 */
571
+	public function getCount(CriteriaElement $criteria = null)
572
+	{
573
+		$field   = '';
574
+		$groupby = false;
575
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
576
+			if ('' !== $criteria->groupby) {
577
+				$groupby = true;
578
+				$field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
579
+			}
580
+		}
581
+		/**
582
+		 * if we have a generalSQL, lets used this one.
583
+		 * This needs to be improved...
584
+		 */
585
+		if ($this->generalSQL) {
586
+			$sql = $this->generalSQL;
587
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
588
+		} else {
589
+			$sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
590
+		}
591
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
592
+			$sql .= ' ' . $criteria->renderWhere();
593
+			if ('' !== $criteria->groupby) {
594
+				$sql .= $criteria->getGroupby();
595
+			}
596
+		}
597
+
598
+		$result = $this->db->query($sql);
599
+		if (!$result) {
600
+			return 0;
601
+		}
602
+		if (false === $groupby) {
603
+			list($count) = $this->db->fetchRow($result);
604
+
605
+			return $count;
606
+		} else {
607
+			$ret = [];
608
+			while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
609
+				$ret[$id] = $count;
610
+			}
611
+
612
+			return $ret;
613
+		}
614
+	}
615
+
616
+	/**
617
+	 * delete an object from the database
618
+	 *
619
+	 * @param \XoopsObject $obj reference to the object to delete
620
+	 * @param  bool        $force
621
+	 * @return bool        FALSE if failed.
622
+	 */
623
+	public function delete(\XoopsObject $obj, $force = false)
624
+	{
625
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
626
+		if (!$eventResult) {
627
+			$obj->setErrors('An error occured during the BeforeDelete event');
628
+
629
+			return false;
630
+		}
631
+
632
+		if (is_array($this->keyName)) {
633
+			$clause = [];
634
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
635
+				$clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
636
+			}
637
+			$whereclause = implode(' AND ', $clause);
638
+		} else {
639
+			$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
640
+		}
641
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
642
+		if (false !== $force) {
643
+			$result = $this->db->queryF($sql);
644
+		} else {
645
+			$result = $this->db->query($sql);
646
+		}
647
+		if (!$result) {
648
+			return false;
649
+		}
650
+
651
+		$eventResult = $this->executeEvent('afterDelete', $obj);
652
+		if (!$eventResult) {
653
+			$obj->setErrors('An error occured during the AfterDelete event');
654
+
655
+			return false;
656
+		}
657
+
658
+		return true;
659
+	}
660
+
661
+	/**
662
+	 * @param $event
663
+	 */
664
+	public function disableEvent($event)
665
+	{
666
+		if (is_array($event)) {
667
+			foreach ($event as $v) {
668
+				$this->_disabledEvents[] = $v;
669
+			}
670
+		} else {
671
+			$this->_disabledEvents[] = $event;
672
+		}
673
+	}
674
+
675
+	/**
676
+	 * @return array
677
+	 */
678
+	public function getPermissions()
679
+	{
680
+		return $this->permissionsArray;
681
+	}
682
+
683
+	/**
684
+	 * insert a new object in the database
685
+	 *
686
+	 * @param \XoopsObject $obj         reference to the object
687
+	 * @param  bool        $force       whether to force the query execution despite security settings
688
+	 * @param  bool        $checkObject check if the object is dirty and clean the attributes
689
+	 * @param  bool        $debug
690
+	 * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
691
+	 */
692
+	public function insert(\XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
693
+	{
694
+		if (false !== $checkObject) {
695
+			if (!is_object($obj)) {
696
+				return false;
697
+			}
698
+			/**
699
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
700
+			 */
701
+			if (!is_a($obj, $this->className)) {
702
+				$obj->setError(get_class($obj) . ' Differs from ' . $this->className);
703
+
704
+				return false;
705
+			}
706
+			if (!$obj->isDirty()) {
707
+				$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
708
+
709
+				return true;
710
+			}
711
+		}
712
+
713
+		if ($obj->seoEnabled) {
714
+			// Auto create meta tags if empty
715
+			$smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
716
+
717
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
718
+				if (!$obj->meta_keywords()) {
719
+					$obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
720
+				}
721
+
722
+				if (!$obj->meta_description()) {
723
+					$obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
724
+				}
725
+			}
726
+
727
+			// Auto create short_url if empty
728
+			if (!$obj->short_url()) {
729
+				$obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
730
+			}
731
+		}
732
+
733
+		$eventResult = $this->executeEvent('beforeSave', $obj);
734
+		if (!$eventResult) {
735
+			$obj->setErrors('An error occured during the BeforeSave event');
736
+
737
+			return false;
738
+		}
739
+
740
+		if ($obj->isNew()) {
741
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
742
+			if (!$eventResult) {
743
+				$obj->setErrors('An error occured during the BeforeInsert event');
744
+
745
+				return false;
746
+			}
747
+		} else {
748
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
749
+			if (!$eventResult) {
750
+				$obj->setErrors('An error occured during the BeforeUpdate event');
751
+
752
+				return false;
753
+			}
754
+		}
755
+		if (!$obj->cleanVars()) {
756
+			$obj->setErrors('Variables were not cleaned properly.');
757
+
758
+			return false;
759
+		}
760
+		$fieldsToStoreInDB = [];
761
+		foreach ($obj->cleanVars as $k => $v) {
762
+			if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
763
+				$cleanvars[$k] = (int)$v;
764
+			} elseif (is_array($v)) {
765
+				$cleanvars[$k] = $this->db->quoteString(implode(',', $v));
766
+			} else {
767
+				$cleanvars[$k] = $this->db->quoteString($v);
768
+			}
769
+			if ($obj->vars[$k]['persistent']) {
770
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
771
+			}
772
+		}
773
+		if ($obj->isNew()) {
774
+			if (!is_array($this->keyName)) {
775
+				if ($cleanvars[$this->keyName] < 1) {
776
+					$cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
777
+				}
778
+			}
779
+
780
+			$sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
781
+		} else {
782
+			$sql = 'UPDATE ' . $this->table . ' SET';
783
+			foreach ($fieldsToStoreInDB as $key => $value) {
784
+				if ((!is_array($this->keyName) && $key == $this->keyName)
785
+					|| (is_array($this->keyName)
786
+						&& in_array($key, $this->keyName))) {
787
+					continue;
788
+				}
789
+				if (isset($notfirst)) {
790
+					$sql .= ',';
791
+				}
792
+				$sql      .= ' ' . $key . ' = ' . $value;
793
+				$notfirst = true;
794
+			}
795
+			if (is_array($this->keyName)) {
796
+				$whereclause = '';
797
+				for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
798
+					if ($i > 0) {
799
+						$whereclause .= ' AND ';
800
+					}
801
+					$whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
802
+				}
803
+			} else {
804
+				$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
805
+			}
806
+			$sql .= ' WHERE ' . $whereclause;
807
+		}
808
+
809
+		if ($debug) {
810
+			xoops_debug($sql);
811
+		}
812
+
813
+		if (false != $force) {
814
+			$result = $this->db->queryF($sql);
815
+		} else {
816
+			$result = $this->db->query($sql);
817
+		}
818
+
819
+		if (!$result) {
820
+			$obj->setErrors($this->db->error());
821
+
822
+			return false;
823
+		}
824
+
825
+		if ($obj->isNew() && !is_array($this->keyName)) {
826
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
827
+		}
828
+		$eventResult = $this->executeEvent('afterSave', $obj);
829
+		if (!$eventResult) {
830
+			$obj->setErrors('An error occured during the AfterSave event');
831
+
832
+			return false;
833
+		}
834
+
835
+		if ($obj->isNew()) {
836
+			$obj->unsetNew();
837
+			$eventResult = $this->executeEvent('afterInsert', $obj);
838
+			if (!$eventResult) {
839
+				$obj->setErrors('An error occured during the AfterInsert event');
840
+
841
+				return false;
842
+			}
843
+		} else {
844
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
845
+			if (!$eventResult) {
846
+				$obj->setErrors('An error occured during the AfterUpdate event');
847
+
848
+				return false;
849
+			}
850
+		}
851
+
852
+		return true;
853
+	}
854
+
855
+	/**
856
+	 * @param       $obj
857
+	 * @param  bool $force
858
+	 * @param  bool $checkObject
859
+	 * @param  bool $debug
860
+	 * @return bool
861
+	 */
862
+	public function insertD($obj, $force = false, $checkObject = true, $debug = false)
863
+	{
864
+		return $this->insert($obj, $force, $checkObject, true);
865
+	}
866
+
867
+	/**
868
+	 * Change a value for objects with a certain criteria
869
+	 *
870
+	 * @param string          $fieldname  Name of the field
871
+	 * @param string          $fieldvalue Value to write
872
+	 * @param CriteriaElement $criteria   {@link CriteriaElement}
873
+	 *
874
+	 * @param  bool           $force
875
+	 * @return bool
876
+	 */
877
+	public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
878
+	{
879
+		$set_clause = $fieldname . ' = ';
880
+		if (is_numeric($fieldvalue)) {
881
+			$set_clause .= $fieldvalue;
882
+		} elseif (is_array($fieldvalue)) {
883
+			$set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
884
+		} else {
885
+			$set_clause .= $this->db->quoteString($fieldvalue);
886
+		}
887
+		$sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
888
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
889
+			$sql .= ' ' . $criteria->renderWhere();
890
+		}
891
+		if (false != $force) {
892
+			$result = $this->db->queryF($sql);
893
+		} else {
894
+			$result = $this->db->query($sql);
895
+		}
896
+		if (!$result) {
897
+			return false;
898
+		}
899
+
900
+		return true;
901
+	}
902
+
903
+	/**
904
+	 * delete all objects meeting the conditions
905
+	 *
906
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
907
+	 * @return bool
908
+	 */
909
+
910
+	public function deleteAll(CriteriaElement $criteria = null)
911
+	{
912
+		if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
913
+			$sql = 'DELETE FROM ' . $this->table;
914
+			$sql .= ' ' . $criteria->renderWhere();
915
+			if (!$this->db->query($sql)) {
916
+				return false;
917
+			}
918
+			$rows = $this->db->getAffectedRows();
919
+
920
+			return $rows > 0 ? $rows : true;
921
+		}
922
+
923
+		return false;
924
+	}
925
+
926
+	/**
927
+	 * @return mixed
928
+	 */
929
+	public function getModuleInfo()
930
+	{
931
+		return smart_getModuleInfo($this->_moduleName);
932
+	}
933
+
934
+	/**
935
+	 * @return bool
936
+	 */
937
+	public function getModuleConfig()
938
+	{
939
+		return smart_getModuleConfig($this->_moduleName);
940
+	}
941
+
942
+	/**
943
+	 * @return string
944
+	 */
945
+	public function getModuleItemString()
946
+	{
947
+		$ret = $this->_moduleName . '_' . $this->_itemname;
948
+
949
+		return $ret;
950
+	}
951
+
952
+	/**
953
+	 * @param $object
954
+	 */
955
+	public function updateCounter($object)
956
+	{
957
+		if (isset($object->vars['counter'])) {
958
+			$new_counter = $object->getVar('counter') + 1;
959
+			$sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
960
+			$this->query($sql, null, true);
961
+		}
962
+	}
963
+
964
+	/**
965
+	 * Execute the function associated with an event
966
+	 * This method will check if the function is available
967
+	 *
968
+	 * @param  string $event name of the event
969
+	 * @param         $executeEventObj
970
+	 * @return mixed  result of the execution of the function or FALSE if the function was not executed
971
+	 * @internal param object $obj $object on which is performed the event
972
+	 */
973
+	public function executeEvent($event, &$executeEventObj)
974
+	{
975
+		if (!in_array($event, $this->_disabledEvents)) {
976
+			if (method_exists($this, $event)) {
977
+				$ret = $this->$event($executeEventObj);
978
+			} else {
979
+				// check to see if there is a hook for this event
980
+				if (isset($this->_eventHooks[$event])) {
981
+					$method = $this->_eventHooks[$event];
982
+					// check to see if the method specified by this hook exists
983
+					if (method_exists($this, $method)) {
984
+						$ret = $this->$method($executeEventObj);
985
+					}
986
+				}
987
+				$ret = true;
988
+			}
989
+
990
+			return $ret;
991
+		}
992
+
993
+		return true;
994
+	}
995
+
996
+	/**
997
+	 * @param  bool $withprefix
998
+	 * @return string
999
+	 */
1000
+	public function getIdentifierName($withprefix = true)
1001
+	{
1002
+		if ($withprefix) {
1003
+			return $this->_itemname . '.' . $this->identifierName;
1004
+		} else {
1005
+			return $this->identifierName;
1006
+		}
1007
+	}
1008 1008
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -150,16 +150,16 @@  discard block
 block discarded – undo
150 150
 
151 151
         $this->_itemname      = $itemname;
152 152
         $this->_moduleName    = $modulename;
153
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
153
+        $this->table          = $db->prefix($modulename.'_'.$itemname);
154 154
         $this->keyName        = $keyname;
155
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
155
+        $this->className      = ucfirst($modulename).ucfirst($itemname);
156 156
         $this->identifierName = $idenfierName;
157 157
         $this->summaryName    = $summaryName;
158
-        $this->_page          = $itemname . '.php';
159
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
160
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
161
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
162
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
158
+        $this->_page          = $itemname.'.php';
159
+        $this->_modulePath    = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/';
160
+        $this->_moduleUrl     = XOOPS_URL.'/modules/'.$this->_moduleName.'/';
161
+        $this->_uploadPath    = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/';
162
+        $this->_uploadUrl     = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/';
163 163
     }
164 164
 
165 165
     /**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function addPermission($perm_name, $caption, $description = false)
184 184
     {
185
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
185
+        require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php';
186 186
 
187 187
         $this->permissionsArray[] = [
188 188
             'perm_name'   => $perm_name,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
202 202
         $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
203 203
         if (count($grantedItems) > 0) {
204
-            $criteria->add(new \Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
204
+            $criteria->add(new \Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN'));
205 205
 
206 206
             return true;
207 207
         } else {
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function getImageUrl()
259 259
     {
260
-        return $this->_uploadUrl . $this->_itemname . '/';
260
+        return $this->_uploadUrl.$this->_itemname.'/';
261 261
     }
262 262
 
263 263
     /**
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
      */
266 266
     public function getImagePath()
267 267
     {
268
-        $dir = $this->_uploadPath . $this->_itemname;
268
+        $dir = $this->_uploadPath.$this->_itemname;
269 269
         if (!file_exists($dir)) {
270 270
             smart_admin_mkdir($dir);
271 271
         }
272 272
 
273
-        return $dir . '/';
273
+        return $dir.'/';
274 274
     }
275 275
 
276 276
     /**
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         if ($debug) {
310 310
             $obj_array = $this->getObjectsD($criteria, false, $as_object);
311 311
         } else {
312
-            $obj_array =& $this->getObjects($criteria, false, $as_object);
312
+            $obj_array = & $this->getObjects($criteria, false, $as_object);
313 313
             //patch: weird bug of indexing by id even if id_as_key = false;
314 314
             if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
315 315
                 $obj_array[0] = $obj_array[$id];
@@ -363,13 +363,13 @@  discard block
 block discarded – undo
363 363
         if ($this->generalSQL) {
364 364
             $sql = $this->generalSQL;
365 365
         } elseif (!$sql) {
366
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
366
+            $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname;
367 367
         }
368 368
 
369 369
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
370
-            $sql .= ' ' . $criteria->renderWhere();
370
+            $sql .= ' '.$criteria->renderWhere();
371 371
             if ('' !== $criteria->getSort()) {
372
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
372
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
373 373
             }
374 374
             $limit = $criteria->getLimit();
375 375
             $start = $criteria->getStart();
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
         $ret = [];
399 399
 
400 400
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
401
-            $sql .= ' ' . $criteria->renderWhere();
401
+            $sql .= ' '.$criteria->renderWhere();
402 402
             if ($criteria->groupby) {
403 403
                 $sql .= $criteria->getGroupby();
404 404
             }
405 405
             if ('' !== $criteria->getSort()) {
406
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
406
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
407 407
             }
408 408
         }
409 409
         if ($debug) {
@@ -476,18 +476,18 @@  discard block
 block discarded – undo
476 476
             $obj->assignVars($myrow);
477 477
             if (!$id_as_key) {
478 478
                 if ($as_object) {
479
-                    $ret[] =& $obj;
479
+                    $ret[] = & $obj;
480 480
                 } else {
481 481
                     $ret[] = $obj->toArray();
482 482
                 }
483 483
             } else {
484 484
                 if ($as_object) {
485
-                    $value =& $obj;
485
+                    $value = & $obj;
486 486
                 } else {
487 487
                     $value = $obj->toArray();
488 488
                 }
489 489
                 if ('parentid' === $id_as_key) {
490
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
490
+                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value;
491 491
                 } else {
492 492
                     $ret[$obj->getVar($this->keyName)] = $value;
493 493
                 }
@@ -530,15 +530,15 @@  discard block
 block discarded – undo
530 530
             $criteria->setSort($this->getIdentifierName());
531 531
         }
532 532
 
533
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
533
+        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
534 534
         if (!empty($this->identifierName)) {
535
-            $sql .= ', ' . $this->getIdentifierName();
535
+            $sql .= ', '.$this->getIdentifierName();
536 536
         }
537
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
537
+        $sql .= ' FROM '.$this->table.' AS '.$this->_itemname;
538 538
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
539
-            $sql .= ' ' . $criteria->renderWhere();
539
+            $sql .= ' '.$criteria->renderWhere();
540 540
             if ('' !== $criteria->getSort()) {
541
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
541
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
542 542
             }
543 543
             $limit = $criteria->getLimit();
544 544
             $start = $criteria->getStart();
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
576 576
             if ('' !== $criteria->groupby) {
577 577
                 $groupby = true;
578
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
578
+                $field   = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
579 579
             }
580 580
         }
581 581
         /**
@@ -586,10 +586,10 @@  discard block
 block discarded – undo
586 586
             $sql = $this->generalSQL;
587 587
             $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
588 588
         } else {
589
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
589
+            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname;
590 590
         }
591 591
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
592
-            $sql .= ' ' . $criteria->renderWhere();
592
+            $sql .= ' '.$criteria->renderWhere();
593 593
             if ('' !== $criteria->groupby) {
594 594
                 $sql .= $criteria->getGroupby();
595 595
             }
@@ -632,13 +632,13 @@  discard block
 block discarded – undo
632 632
         if (is_array($this->keyName)) {
633 633
             $clause = [];
634 634
             for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
635
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
635
+                $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
636 636
             }
637 637
             $whereclause = implode(' AND ', $clause);
638 638
         } else {
639
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
639
+            $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
640 640
         }
641
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
641
+        $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause;
642 642
         if (false !== $force) {
643 643
             $result = $this->db->queryF($sql);
644 644
         } else {
@@ -699,7 +699,7 @@  discard block
 block discarded – undo
699 699
              * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
700 700
              */
701 701
             if (!is_a($obj, $this->className)) {
702
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
702
+                $obj->setError(get_class($obj).' Differs from '.$this->className);
703 703
 
704 704
                 return false;
705 705
             }
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
         $fieldsToStoreInDB = [];
761 761
         foreach ($obj->cleanVars as $k => $v) {
762 762
             if (XOBJ_DTYPE_INT == $obj->vars[$k]['data_type']) {
763
-                $cleanvars[$k] = (int)$v;
763
+                $cleanvars[$k] = (int) $v;
764 764
             } elseif (is_array($v)) {
765 765
                 $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
766 766
             } else {
@@ -773,13 +773,13 @@  discard block
 block discarded – undo
773 773
         if ($obj->isNew()) {
774 774
             if (!is_array($this->keyName)) {
775 775
                 if ($cleanvars[$this->keyName] < 1) {
776
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
776
+                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
777 777
                 }
778 778
             }
779 779
 
780
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
780
+            $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')';
781 781
         } else {
782
-            $sql = 'UPDATE ' . $this->table . ' SET';
782
+            $sql = 'UPDATE '.$this->table.' SET';
783 783
             foreach ($fieldsToStoreInDB as $key => $value) {
784 784
                 if ((!is_array($this->keyName) && $key == $this->keyName)
785 785
                     || (is_array($this->keyName)
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
                 if (isset($notfirst)) {
790 790
                     $sql .= ',';
791 791
                 }
792
-                $sql      .= ' ' . $key . ' = ' . $value;
792
+                $sql .= ' '.$key.' = '.$value;
793 793
                 $notfirst = true;
794 794
             }
795 795
             if (is_array($this->keyName)) {
@@ -798,12 +798,12 @@  discard block
 block discarded – undo
798 798
                     if ($i > 0) {
799 799
                         $whereclause .= ' AND ';
800 800
                     }
801
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
801
+                    $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
802 802
                 }
803 803
             } else {
804
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
804
+                $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
805 805
             }
806
-            $sql .= ' WHERE ' . $whereclause;
806
+            $sql .= ' WHERE '.$whereclause;
807 807
         }
808 808
 
809 809
         if ($debug) {
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
      */
877 877
     public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
878 878
     {
879
-        $set_clause = $fieldname . ' = ';
879
+        $set_clause = $fieldname.' = ';
880 880
         if (is_numeric($fieldvalue)) {
881 881
             $set_clause .= $fieldvalue;
882 882
         } elseif (is_array($fieldvalue)) {
@@ -884,9 +884,9 @@  discard block
 block discarded – undo
884 884
         } else {
885 885
             $set_clause .= $this->db->quoteString($fieldvalue);
886 886
         }
887
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
887
+        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
888 888
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
889
-            $sql .= ' ' . $criteria->renderWhere();
889
+            $sql .= ' '.$criteria->renderWhere();
890 890
         }
891 891
         if (false != $force) {
892 892
             $result = $this->db->queryF($sql);
@@ -910,8 +910,8 @@  discard block
 block discarded – undo
910 910
     public function deleteAll(CriteriaElement $criteria = null)
911 911
     {
912 912
         if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
913
-            $sql = 'DELETE FROM ' . $this->table;
914
-            $sql .= ' ' . $criteria->renderWhere();
913
+            $sql = 'DELETE FROM '.$this->table;
914
+            $sql .= ' '.$criteria->renderWhere();
915 915
             if (!$this->db->query($sql)) {
916 916
                 return false;
917 917
             }
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
      */
945 945
     public function getModuleItemString()
946 946
     {
947
-        $ret = $this->_moduleName . '_' . $this->_itemname;
947
+        $ret = $this->_moduleName.'_'.$this->_itemname;
948 948
 
949 949
         return $ret;
950 950
     }
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
     {
957 957
         if (isset($object->vars['counter'])) {
958 958
             $new_counter = $object->getVar('counter') + 1;
959
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
959
+            $sql         = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id();
960 960
             $this->query($sql, null, true);
961 961
         }
962 962
     }
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
     public function getIdentifierName($withprefix = true)
1001 1001
     {
1002 1002
         if ($withprefix) {
1003
-            return $this->_itemname . '.' . $this->identifierName;
1003
+            return $this->_itemname.'.'.$this->identifierName;
1004 1004
         } else {
1005 1005
             return $this->identifierName;
1006 1006
         }
Please login to merge, or discard this patch.