@@ -11,25 +11,25 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormUploadElement extends XoopsFormFile |
13 | 13 | { |
14 | - /** |
|
15 | - * @param $object |
|
16 | - * @param $key |
|
17 | - */ |
|
18 | - public function SmartFormFileElement($object, $key) |
|
19 | - { |
|
20 | - parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | - $this->setExtra(' size=50'); |
|
22 | - } |
|
14 | + /** |
|
15 | + * @param $object |
|
16 | + * @param $key |
|
17 | + */ |
|
18 | + public function SmartFormFileElement($object, $key) |
|
19 | + { |
|
20 | + parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | + $this->setExtra(' size=50'); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * prepare HTML for output |
|
26 | - * |
|
27 | - * @return string HTML |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
24 | + /** |
|
25 | + * prepare HTML for output |
|
26 | + * |
|
27 | + * @return string HTML |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
32 | 32 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
33 | 33 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
34 | - } |
|
34 | + } |
|
35 | 35 | } |
@@ -5,38 +5,38 @@ |
||
5 | 5 | */ |
6 | 6 | class SmartFormFileElement extends XoopsFormFile |
7 | 7 | { |
8 | - public $object; |
|
9 | - public $key; |
|
8 | + public $object; |
|
9 | + public $key; |
|
10 | 10 | |
11 | - /** |
|
12 | - * SmartFormFileElement constructor. |
|
13 | - * @param string $object |
|
14 | - * @param string $key |
|
15 | - */ |
|
16 | - public function __construct($object, $key) |
|
17 | - { |
|
18 | - $this->object = $object; |
|
19 | - $this->key = $key; |
|
20 | - parent::__construct($object->vars[$key]['form_caption'], $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | - $this->setExtra(' size=50'); |
|
22 | - } |
|
11 | + /** |
|
12 | + * SmartFormFileElement constructor. |
|
13 | + * @param string $object |
|
14 | + * @param string $key |
|
15 | + */ |
|
16 | + public function __construct($object, $key) |
|
17 | + { |
|
18 | + $this->object = $object; |
|
19 | + $this->key = $key; |
|
20 | + parent::__construct($object->vars[$key]['form_caption'], $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
21 | + $this->setExtra(' size=50'); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * prepare HTML for output |
|
26 | - * |
|
27 | - * @return string HTML |
|
28 | - */ |
|
29 | - public function render() |
|
30 | - { |
|
31 | - $ret = ''; |
|
32 | - if ($this->object->getVar($this->key) !== '') { |
|
33 | - $ret .= '<div>' . _CO_SOBJECT_CURRENT_FILE . $this->object->getVar($this->key) . '</div>'; |
|
34 | - } |
|
24 | + /** |
|
25 | + * prepare HTML for output |
|
26 | + * |
|
27 | + * @return string HTML |
|
28 | + */ |
|
29 | + public function render() |
|
30 | + { |
|
31 | + $ret = ''; |
|
32 | + if ($this->object->getVar($this->key) !== '') { |
|
33 | + $ret .= '<div>' . _CO_SOBJECT_CURRENT_FILE . $this->object->getVar($this->key) . '</div>'; |
|
34 | + } |
|
35 | 35 | |
36 | - $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
36 | + $ret .= "<div><input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
37 | 37 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
38 | 38 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'></div>"; |
39 | 39 | |
40 | - return $ret; |
|
41 | - } |
|
40 | + return $ret; |
|
41 | + } |
|
42 | 42 | } |
@@ -11,59 +11,59 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormSelectElement extends XoopsFormSelect |
13 | 13 | { |
14 | - public $multiple = false; |
|
14 | + public $multiple = false; |
|
15 | 15 | |
16 | - /** |
|
17 | - * SmartFormSelectElement constructor. |
|
18 | - * @param string $object |
|
19 | - * @param string $key |
|
20 | - */ |
|
21 | - public function __construct($object, $key) |
|
22 | - { |
|
23 | - $var = $object->vars[$key]; |
|
24 | - $size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
|
16 | + /** |
|
17 | + * SmartFormSelectElement constructor. |
|
18 | + * @param string $object |
|
19 | + * @param string $key |
|
20 | + */ |
|
21 | + public function __construct($object, $key) |
|
22 | + { |
|
23 | + $var = $object->vars[$key]; |
|
24 | + $size = isset($var['size']) ? $var['size'] : ($this->multiple ? 5 : 1); |
|
25 | 25 | |
26 | - // Adding the options inside this SelectBox |
|
27 | - // If the custom method is not from a module, than it's from the core |
|
28 | - $control = $object->getControl($key); |
|
26 | + // Adding the options inside this SelectBox |
|
27 | + // If the custom method is not from a module, than it's from the core |
|
28 | + $control = $object->getControl($key); |
|
29 | 29 | |
30 | - $value = isset($control['value']) ? $control['value'] : $object->getVar($key, 'e'); |
|
30 | + $value = isset($control['value']) ? $control['value'] : $object->getVar($key, 'e'); |
|
31 | 31 | |
32 | - parent::__construct($var['form_caption'], $key, $value, $size, $this->multiple); |
|
32 | + parent::__construct($var['form_caption'], $key, $value, $size, $this->multiple); |
|
33 | 33 | |
34 | - if (isset($control['options'])) { |
|
35 | - $this->addOptionArray($control['options']); |
|
36 | - } else { |
|
37 | - // let's find if the method we need to call comes from an already defined object |
|
38 | - if (isset($control['object'])) { |
|
39 | - if (method_exists($control['object'], $control['method'])) { |
|
40 | - if ($option_array = $control['object']->{$control['method']}()) { |
|
41 | - // Adding the options array to the XoopsFormSelect |
|
42 | - $this->addOptionArray($option_array); |
|
43 | - } |
|
44 | - } |
|
45 | - } else { |
|
46 | - // finding the itemHandler; if none, let's take the itemHandler of the $object |
|
47 | - if (isset($control['itemHandler'])) { |
|
48 | - if (!$control['module']) { |
|
49 | - // Creating the specified core object handler |
|
50 | - $controlHandler = xoops_getHandler($control['itemHandler']); |
|
51 | - } else { |
|
52 | - $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
|
53 | - } |
|
54 | - } else { |
|
55 | - $controlHandler = $object->handler; |
|
56 | - } |
|
34 | + if (isset($control['options'])) { |
|
35 | + $this->addOptionArray($control['options']); |
|
36 | + } else { |
|
37 | + // let's find if the method we need to call comes from an already defined object |
|
38 | + if (isset($control['object'])) { |
|
39 | + if (method_exists($control['object'], $control['method'])) { |
|
40 | + if ($option_array = $control['object']->{$control['method']}()) { |
|
41 | + // Adding the options array to the XoopsFormSelect |
|
42 | + $this->addOptionArray($option_array); |
|
43 | + } |
|
44 | + } |
|
45 | + } else { |
|
46 | + // finding the itemHandler; if none, let's take the itemHandler of the $object |
|
47 | + if (isset($control['itemHandler'])) { |
|
48 | + if (!$control['module']) { |
|
49 | + // Creating the specified core object handler |
|
50 | + $controlHandler = xoops_getHandler($control['itemHandler']); |
|
51 | + } else { |
|
52 | + $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
|
53 | + } |
|
54 | + } else { |
|
55 | + $controlHandler = $object->handler; |
|
56 | + } |
|
57 | 57 | |
58 | - // Checking if the specified method exists |
|
59 | - if (method_exists($controlHandler, $control['method'])) { |
|
60 | - // TODO: How could I pass the parameters in the following call ... |
|
61 | - if ($option_array = $controlHandler->{$control['method']}()) { |
|
62 | - // Adding the options array to the XoopsFormSelect |
|
63 | - $this->addOptionArray($option_array); |
|
64 | - } |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
68 | - } |
|
58 | + // Checking if the specified method exists |
|
59 | + if (method_exists($controlHandler, $control['method'])) { |
|
60 | + // TODO: How could I pass the parameters in the following call ... |
|
61 | + if ($option_array = $controlHandler->{$control['method']}()) { |
|
62 | + // Adding the options array to the XoopsFormSelect |
|
63 | + $this->addOptionArray($option_array); |
|
64 | + } |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -11,39 +11,39 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormImageElement extends XoopsFormElementTray |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormImageElement constructor. |
|
16 | - * @param string $object |
|
17 | - * @param string $key |
|
18 | - */ |
|
19 | - public function __construct($object, $key) |
|
20 | - { |
|
21 | - $var = $object->vars[$key]; |
|
22 | - $object_imageurl = $object->getImageDir(); |
|
23 | - parent::__construct($var['form_caption'], ' '); |
|
14 | + /** |
|
15 | + * SmartFormImageElement constructor. |
|
16 | + * @param string $object |
|
17 | + * @param string $key |
|
18 | + */ |
|
19 | + public function __construct($object, $key) |
|
20 | + { |
|
21 | + $var = $object->vars[$key]; |
|
22 | + $object_imageurl = $object->getImageDir(); |
|
23 | + parent::__construct($var['form_caption'], ' '); |
|
24 | 24 | |
25 | - $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']); |
|
25 | + $objectArray['image'] = str_replace('{XOOPS_URL}', XOOPS_URL, $objectArray['image']); |
|
26 | 26 | |
27 | - if ($object->getVar($key) !== '' |
|
28 | - && (0 === strpos($object->getVar($key), 'http') |
|
29 | - || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) { |
|
30 | - $this->addElement(new XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>")); |
|
31 | - } elseif ($object->getVar($key) !== '') { |
|
32 | - $this->addElement(new XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>")); |
|
33 | - } |
|
27 | + if ($object->getVar($key) !== '' |
|
28 | + && (0 === strpos($object->getVar($key), 'http') |
|
29 | + || 0 === strpos($object->getVar($key), '{XOOPS_URL}'))) { |
|
30 | + $this->addElement(new XoopsFormLabel('', "<img src='" . str_replace('{XOOPS_URL}', XOOPS_URL, $object->getVar($key)) . "' alt=''><br><br>")); |
|
31 | + } elseif ($object->getVar($key) !== '') { |
|
32 | + $this->addElement(new XoopsFormLabel('', "<img src='" . $object_imageurl . $object->getVar($key) . "' alt=''><br><br>")); |
|
33 | + } |
|
34 | 34 | |
35 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
36 | - $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
35 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformfileuploadelement.php'; |
|
36 | + $this->addElement(new SmartFormFileUploadElement($object, $key)); |
|
37 | 37 | |
38 | - $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', '')); |
|
39 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php'; |
|
40 | - require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
38 | + $this->addElement(new XoopsFormLabel('<div style="height: 10px; padding-top: 8px; font-size: 80%;">' . _CO_SOBJECT_URL_FILE_DSC . '</div>', '')); |
|
39 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformtextelement.php'; |
|
40 | + require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
|
41 | 41 | |
42 | - $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
43 | - $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
44 | - $this->addElement(new XoopsFormLabel('', '<br><br>')); |
|
45 | - $delete_check = new SmartFormCheckElement('', 'delete_' . $key); |
|
46 | - $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>'); |
|
47 | - $this->addElement($delete_check); |
|
48 | - } |
|
42 | + $this->addElement(new XoopsFormLabel('', '<br>' . _CO_SOBJECT_URL_FILE)); |
|
43 | + $this->addElement(new SmartFormTextElement($object, 'url_' . $key)); |
|
44 | + $this->addElement(new XoopsFormLabel('', '<br><br>')); |
|
45 | + $delete_check = new SmartFormCheckElement('', 'delete_' . $key); |
|
46 | + $delete_check->addOption(1, '<span style="color:red;">' . _CO_SOBJECT_DELETE . '</span>'); |
|
47 | + $this->addElement($delete_check); |
|
48 | + } |
|
49 | 49 | } |
@@ -7,41 +7,41 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class SmartFormCheckElement extends XoopsFormCheckBox |
9 | 9 | { |
10 | - /** |
|
11 | - * |
|
12 | - * /** |
|
13 | - * prepare HTML for output |
|
14 | - * |
|
15 | - * @return string |
|
16 | - */ |
|
17 | - public function render() |
|
18 | - { |
|
19 | - $ret = ''; |
|
20 | - if (count($this->getOptions()) > 1 && substr($this->getName(), -2, 2) !== '[]') { |
|
21 | - $newname = $this->getName() . '[]'; |
|
22 | - $this->setName($newname); |
|
23 | - } |
|
24 | - foreach ($this->getOptions() as $value => $name) { |
|
25 | - $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
26 | - if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
27 | - $ret .= ' checked'; |
|
28 | - } |
|
29 | - $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
30 | - } |
|
10 | + /** |
|
11 | + * |
|
12 | + * /** |
|
13 | + * prepare HTML for output |
|
14 | + * |
|
15 | + * @return string |
|
16 | + */ |
|
17 | + public function render() |
|
18 | + { |
|
19 | + $ret = ''; |
|
20 | + if (count($this->getOptions()) > 1 && substr($this->getName(), -2, 2) !== '[]') { |
|
21 | + $newname = $this->getName() . '[]'; |
|
22 | + $this->setName($newname); |
|
23 | + } |
|
24 | + foreach ($this->getOptions() as $value => $name) { |
|
25 | + $ret .= "<input type='checkbox' name='" . $this->getName() . "' value='" . $value . "'"; |
|
26 | + if (count($this->getValue()) > 0 && in_array($value, $this->getValue())) { |
|
27 | + $ret .= ' checked'; |
|
28 | + } |
|
29 | + $ret .= $this->getExtra() . '>' . $name . '<br>'; |
|
30 | + } |
|
31 | 31 | |
32 | - return $ret; |
|
33 | - } |
|
32 | + return $ret; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function renderValidationJS() |
|
39 | - { |
|
40 | - $js .= 'var hasSelections = false;'; |
|
41 | - //sometimes, there is an implicit '[]', sometimes not |
|
42 | - $eltname = $this->getName(); |
|
43 | - if (strpos($eltname, '[') === false) { |
|
44 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
35 | + /** |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function renderValidationJS() |
|
39 | + { |
|
40 | + $js .= 'var hasSelections = false;'; |
|
41 | + //sometimes, there is an implicit '[]', sometimes not |
|
42 | + $eltname = $this->getName(); |
|
43 | + if (strpos($eltname, '[') === false) { |
|
44 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
45 | 45 | if (myform['{$eltname}[]'][i].checked) { |
46 | 46 | hasSelections = true; |
47 | 47 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | } |
50 | 50 | if (hasSelections === false) { |
51 | 51 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
52 | - } else { |
|
53 | - $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
52 | + } else { |
|
53 | + $js .= "for (var i = 0; i < myform['" . $eltname . "'].length; i++) { |
|
54 | 54 | if (myform['{$eltname}'][i].checked) { |
55 | 55 | hasSelections = true; |
56 | 56 | } |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | } |
59 | 59 | if (hasSelections === false) { |
60 | 60 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - return $js; |
|
64 | - } |
|
63 | + return $js; |
|
64 | + } |
|
65 | 65 | } |
@@ -11,59 +11,59 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormParentCategoryElement extends XoopsFormSelect |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormParentcategoryElement constructor. |
|
16 | - * @param string $object |
|
17 | - * @param string $key |
|
18 | - */ |
|
19 | - public function __construct($object, $key) |
|
20 | - { |
|
21 | - $addNoParent = isset($object->controls[$key]['addNoParent']) ? $object->controls[$key]['addNoParent'] : true; |
|
22 | - $criteria = new CriteriaCompo(); |
|
23 | - $criteria->setSort('weight, name'); |
|
24 | - $categoryHandler = xoops_getModuleHandler('category', $object->handler->_moduleName); |
|
25 | - $categories = $categoryHandler->getObjects($criteria); |
|
14 | + /** |
|
15 | + * SmartFormParentcategoryElement constructor. |
|
16 | + * @param string $object |
|
17 | + * @param string $key |
|
18 | + */ |
|
19 | + public function __construct($object, $key) |
|
20 | + { |
|
21 | + $addNoParent = isset($object->controls[$key]['addNoParent']) ? $object->controls[$key]['addNoParent'] : true; |
|
22 | + $criteria = new CriteriaCompo(); |
|
23 | + $criteria->setSort('weight, name'); |
|
24 | + $categoryHandler = xoops_getModuleHandler('category', $object->handler->_moduleName); |
|
25 | + $categories = $categoryHandler->getObjects($criteria); |
|
26 | 26 | |
27 | - require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
|
28 | - $mytree = new XoopsObjectTree($categories, 'categoryid', 'parentid'); |
|
29 | - parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e')); |
|
27 | + require_once XOOPS_ROOT_PATH . '/class/tree.php'; |
|
28 | + $mytree = new XoopsObjectTree($categories, 'categoryid', 'parentid'); |
|
29 | + parent::__construct($object->vars[$key]['form_caption'], $key, $object->getVar($key, 'e')); |
|
30 | 30 | |
31 | - $ret = array(); |
|
32 | - $options = $this->getOptionArray($mytree, 'name', 0, '', $ret); |
|
33 | - if ($addNoParent) { |
|
34 | - $newOptions = array('0' => '----'); |
|
35 | - foreach ($options as $k => $v) { |
|
36 | - $newOptions[$k] = $v; |
|
37 | - } |
|
38 | - $options = $newOptions; |
|
39 | - } |
|
40 | - $this->addOptionArray($options); |
|
41 | - } |
|
31 | + $ret = array(); |
|
32 | + $options = $this->getOptionArray($mytree, 'name', 0, '', $ret); |
|
33 | + if ($addNoParent) { |
|
34 | + $newOptions = array('0' => '----'); |
|
35 | + foreach ($options as $k => $v) { |
|
36 | + $newOptions[$k] = $v; |
|
37 | + } |
|
38 | + $options = $newOptions; |
|
39 | + } |
|
40 | + $this->addOptionArray($options); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get options for a category select with hierarchy (recursive) |
|
45 | - * |
|
46 | - * @param XoopsObjectTree $tree |
|
47 | - * @param string $fieldName |
|
48 | - * @param int $key |
|
49 | - * @param string $prefix_curr |
|
50 | - * @param array $ret |
|
51 | - * |
|
52 | - * @return array |
|
53 | - */ |
|
54 | - public function getOptionArray($tree, $fieldName, $key, $prefix_curr = '', &$ret) |
|
55 | - { |
|
56 | - if ($key > 0) { |
|
57 | - $value = $tree->tree[$key]['obj']->getVar($tree->_myId); |
|
58 | - $ret[$key] = $prefix_curr . $tree->tree[$key]['obj']->getVar($fieldName); |
|
59 | - $prefix_curr .= '-'; |
|
60 | - } |
|
61 | - if (isset($tree->tree[$key]['child']) && !empty($tree->tree[$key]['child'])) { |
|
62 | - foreach ($tree->tree[$key]['child'] as $childkey) { |
|
63 | - $this->getOptionArray($tree, $fieldName, $childkey, $prefix_curr, $ret); |
|
64 | - } |
|
65 | - } |
|
43 | + /** |
|
44 | + * Get options for a category select with hierarchy (recursive) |
|
45 | + * |
|
46 | + * @param XoopsObjectTree $tree |
|
47 | + * @param string $fieldName |
|
48 | + * @param int $key |
|
49 | + * @param string $prefix_curr |
|
50 | + * @param array $ret |
|
51 | + * |
|
52 | + * @return array |
|
53 | + */ |
|
54 | + public function getOptionArray($tree, $fieldName, $key, $prefix_curr = '', &$ret) |
|
55 | + { |
|
56 | + if ($key > 0) { |
|
57 | + $value = $tree->tree[$key]['obj']->getVar($tree->_myId); |
|
58 | + $ret[$key] = $prefix_curr . $tree->tree[$key]['obj']->getVar($fieldName); |
|
59 | + $prefix_curr .= '-'; |
|
60 | + } |
|
61 | + if (isset($tree->tree[$key]['child']) && !empty($tree->tree[$key]['child'])) { |
|
62 | + foreach ($tree->tree[$key]['child'] as $childkey) { |
|
63 | + $this->getOptionArray($tree, $fieldName, $childkey, $prefix_curr, $ret); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - return $ret; |
|
68 | - } |
|
67 | + return $ret; |
|
68 | + } |
|
69 | 69 | } |
@@ -24,20 +24,20 @@ |
||
24 | 24 | */ |
25 | 25 | class SmartFormHidden extends XoopsFormHidden |
26 | 26 | { |
27 | - /** |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - public function render() |
|
31 | - { |
|
32 | - if (is_array($this->getValue())) { |
|
33 | - $ret = ''; |
|
34 | - foreach ($this->getValue() as $value) { |
|
35 | - $ret .= "<input type='hidden' name='" . $this->getName() . "[]' id='" . $this->getName() . "' value='" . $value . "'>\n"; |
|
36 | - } |
|
37 | - } else { |
|
38 | - $ret = "<input type='hidden' name='" . $this->getName() . "' id='" . $this->getName() . "' value='" . $this->getValue() . "'>"; |
|
39 | - } |
|
27 | + /** |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + public function render() |
|
31 | + { |
|
32 | + if (is_array($this->getValue())) { |
|
33 | + $ret = ''; |
|
34 | + foreach ($this->getValue() as $value) { |
|
35 | + $ret .= "<input type='hidden' name='" . $this->getName() . "[]' id='" . $this->getName() . "' value='" . $value . "'>\n"; |
|
36 | + } |
|
37 | + } else { |
|
38 | + $ret = "<input type='hidden' name='" . $this->getName() . "' id='" . $this->getName() . "' value='" . $this->getValue() . "'>"; |
|
39 | + } |
|
40 | 40 | |
41 | - return $ret; |
|
42 | - } |
|
41 | + return $ret; |
|
42 | + } |
|
43 | 43 | } |
@@ -11,54 +11,54 @@ |
||
11 | 11 | */ |
12 | 12 | class SmartFormRadioElement extends XoopsFormRadio |
13 | 13 | { |
14 | - /** |
|
15 | - * SmartFormRadioElement constructor. |
|
16 | - * @param string $object |
|
17 | - * @param string $key |
|
18 | - */ |
|
19 | - public function __construct($object, $key) |
|
20 | - { |
|
21 | - $var = $object->vars[$key]; |
|
14 | + /** |
|
15 | + * SmartFormRadioElement constructor. |
|
16 | + * @param string $object |
|
17 | + * @param string $key |
|
18 | + */ |
|
19 | + public function __construct($object, $key) |
|
20 | + { |
|
21 | + $var = $object->vars[$key]; |
|
22 | 22 | |
23 | - parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
23 | + parent::__construct($var['form_caption'], $key, $object->getVar($key, 'e')); |
|
24 | 24 | |
25 | - // Adding the options inside this SelectBox |
|
26 | - // If the custom method is not from a module, than it's from the core |
|
27 | - $control = $object->getControl($key); |
|
25 | + // Adding the options inside this SelectBox |
|
26 | + // If the custom method is not from a module, than it's from the core |
|
27 | + $control = $object->getControl($key); |
|
28 | 28 | |
29 | - if (isset($control['options'])) { |
|
30 | - $this->addOptionArray($control['options']); |
|
31 | - } else { |
|
32 | - // let's find if the method we need to call comes from an already defined object |
|
33 | - if (isset($control['object'])) { |
|
34 | - if (method_exists($control['object'], $control['method'])) { |
|
35 | - if ($option_array = $control['object']->{$control['method']}()) { |
|
36 | - // Adding the options array to the XoopsFormSelect |
|
37 | - $this->addOptionArray($option_array); |
|
38 | - } |
|
39 | - } |
|
40 | - } else { |
|
41 | - // finding the itemHandler; if none, let's take the itemHandler of the $object |
|
42 | - if (isset($control['itemHandler'])) { |
|
43 | - if (!$control['module']) { |
|
44 | - // Creating the specified core object handler |
|
45 | - $controlHandler = xoops_getHandler($control['itemHandler']); |
|
46 | - } else { |
|
47 | - $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
|
48 | - } |
|
49 | - } else { |
|
50 | - $controlHandler = $object->handler; |
|
51 | - } |
|
29 | + if (isset($control['options'])) { |
|
30 | + $this->addOptionArray($control['options']); |
|
31 | + } else { |
|
32 | + // let's find if the method we need to call comes from an already defined object |
|
33 | + if (isset($control['object'])) { |
|
34 | + if (method_exists($control['object'], $control['method'])) { |
|
35 | + if ($option_array = $control['object']->{$control['method']}()) { |
|
36 | + // Adding the options array to the XoopsFormSelect |
|
37 | + $this->addOptionArray($option_array); |
|
38 | + } |
|
39 | + } |
|
40 | + } else { |
|
41 | + // finding the itemHandler; if none, let's take the itemHandler of the $object |
|
42 | + if (isset($control['itemHandler'])) { |
|
43 | + if (!$control['module']) { |
|
44 | + // Creating the specified core object handler |
|
45 | + $controlHandler = xoops_getHandler($control['itemHandler']); |
|
46 | + } else { |
|
47 | + $controlHandler = xoops_getModuleHandler($control['itemHandler'], $control['module']); |
|
48 | + } |
|
49 | + } else { |
|
50 | + $controlHandler = $object->handler; |
|
51 | + } |
|
52 | 52 | |
53 | - // Checking if the specified method exists |
|
54 | - if (method_exists($controlHandler, $control['method'])) { |
|
55 | - // TODO: How could I pass the parameters in the following call ... |
|
56 | - if ($option_array = $controlHandler->{$control['method']}()) { |
|
57 | - // Adding the options array to the XoopsFormSelect |
|
58 | - $this->addOptionArray($option_array); |
|
59 | - } |
|
60 | - } |
|
61 | - } |
|
62 | - } |
|
63 | - } |
|
53 | + // Checking if the specified method exists |
|
54 | + if (method_exists($controlHandler, $control['method'])) { |
|
55 | + // TODO: How could I pass the parameters in the following call ... |
|
56 | + if ($option_array = $controlHandler->{$control['method']}()) { |
|
57 | + // Adding the options array to the XoopsFormSelect |
|
58 | + $this->addOptionArray($option_array); |
|
59 | + } |
|
60 | + } |
|
61 | + } |
|
62 | + } |
|
63 | + } |
|
64 | 64 | } |
@@ -19,118 +19,118 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class SmartObjectExport |
21 | 21 | { |
22 | - public $handler; |
|
23 | - public $criteria; |
|
24 | - public $fields; |
|
25 | - public $format; |
|
26 | - public $filename; |
|
27 | - public $filepath; |
|
28 | - public $options; |
|
29 | - public $outputMethods = false; |
|
30 | - public $notDisplayFields; |
|
22 | + public $handler; |
|
23 | + public $criteria; |
|
24 | + public $fields; |
|
25 | + public $format; |
|
26 | + public $filename; |
|
27 | + public $filepath; |
|
28 | + public $options; |
|
29 | + public $outputMethods = false; |
|
30 | + public $notDisplayFields; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor |
|
34 | - * |
|
35 | - * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
36 | - * @param CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
37 | - * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
38 | - * @param bool|string $filename name of the file to be created |
|
39 | - * @param bool|string $filepath path where the file will be saved |
|
40 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
41 | - * @param array|bool $options options of the format to be exported in |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - SmartPersistableObjectHandler $objectHandler, |
|
45 | - CriteriaElement $criteria = null, |
|
46 | - $fields = false, |
|
47 | - $filename = false, |
|
48 | - $filepath = false, |
|
49 | - $format = 'csv', |
|
50 | - $options = false |
|
51 | - ) { |
|
52 | - $this->handler = $objectHandler; |
|
53 | - $this->criteria = $criteria; |
|
54 | - $this->fields = $fields; |
|
55 | - $this->filename = $filename; |
|
56 | - $this->format = $format; |
|
57 | - $this->options = $options; |
|
58 | - $this->notDisplayFields = false; |
|
59 | - } |
|
32 | + /** |
|
33 | + * Constructor |
|
34 | + * |
|
35 | + * @param SmartPersistableObjectHandler $objectHandler SmartObjectHandler handling the data we want to export |
|
36 | + * @param CriteriaElement $criteria containing the criteria of the query fetching the objects to be exported |
|
37 | + * @param array|bool $fields fields to be exported. If FALSE then all fields will be exported |
|
38 | + * @param bool|string $filename name of the file to be created |
|
39 | + * @param bool|string $filepath path where the file will be saved |
|
40 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
41 | + * @param array|bool $options options of the format to be exported in |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + SmartPersistableObjectHandler $objectHandler, |
|
45 | + CriteriaElement $criteria = null, |
|
46 | + $fields = false, |
|
47 | + $filename = false, |
|
48 | + $filepath = false, |
|
49 | + $format = 'csv', |
|
50 | + $options = false |
|
51 | + ) { |
|
52 | + $this->handler = $objectHandler; |
|
53 | + $this->criteria = $criteria; |
|
54 | + $this->fields = $fields; |
|
55 | + $this->filename = $filename; |
|
56 | + $this->format = $format; |
|
57 | + $this->options = $options; |
|
58 | + $this->notDisplayFields = false; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Renders the export |
|
63 | - * @param $filename |
|
64 | - */ |
|
65 | - public function render($filename) |
|
66 | - { |
|
67 | - $this->filename = $filename; |
|
61 | + /** |
|
62 | + * Renders the export |
|
63 | + * @param $filename |
|
64 | + */ |
|
65 | + public function render($filename) |
|
66 | + { |
|
67 | + $this->filename = $filename; |
|
68 | 68 | |
69 | - $objects = $this->handler->getObjects($this->criteria); |
|
70 | - $rows = array(); |
|
71 | - $columnsHeaders = array(); |
|
72 | - $firstObject = true; |
|
73 | - foreach ($objects as $object) { |
|
74 | - $row = array(); |
|
75 | - foreach ($object->vars as $key => $var) { |
|
76 | - if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
77 | - if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
78 | - && method_exists($object, $this->outputMethods[$key])) { |
|
79 | - $method = $this->outputMethods[$key]; |
|
80 | - $row[$key] = $object->$method(); |
|
81 | - } else { |
|
82 | - $row[$key] = $object->getVar($key); |
|
83 | - } |
|
84 | - if ($firstObject) { |
|
85 | - // then set the columnsHeaders array as well |
|
86 | - $columnsHeaders[$key] = $var['form_caption']; |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - $firstObject = false; |
|
91 | - $rows[] = $row; |
|
92 | - unset($row); |
|
93 | - } |
|
94 | - $data = array(); |
|
95 | - $data['rows'] = $rows; |
|
96 | - $data['columnsHeaders'] = $columnsHeaders; |
|
97 | - $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
98 | - $smartExportRenderer->execute(); |
|
99 | - } |
|
69 | + $objects = $this->handler->getObjects($this->criteria); |
|
70 | + $rows = array(); |
|
71 | + $columnsHeaders = array(); |
|
72 | + $firstObject = true; |
|
73 | + foreach ($objects as $object) { |
|
74 | + $row = array(); |
|
75 | + foreach ($object->vars as $key => $var) { |
|
76 | + if ((!$this->fields || in_array($key, $this->fields)) && !in_array($key, $this->notDisplayFields)) { |
|
77 | + if ($this->outputMethods && isset($this->outputMethods[$key]) |
|
78 | + && method_exists($object, $this->outputMethods[$key])) { |
|
79 | + $method = $this->outputMethods[$key]; |
|
80 | + $row[$key] = $object->$method(); |
|
81 | + } else { |
|
82 | + $row[$key] = $object->getVar($key); |
|
83 | + } |
|
84 | + if ($firstObject) { |
|
85 | + // then set the columnsHeaders array as well |
|
86 | + $columnsHeaders[$key] = $var['form_caption']; |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + $firstObject = false; |
|
91 | + $rows[] = $row; |
|
92 | + unset($row); |
|
93 | + } |
|
94 | + $data = array(); |
|
95 | + $data['rows'] = $rows; |
|
96 | + $data['columnsHeaders'] = $columnsHeaders; |
|
97 | + $smartExportRenderer = new SmartExportRenderer($data, $this->filename, $this->filepath, $this->format, $this->options); |
|
98 | + $smartExportRenderer->execute(); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Set an array contaning the alternate methods to use instead of the default getVar() |
|
103 | - * |
|
104 | - * $outputMethods array example: 'uid' => 'getUserName'... |
|
105 | - * @param $outputMethods |
|
106 | - */ |
|
107 | - public function setOuptutMethods($outputMethods) |
|
108 | - { |
|
109 | - $this->outputMethods = $outputMethods; |
|
110 | - } |
|
101 | + /** |
|
102 | + * Set an array contaning the alternate methods to use instead of the default getVar() |
|
103 | + * |
|
104 | + * $outputMethods array example: 'uid' => 'getUserName'... |
|
105 | + * @param $outputMethods |
|
106 | + */ |
|
107 | + public function setOuptutMethods($outputMethods) |
|
108 | + { |
|
109 | + $this->outputMethods = $outputMethods; |
|
110 | + } |
|
111 | 111 | |
112 | - /* |
|
112 | + /* |
|
113 | 113 | * Set an array of fields that we don't want in export |
114 | 114 | */ |
115 | - /** |
|
116 | - * @param $fields |
|
117 | - */ |
|
118 | - public function setNotDisplayFields($fields) |
|
119 | - { |
|
120 | - if (!$this->notDisplayFields) { |
|
121 | - if (is_array($fields)) { |
|
122 | - $this->notDisplayFields = $fields; |
|
123 | - } else { |
|
124 | - $this->notDisplayFields = array($fields); |
|
125 | - } |
|
126 | - } else { |
|
127 | - if (is_array($fields)) { |
|
128 | - $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
129 | - } else { |
|
130 | - $this->notDisplayFields[] = $fields; |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
115 | + /** |
|
116 | + * @param $fields |
|
117 | + */ |
|
118 | + public function setNotDisplayFields($fields) |
|
119 | + { |
|
120 | + if (!$this->notDisplayFields) { |
|
121 | + if (is_array($fields)) { |
|
122 | + $this->notDisplayFields = $fields; |
|
123 | + } else { |
|
124 | + $this->notDisplayFields = array($fields); |
|
125 | + } |
|
126 | + } else { |
|
127 | + if (is_array($fields)) { |
|
128 | + $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
|
129 | + } else { |
|
130 | + $this->notDisplayFields[] = $fields; |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -144,186 +144,186 @@ discard block |
||
144 | 144 | */ |
145 | 145 | class SmartExportRenderer |
146 | 146 | { |
147 | - public $data; |
|
148 | - public $format; |
|
149 | - public $filename; |
|
150 | - public $filepath; |
|
151 | - public $options; |
|
147 | + public $data; |
|
148 | + public $format; |
|
149 | + public $filename; |
|
150 | + public $filepath; |
|
151 | + public $options; |
|
152 | 152 | |
153 | - /** |
|
154 | - * Constructor |
|
155 | - * |
|
156 | - * @param array $data contains the data to be exported |
|
157 | - * @param bool|string $filename name of the file in which the exported data will be saved |
|
158 | - * @param bool|string $filepath path where the file will be saved |
|
159 | - * @param string $format format of the ouputed export. Currently only supports CSV |
|
160 | - * @param array $options options of the format to be exported in |
|
161 | - */ |
|
162 | - public function __construct( |
|
163 | - $data, |
|
164 | - $filename = false, |
|
165 | - $filepath = false, |
|
166 | - $format = 'csv', |
|
167 | - $options = array('separator' => ';') |
|
168 | - ) { |
|
169 | - $this->data = $data; |
|
170 | - $this->format = $format; |
|
171 | - $this->filename = $filename; |
|
172 | - $this->filepath = $filepath; |
|
173 | - $this->options = $options; |
|
174 | - } |
|
153 | + /** |
|
154 | + * Constructor |
|
155 | + * |
|
156 | + * @param array $data contains the data to be exported |
|
157 | + * @param bool|string $filename name of the file in which the exported data will be saved |
|
158 | + * @param bool|string $filepath path where the file will be saved |
|
159 | + * @param string $format format of the ouputed export. Currently only supports CSV |
|
160 | + * @param array $options options of the format to be exported in |
|
161 | + */ |
|
162 | + public function __construct( |
|
163 | + $data, |
|
164 | + $filename = false, |
|
165 | + $filepath = false, |
|
166 | + $format = 'csv', |
|
167 | + $options = array('separator' => ';') |
|
168 | + ) { |
|
169 | + $this->data = $data; |
|
170 | + $this->format = $format; |
|
171 | + $this->filename = $filename; |
|
172 | + $this->filepath = $filepath; |
|
173 | + $this->options = $options; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * @param $dataArray |
|
178 | - * @param $separator |
|
179 | - * @param string $trim |
|
180 | - * @param bool $removeEmptyLines |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
184 | - { |
|
185 | - if (!is_array($dataArray) || empty($dataArray)) { |
|
186 | - return ''; |
|
187 | - } |
|
188 | - switch ($trim) { |
|
189 | - case 'none': |
|
190 | - $trimFunction = false; |
|
191 | - break; |
|
192 | - case 'left': |
|
193 | - $trimFunction = 'ltrim'; |
|
194 | - break; |
|
195 | - case 'right': |
|
196 | - $trimFunction = 'rtrim'; |
|
197 | - break; |
|
198 | - default: //'both': |
|
199 | - $trimFunction = 'trim'; |
|
200 | - break; |
|
201 | - } |
|
202 | - $ret = array(); |
|
203 | - foreach ($dataArray as $key => $field) { |
|
204 | - $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
205 | - } |
|
176 | + /** |
|
177 | + * @param $dataArray |
|
178 | + * @param $separator |
|
179 | + * @param string $trim |
|
180 | + * @param bool $removeEmptyLines |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = true) |
|
184 | + { |
|
185 | + if (!is_array($dataArray) || empty($dataArray)) { |
|
186 | + return ''; |
|
187 | + } |
|
188 | + switch ($trim) { |
|
189 | + case 'none': |
|
190 | + $trimFunction = false; |
|
191 | + break; |
|
192 | + case 'left': |
|
193 | + $trimFunction = 'ltrim'; |
|
194 | + break; |
|
195 | + case 'right': |
|
196 | + $trimFunction = 'rtrim'; |
|
197 | + break; |
|
198 | + default: //'both': |
|
199 | + $trimFunction = 'trim'; |
|
200 | + break; |
|
201 | + } |
|
202 | + $ret = array(); |
|
203 | + foreach ($dataArray as $key => $field) { |
|
204 | + $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
|
205 | + } |
|
206 | 206 | |
207 | - return implode($separator, $ret); |
|
208 | - } |
|
207 | + return implode($separator, $ret); |
|
208 | + } |
|
209 | 209 | |
210 | - /** |
|
211 | - * @param $val |
|
212 | - * @param $separator |
|
213 | - * @param $trimFunction |
|
214 | - * @return mixed|string |
|
215 | - */ |
|
216 | - public function valToCsvHelper($val, $separator, $trimFunction) |
|
217 | - { |
|
218 | - if ($trimFunction) { |
|
219 | - $val = $trimFunction($val); |
|
220 | - } |
|
221 | - //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
222 | - $needQuote = false; |
|
223 | - do { |
|
224 | - if (strpos($val, '"') !== false) { |
|
225 | - $val = str_replace('"', '""', $val); |
|
226 | - $needQuote = true; |
|
227 | - break; |
|
228 | - } |
|
229 | - if (strpos($val, $separator) !== false) { |
|
230 | - $needQuote = true; |
|
231 | - break; |
|
232 | - } |
|
233 | - if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
234 | - $needQuote = true; |
|
235 | - break; |
|
236 | - } |
|
237 | - } while (false); |
|
238 | - if ($needQuote) { |
|
239 | - $val = '"' . $val . '"'; |
|
240 | - } |
|
210 | + /** |
|
211 | + * @param $val |
|
212 | + * @param $separator |
|
213 | + * @param $trimFunction |
|
214 | + * @return mixed|string |
|
215 | + */ |
|
216 | + public function valToCsvHelper($val, $separator, $trimFunction) |
|
217 | + { |
|
218 | + if ($trimFunction) { |
|
219 | + $val = $trimFunction($val); |
|
220 | + } |
|
221 | + //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
|
222 | + $needQuote = false; |
|
223 | + do { |
|
224 | + if (strpos($val, '"') !== false) { |
|
225 | + $val = str_replace('"', '""', $val); |
|
226 | + $needQuote = true; |
|
227 | + break; |
|
228 | + } |
|
229 | + if (strpos($val, $separator) !== false) { |
|
230 | + $needQuote = true; |
|
231 | + break; |
|
232 | + } |
|
233 | + if ((strpos($val, "\n") !== false) || (strpos($val, "\r") !== false)) { // \r is for mac |
|
234 | + $needQuote = true; |
|
235 | + break; |
|
236 | + } |
|
237 | + } while (false); |
|
238 | + if ($needQuote) { |
|
239 | + $val = '"' . $val . '"'; |
|
240 | + } |
|
241 | 241 | |
242 | - return $val; |
|
243 | - } |
|
242 | + return $val; |
|
243 | + } |
|
244 | 244 | |
245 | - public function execute() |
|
246 | - { |
|
247 | - $exportFileData = ''; |
|
245 | + public function execute() |
|
246 | + { |
|
247 | + $exportFileData = ''; |
|
248 | 248 | |
249 | - switch ($this->format) { |
|
250 | - case 'csv': |
|
251 | - $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
252 | - $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
253 | - $exportFileData .= $firstRow . "\r\n"; |
|
249 | + switch ($this->format) { |
|
250 | + case 'csv': |
|
251 | + $separator = isset($this->options['separator']) ? $this->options['separator'] : ';'; |
|
252 | + $firstRow = implode($separator, $this->data['columnsHeaders']); |
|
253 | + $exportFileData .= $firstRow . "\r\n"; |
|
254 | 254 | |
255 | - foreach ($this->data['rows'] as $cols) { |
|
256 | - $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
257 | - } |
|
258 | - break; |
|
259 | - } |
|
260 | - $this->saveExportFile($exportFileData); |
|
261 | - } |
|
255 | + foreach ($this->data['rows'] as $cols) { |
|
256 | + $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
|
257 | + } |
|
258 | + break; |
|
259 | + } |
|
260 | + $this->saveExportFile($exportFileData); |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * @param $content |
|
265 | - */ |
|
266 | - public function saveExportFile($content) |
|
267 | - { |
|
268 | - switch ($this->format) { |
|
269 | - case 'csv': |
|
270 | - $this->saveCsv($content); |
|
271 | - break; |
|
272 | - } |
|
273 | - } |
|
263 | + /** |
|
264 | + * @param $content |
|
265 | + */ |
|
266 | + public function saveExportFile($content) |
|
267 | + { |
|
268 | + switch ($this->format) { |
|
269 | + case 'csv': |
|
270 | + $this->saveCsv($content); |
|
271 | + break; |
|
272 | + } |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * @param $content |
|
277 | - */ |
|
278 | - public function saveCsv($content) |
|
279 | - { |
|
280 | - if (!$this->filepath) { |
|
281 | - $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
282 | - } |
|
283 | - if (!$this->filename) { |
|
284 | - $this->filename .= time(); |
|
285 | - $this->filename .= '.csv'; |
|
286 | - } |
|
275 | + /** |
|
276 | + * @param $content |
|
277 | + */ |
|
278 | + public function saveCsv($content) |
|
279 | + { |
|
280 | + if (!$this->filepath) { |
|
281 | + $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
|
282 | + } |
|
283 | + if (!$this->filename) { |
|
284 | + $this->filename .= time(); |
|
285 | + $this->filename .= '.csv'; |
|
286 | + } |
|
287 | 287 | |
288 | - $fullFileName = $this->filepath . $this->filename; |
|
288 | + $fullFileName = $this->filepath . $this->filename; |
|
289 | 289 | |
290 | - if (!$handle = fopen($fullFileName, 'a+')) { |
|
291 | - trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
292 | - } elseif (fwrite($handle, $content) === false) { |
|
293 | - trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
294 | - } else { |
|
295 | - $mimeType = 'text/csv'; |
|
296 | - $file = strrev($this->filename); |
|
297 | - $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
298 | - if ($temp_name === '') { |
|
299 | - $file_name = $this->filename; |
|
300 | - } else { |
|
301 | - $file_name = $temp_name; |
|
302 | - } |
|
303 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
290 | + if (!$handle = fopen($fullFileName, 'a+')) { |
|
291 | + trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
|
292 | + } elseif (fwrite($handle, $content) === false) { |
|
293 | + trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
|
294 | + } else { |
|
295 | + $mimeType = 'text/csv'; |
|
296 | + $file = strrev($this->filename); |
|
297 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
|
298 | + if ($temp_name === '') { |
|
299 | + $file_name = $this->filename; |
|
300 | + } else { |
|
301 | + $file_name = $temp_name; |
|
302 | + } |
|
303 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
304 | 304 | |
305 | - if (ini_get('zlib.output_compression')) { |
|
306 | - ini_set('zlib.output_compression', 'Off'); |
|
307 | - } |
|
305 | + if (ini_get('zlib.output_compression')) { |
|
306 | + ini_set('zlib.output_compression', 'Off'); |
|
307 | + } |
|
308 | 308 | |
309 | - header('Pragma: public'); |
|
310 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
311 | - header('Cache-Control: private', false); |
|
312 | - header('Content-Transfer-Encoding: binary'); |
|
313 | - if (isset($mimeType)) { |
|
314 | - header('Content-Type: ' . $mimeType); |
|
315 | - } |
|
309 | + header('Pragma: public'); |
|
310 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
311 | + header('Cache-Control: private', false); |
|
312 | + header('Content-Transfer-Encoding: binary'); |
|
313 | + if (isset($mimeType)) { |
|
314 | + header('Content-Type: ' . $mimeType); |
|
315 | + } |
|
316 | 316 | |
317 | - header('Content-Disposition: attachment; filename=' . $file_name); |
|
317 | + header('Content-Disposition: attachment; filename=' . $file_name); |
|
318 | 318 | |
319 | - if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
320 | - $fp = fopen($fullFileName, 'r'); |
|
321 | - } else { |
|
322 | - $fp = fopen($fullFileName, 'rb'); |
|
323 | - } |
|
324 | - fpassthru($fp); |
|
325 | - exit(); |
|
326 | - } |
|
327 | - fclose($handle); |
|
328 | - } |
|
319 | + if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
|
320 | + $fp = fopen($fullFileName, 'r'); |
|
321 | + } else { |
|
322 | + $fp = fopen($fullFileName, 'rb'); |
|
323 | + } |
|
324 | + fpassthru($fp); |
|
325 | + exit(); |
|
326 | + } |
|
327 | + fclose($handle); |
|
328 | + } |
|
329 | 329 | } |