@@ -78,6 +78,9 @@ |
||
78 | 78 | 'maxlength' => 6)); |
79 | 79 | } |
80 | 80 | |
81 | + /** |
|
82 | + * @param string $key |
|
83 | + */ |
|
81 | 84 | function getVar($key, $format = 's') { |
82 | 85 | if ($format == 's' && in_array($key, array())) { |
83 | 86 | return call_user_func(array($this,$key)); |
@@ -73,6 +73,9 @@ |
||
73 | 73 | $this->hideFieldFromForm('default_currency'); |
74 | 74 | } |
75 | 75 | |
76 | + /** |
|
77 | + * @param string $key |
|
78 | + */ |
|
76 | 79 | function getVar($key, $format = 's') { |
77 | 80 | if ($format == 's' && in_array($key, array('rate', 'default_currency'))) { |
78 | 81 | return call_user_func(array($this,$key)); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // -------------------------------------------------------------------------// |
29 | 29 | |
30 | 30 | if (!defined("XOOPS_ROOT_PATH")) { |
31 | - die("XOOPS root path not defined"); |
|
31 | + die("XOOPS root path not defined"); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | var $_modulePlugin=false; |
40 | 40 | |
41 | - function SmartobjectCurrency() { |
|
42 | - $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
41 | + function SmartobjectCurrency() { |
|
42 | + $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
|
43 | 43 | $this->quickInitVar('iso4217', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_ISO4217, _CO_SOBJECT_CURRENCY_ISO4217_DSC); |
44 | 44 | $this->quickInitVar('name', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_NAME); |
45 | 45 | $this->quickInitVar('symbol', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_CURRENCY_SYMBOL); |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | )); |
72 | 72 | |
73 | 73 | $this->hideFieldFromForm('default_currency'); |
74 | - } |
|
74 | + } |
|
75 | 75 | |
76 | - function getVar($key, $format = 's') { |
|
77 | - if ($format == 's' && in_array($key, array('rate', 'default_currency'))) { |
|
78 | - return call_user_func(array($this,$key)); |
|
79 | - } |
|
80 | - return parent::getVar($key, $format); |
|
81 | - } |
|
76 | + function getVar($key, $format = 's') { |
|
77 | + if ($format == 's' && in_array($key, array('rate', 'default_currency'))) { |
|
78 | + return call_user_func(array($this,$key)); |
|
79 | + } |
|
80 | + return parent::getVar($key, $format); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | function getCurrencyLink() { |
84 | 84 | $ret = $this->getVar('name', 'e'); |
@@ -90,17 +90,17 @@ discard block |
||
90 | 90 | return $ret; |
91 | 91 | } |
92 | 92 | |
93 | - function rate() { |
|
94 | - return smart_currency($this->getVar('rate', 'e')); |
|
95 | - } |
|
93 | + function rate() { |
|
94 | + return smart_currency($this->getVar('rate', 'e')); |
|
95 | + } |
|
96 | 96 | |
97 | - function default_currency() { |
|
98 | - if ($this->getVar('default_currency', 'e') == true) { |
|
99 | - return _YES; |
|
100 | - } else { |
|
101 | - return _NO; |
|
102 | - } |
|
103 | - } |
|
97 | + function default_currency() { |
|
98 | + if ($this->getVar('default_currency', 'e') == true) { |
|
99 | + return _YES; |
|
100 | + } else { |
|
101 | + return _NO; |
|
102 | + } |
|
103 | + } |
|
104 | 104 | |
105 | 105 | function getDefault_currencyControl() { |
106 | 106 | $radio_box = '<input name="default_currency" value="' . $this->getVar('currencyid') . '" type="radio"'; |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | } |
115 | 115 | class SmartobjectCurrencyHandler extends SmartPersistableObjectHandler { |
116 | 116 | |
117 | - function SmartobjectCurrencyHandler($db) { |
|
118 | - $this->SmartPersistableObjectHandler($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
119 | - } |
|
117 | + function SmartobjectCurrencyHandler($db) { |
|
118 | + $this->SmartPersistableObjectHandler($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
119 | + } |
|
120 | 120 | |
121 | - function getCurrencies() { |
|
122 | - $currenciesObj = $this->getObjects(null, true); |
|
123 | - return $currenciesObj; |
|
124 | - } |
|
121 | + function getCurrencies() { |
|
122 | + $currenciesObj = $this->getObjects(null, true); |
|
123 | + return $currenciesObj; |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | ?> |
127 | 127 | \ No newline at end of file |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | die("XOOPS root path not defined"); |
32 | 32 | } |
33 | 33 | |
34 | -include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
|
34 | +include_once XOOPS_ROOT_PATH . "/modules/smartobject/class/smartobject.php"; |
|
35 | 35 | include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
36 | 36 | |
37 | 37 | class SmartobjectCurrency extends SmartObject { |
38 | 38 | |
39 | - var $_modulePlugin=false; |
|
39 | + var $_modulePlugin = false; |
|
40 | 40 | |
41 | 41 | function SmartobjectCurrency() { |
42 | 42 | $this->quickInitVar('currencyid', XOBJ_DTYPE_INT, true); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | function getVar($key, $format = 's') { |
77 | 77 | if ($format == 's' && in_array($key, array('rate', 'default_currency'))) { |
78 | - return call_user_func(array($this,$key)); |
|
78 | + return call_user_func(array($this, $key)); |
|
79 | 79 | } |
80 | 80 | return parent::getVar($key, $format); |
81 | 81 | } |
@@ -57,6 +57,9 @@ |
||
57 | 57 | |
58 | 58 | } |
59 | 59 | |
60 | + /** |
|
61 | + * @param string $key |
|
62 | + */ |
|
60 | 63 | function getVar($key, $format = 's') { |
61 | 64 | if ($format == 's' && in_array($key, array())) { |
62 | 65 | return call_user_func(array($this,$key)); |
@@ -39,12 +39,6 @@ |
||
39 | 39 | /** |
40 | 40 | * Constructor |
41 | 41 | * |
42 | - * @param string $caption Caption |
|
43 | - * @param string $name "name" attribute |
|
44 | - * @param int $size Size of the field |
|
45 | - * @param int $maxlength Maximum length of the text |
|
46 | - * @param int $value Initial value of the field. |
|
47 | - * <b>Warning:</b> this is readable in cleartext in the page's source! |
|
48 | 42 | */ |
49 | 43 | function SmartFormSet_passwordElement($object, $key){ |
50 | 44 |
@@ -1,14 +1,14 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Contains the set password tray class |
|
4 | - * |
|
5 | - * @license GNU |
|
6 | - * @author marcan <[email protected]> |
|
7 | - * @version $Id: smartformset_passwordelement.php 159 2007-12-17 16:44:05Z malanciault $ |
|
8 | - * @link http://smartfactory.ca The SmartFactory |
|
9 | - * @package SmartObject |
|
10 | - * @subpackage SmartObjectForm |
|
11 | - */ |
|
3 | + * Contains the set password tray class |
|
4 | + * |
|
5 | + * @license GNU |
|
6 | + * @author marcan <[email protected]> |
|
7 | + * @version $Id: smartformset_passwordelement.php 159 2007-12-17 16:44:05Z malanciault $ |
|
8 | + * @link http://smartfactory.ca The SmartFactory |
|
9 | + * @package SmartObject |
|
10 | + * @subpackage SmartObjectForm |
|
11 | + */ |
|
12 | 12 | if (!defined('XOOPS_ROOT_PATH')) { |
13 | 13 | die("XOOPS root path not defined"); |
14 | 14 | } |
@@ -16,21 +16,21 @@ discard block |
||
16 | 16 | class SmartFormSet_passwordElement extends XoopsFormElementTray { |
17 | 17 | |
18 | 18 | /** |
19 | - * Size of the field. |
|
19 | + * Size of the field. |
|
20 | 20 | * @var int |
21 | 21 | * @access private |
22 | 22 | */ |
23 | 23 | var $_size; |
24 | 24 | |
25 | 25 | /** |
26 | - * Maximum length of the text |
|
26 | + * Maximum length of the text |
|
27 | 27 | * @var int |
28 | 28 | * @access private |
29 | 29 | */ |
30 | 30 | var $_maxlength; |
31 | 31 | |
32 | 32 | /** |
33 | - * Initial content of the field. |
|
33 | + * Initial content of the field. |
|
34 | 34 | * @var string |
35 | 35 | * @access private |
36 | 36 | */ |
@@ -48,10 +48,10 @@ discard block |
||
48 | 48 | */ |
49 | 49 | function SmartFormSet_passwordElement($object, $key){ |
50 | 50 | |
51 | - $var = $object->vars[$key]; |
|
52 | - $control = $object->controls[$key]; |
|
51 | + $var = $object->vars[$key]; |
|
52 | + $control = $object->controls[$key]; |
|
53 | 53 | |
54 | - $this->XoopsFormElementTray($var['form_caption'] . '<br />' . _US_TYPEPASSTWICE, ' ', $key . '_password_tray'); |
|
54 | + $this->XoopsFormElementTray($var['form_caption'] . '<br />' . _US_TYPEPASSTWICE, ' ', $key . '_password_tray'); |
|
55 | 55 | |
56 | 56 | $password_box1 = new XoopsFormPassword('', $key . '1', 10, 32); |
57 | 57 | $this->addElement($password_box1); |
@@ -46,7 +46,7 @@ |
||
46 | 46 | * @param int $value Initial value of the field. |
47 | 47 | * <b>Warning:</b> this is readable in cleartext in the page's source! |
48 | 48 | */ |
49 | - function SmartFormSet_passwordElement($object, $key){ |
|
49 | + function SmartFormSet_passwordElement($object, $key) { |
|
50 | 50 | |
51 | 51 | $var = $object->vars[$key]; |
52 | 52 | $control = $object->controls[$key]; |
@@ -11,6 +11,10 @@ |
||
11 | 11 | * @subpackage SmartObjectForm |
12 | 12 | */ |
13 | 13 | class SmartFormTextElement extends XoopsFormText { |
14 | + |
|
15 | + /** |
|
16 | + * @param string $key |
|
17 | + */ |
|
14 | 18 | function SmartFormTextElement($object, $key) { |
15 | 19 | $var = $object->vars[$key]; |
16 | 20 |
@@ -11,12 +11,12 @@ discard block |
||
11 | 11 | * @subpackage SmartObjectForm |
12 | 12 | */ |
13 | 13 | class SmartFormTextElement extends XoopsFormText { |
14 | - function SmartFormTextElement($object, $key) { |
|
14 | + function SmartFormTextElement($object, $key) { |
|
15 | 15 | $var = $object->vars[$key]; |
16 | 16 | |
17 | 17 | if(isset($object->controls[$key])){ |
18 | 18 | $control = $object->controls[$key]; |
19 | - $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
|
19 | + $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
|
20 | 20 | $form_size = isset($control['size']) ? $control['size'] : 50; |
21 | 21 | }else{ |
22 | 22 | $form_maxlength = 255; |
@@ -24,6 +24,6 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | $this->XoopsFormText($var['form_caption'], $key, $form_size, $form_maxlength, $object->getVar($key, 'e')); |
27 | - } |
|
27 | + } |
|
28 | 28 | } |
29 | 29 | ?> |
30 | 30 | \ No newline at end of file |
@@ -14,12 +14,12 @@ |
||
14 | 14 | function SmartFormTextElement($object, $key) { |
15 | 15 | $var = $object->vars[$key]; |
16 | 16 | |
17 | - if(isset($object->controls[$key])){ |
|
17 | + if (isset($object->controls[$key])) { |
|
18 | 18 | $control = $object->controls[$key]; |
19 | 19 | $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
20 | 20 | $form_size = isset($control['size']) ? $control['size'] : 50; |
21 | - }else{ |
|
22 | - $form_maxlength = 255; |
|
21 | + } else { |
|
22 | + $form_maxlength = 255; |
|
23 | 23 | $form_size = 50; |
24 | 24 | } |
25 | 25 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | $control = $object->controls[$key]; |
19 | 19 | $form_maxlength = isset($control['maxlength']) ? $control['maxlength'] : (isset($var['maxlength']) ? $var['maxlength'] : 255); |
20 | 20 | $form_size = isset($control['size']) ? $control['size'] : 50; |
21 | - }else{ |
|
21 | + } else{ |
|
22 | 22 | $form_maxlength = 255; |
23 | 23 | $form_size = 50; |
24 | 24 | } |
@@ -42,6 +42,10 @@ discard block |
||
42 | 42 | var $_form_caption=false; |
43 | 43 | var $_submit_button_caption=false; |
44 | 44 | |
45 | + /** |
|
46 | + * @param SmartObject $target |
|
47 | + * @param boolean $form_action |
|
48 | + */ |
|
45 | 49 | function SmartobjectForm(&$target, $form_name, $form_caption, $form_action, $form_fields=null, $submit_button_caption = false, $cancel_js_action=false, $captcha=false) { |
46 | 50 | |
47 | 51 | $this->targetObject =& $target; |
@@ -88,7 +92,7 @@ discard block |
||
88 | 92 | * Add an element to the form |
89 | 93 | * |
90 | 94 | * @param object &$formElement reference to a {@link XoopsFormElement} |
91 | - * @param bool $required is this a "required" element? |
|
95 | + * @param string|boolean $required is this a "required" element? |
|
92 | 96 | */ |
93 | 97 | function addElement(&$formElement, $key=false, $var=false, $required='notset'){ |
94 | 98 | if ($key) { |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | if (!defined("XOOPS_ROOT_PATH")) { |
15 | - die("XOOPS root path not defined"); |
|
15 | + die("XOOPS root path not defined"); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -33,143 +33,143 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class SmartobjectForm extends XoopsThemeForm { |
35 | 35 | |
36 | - var $targetObject = null; |
|
37 | - var $form_fields = null; |
|
38 | - var $_cancel_js_action=false; |
|
39 | - var $_custom_button=false; |
|
40 | - var $_captcha=false; |
|
41 | - var $_form_name=false; |
|
42 | - var $_form_caption=false; |
|
43 | - var $_submit_button_caption=false; |
|
36 | + var $targetObject = null; |
|
37 | + var $form_fields = null; |
|
38 | + var $_cancel_js_action=false; |
|
39 | + var $_custom_button=false; |
|
40 | + var $_captcha=false; |
|
41 | + var $_form_name=false; |
|
42 | + var $_form_caption=false; |
|
43 | + var $_submit_button_caption=false; |
|
44 | 44 | |
45 | - function SmartobjectForm(&$target, $form_name, $form_caption, $form_action, $form_fields=null, $submit_button_caption = false, $cancel_js_action=false, $captcha=false) { |
|
45 | + function SmartobjectForm(&$target, $form_name, $form_caption, $form_action, $form_fields=null, $submit_button_caption = false, $cancel_js_action=false, $captcha=false) { |
|
46 | 46 | |
47 | - $this->targetObject =& $target; |
|
48 | - $this->form_fields = $form_fields; |
|
49 | - $this->_cancel_js_action = $cancel_js_action; |
|
50 | - $this->_captcha= $captcha; |
|
51 | - $this->_form_name= $form_name; |
|
52 | - $this->_form_caption= $form_caption; |
|
53 | - $this->_submit_button_caption= $submit_button_caption; |
|
47 | + $this->targetObject =& $target; |
|
48 | + $this->form_fields = $form_fields; |
|
49 | + $this->_cancel_js_action = $cancel_js_action; |
|
50 | + $this->_captcha= $captcha; |
|
51 | + $this->_form_name= $form_name; |
|
52 | + $this->_form_caption= $form_caption; |
|
53 | + $this->_submit_button_caption= $submit_button_caption; |
|
54 | 54 | |
55 | - if (!isset($form_action)) { |
|
56 | - $form_action = xoops_getenv('PHP_SELF'); |
|
57 | - } |
|
55 | + if (!isset($form_action)) { |
|
56 | + $form_action = xoops_getenv('PHP_SELF'); |
|
57 | + } |
|
58 | 58 | |
59 | - $this->XoopsForm( $form_caption, $form_name, $form_action); |
|
60 | - $this->setExtra('enctype="multipart/form-data"'); |
|
59 | + $this->XoopsForm( $form_caption, $form_name, $form_action); |
|
60 | + $this->setExtra('enctype="multipart/form-data"'); |
|
61 | 61 | |
62 | - $this->createElements(); |
|
62 | + $this->createElements(); |
|
63 | 63 | |
64 | - if ($captcha) { |
|
65 | - $this->addCaptcha(); |
|
66 | - } |
|
64 | + if ($captcha) { |
|
65 | + $this->addCaptcha(); |
|
66 | + } |
|
67 | 67 | |
68 | - $this->createPermissionControls(); |
|
68 | + $this->createPermissionControls(); |
|
69 | 69 | |
70 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
71 | - } |
|
70 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
71 | + } |
|
72 | 72 | |
73 | - function addCaptcha() { |
|
74 | - include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
75 | - $this->addElement(new XoopsFormCaptcha(), true); |
|
76 | - } |
|
73 | + function addCaptcha() { |
|
74 | + include_once(SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'); |
|
75 | + $this->addElement(new XoopsFormCaptcha(), true); |
|
76 | + } |
|
77 | 77 | |
78 | - function addCustomButton($name, $caption, $onclick=false) { |
|
79 | - $custom_button_array = array( |
|
78 | + function addCustomButton($name, $caption, $onclick=false) { |
|
79 | + $custom_button_array = array( |
|
80 | 80 | 'name' => $name, |
81 | 81 | 'caption' => $caption, |
82 | 82 | 'onclick' => $onclick |
83 | - ); |
|
84 | - $this->_custom_button[] = $custom_button_array; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Add an element to the form |
|
89 | - * |
|
90 | - * @param object &$formElement reference to a {@link XoopsFormElement} |
|
91 | - * @param bool $required is this a "required" element? |
|
92 | - */ |
|
93 | - function addElement(&$formElement, $key=false, $var=false, $required='notset'){ |
|
94 | - if ($key) { |
|
95 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
96 | - $formElement->setExtra('disabled="disabled"'); |
|
97 | - $formElement->setName($key . '-readonly'); |
|
98 | - // Since this element is disable, we still want to pass it's value in the form |
|
99 | - $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
100 | - $this->addElement($hidden); |
|
101 | - } |
|
102 | - $formElement->setDescription($var['form_dsc']); |
|
103 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
104 | - $hidden = new XoopsFormHidden('changedField', false); |
|
105 | - $this->addElement($hidden); |
|
106 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
107 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
108 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
109 | - } else { |
|
110 | - if (isset($var['form_extra'])) { |
|
111 | - $formElement->setExtra($var['form_extra']); |
|
112 | - } |
|
113 | - } |
|
114 | - $controls = $this->targetObject->controls; |
|
115 | - if(isset($controls[$key]['js'])){ |
|
116 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
117 | - } |
|
118 | - parent::AddElement($formElement, $required == 'notset' ? $var['required'] : $required); |
|
119 | - } else { |
|
120 | - parent::AddElement($formElement, $required == 'notset' ? false : true); |
|
121 | - } |
|
122 | - unset($formElement); |
|
123 | - } |
|
124 | - |
|
125 | - function createElements() { |
|
126 | - $controls = $this->targetObject->controls; |
|
127 | - $vars = $this->targetObject->vars; |
|
128 | - foreach ($vars as $key=>$var) { |
|
129 | - |
|
130 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
131 | - // need to be displayed, then we only create an hidden field |
|
132 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
133 | - $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
134 | - $this->addElement($elementToAdd, $key, $var, false); |
|
135 | - unset($elementToAdd); |
|
136 | - // If not, the we need to create the proper form control for this fields |
|
137 | - } else { |
|
138 | - // If this field has a specific control, we will use it |
|
139 | - |
|
140 | - if ($key == 'parentid') { |
|
141 | - /** |
|
142 | - * Why this ? |
|
143 | - */ |
|
144 | - } |
|
145 | - if (isset($controls[$key])) { |
|
146 | - /* If the control has name, it's because it's an object already present in the script |
|
83 | + ); |
|
84 | + $this->_custom_button[] = $custom_button_array; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Add an element to the form |
|
89 | + * |
|
90 | + * @param object &$formElement reference to a {@link XoopsFormElement} |
|
91 | + * @param bool $required is this a "required" element? |
|
92 | + */ |
|
93 | + function addElement(&$formElement, $key=false, $var=false, $required='notset'){ |
|
94 | + if ($key) { |
|
95 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
96 | + $formElement->setExtra('disabled="disabled"'); |
|
97 | + $formElement->setName($key . '-readonly'); |
|
98 | + // Since this element is disable, we still want to pass it's value in the form |
|
99 | + $hidden = new XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
100 | + $this->addElement($hidden); |
|
101 | + } |
|
102 | + $formElement->setDescription($var['form_dsc']); |
|
103 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
104 | + $hidden = new XoopsFormHidden('changedField', false); |
|
105 | + $this->addElement($hidden); |
|
106 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
107 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
108 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
109 | + } else { |
|
110 | + if (isset($var['form_extra'])) { |
|
111 | + $formElement->setExtra($var['form_extra']); |
|
112 | + } |
|
113 | + } |
|
114 | + $controls = $this->targetObject->controls; |
|
115 | + if(isset($controls[$key]['js'])){ |
|
116 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
117 | + } |
|
118 | + parent::AddElement($formElement, $required == 'notset' ? $var['required'] : $required); |
|
119 | + } else { |
|
120 | + parent::AddElement($formElement, $required == 'notset' ? false : true); |
|
121 | + } |
|
122 | + unset($formElement); |
|
123 | + } |
|
124 | + |
|
125 | + function createElements() { |
|
126 | + $controls = $this->targetObject->controls; |
|
127 | + $vars = $this->targetObject->vars; |
|
128 | + foreach ($vars as $key=>$var) { |
|
129 | + |
|
130 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
131 | + // need to be displayed, then we only create an hidden field |
|
132 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
133 | + $elementToAdd = new XoopsFormHidden($key, $var['value']); |
|
134 | + $this->addElement($elementToAdd, $key, $var, false); |
|
135 | + unset($elementToAdd); |
|
136 | + // If not, the we need to create the proper form control for this fields |
|
137 | + } else { |
|
138 | + // If this field has a specific control, we will use it |
|
139 | + |
|
140 | + if ($key == 'parentid') { |
|
141 | + /** |
|
142 | + * Why this ? |
|
143 | + */ |
|
144 | + } |
|
145 | + if (isset($controls[$key])) { |
|
146 | + /* If the control has name, it's because it's an object already present in the script |
|
147 | 147 | * for example, "user" |
148 | 148 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
149 | 149 | */ |
150 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
151 | - $controls[$key]['name'] = 'select'; |
|
152 | - } |
|
150 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
151 | + $controls[$key]['name'] = 'select'; |
|
152 | + } |
|
153 | 153 | |
154 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
154 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
155 | 155 | |
156 | - // Adding on the form, the control for this field |
|
157 | - $this->addElement($form_select, $key, $var); |
|
158 | - unset($form_select); |
|
156 | + // Adding on the form, the control for this field |
|
157 | + $this->addElement($form_select, $key, $var); |
|
158 | + unset($form_select); |
|
159 | 159 | |
160 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
161 | - } else { |
|
162 | - switch ($var['data_type']) { |
|
160 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
161 | + } else { |
|
162 | + switch ($var['data_type']) { |
|
163 | 163 | |
164 | - case XOBJ_DTYPE_TXTBOX: |
|
164 | + case XOBJ_DTYPE_TXTBOX: |
|
165 | 165 | |
166 | - $form_text = $this->getControl("text", $key); |
|
167 | - $this->addElement($form_text, $key, $var); |
|
168 | - unset($form_text); |
|
169 | - break; |
|
166 | + $form_text = $this->getControl("text", $key); |
|
167 | + $this->addElement($form_text, $key, $var); |
|
168 | + unset($form_text); |
|
169 | + break; |
|
170 | 170 | |
171 | - case XOBJ_DTYPE_INT: |
|
172 | - $this->targetObject->setControl($key, array( |
|
171 | + case XOBJ_DTYPE_INT: |
|
172 | + $this->targetObject->setControl($key, array( |
|
173 | 173 | 'name' => 'text', |
174 | 174 | 'size' => '5' |
175 | 175 | )); |
@@ -178,8 +178,8 @@ discard block |
||
178 | 178 | unset($form_text); |
179 | 179 | break; |
180 | 180 | |
181 | - case XOBJ_DTYPE_FLOAT: |
|
182 | - $this->targetObject->setControl($key, array( |
|
181 | + case XOBJ_DTYPE_FLOAT: |
|
182 | + $this->targetObject->setControl($key, array( |
|
183 | 183 | 'name' => 'text', |
184 | 184 | 'size' => '5' |
185 | 185 | )); |
@@ -188,26 +188,26 @@ discard block |
||
188 | 188 | unset($form_text); |
189 | 189 | break; |
190 | 190 | |
191 | - case XOBJ_DTYPE_LTIME: |
|
192 | - $form_date_time = $this->getControl('date_time', $key); |
|
193 | - $this->addElement($form_date_time, $key, $var); |
|
194 | - unset($form_date_time); |
|
195 | - break; |
|
196 | - |
|
197 | - case XOBJ_DTYPE_STIME: |
|
198 | - $form_date_time = $this->getControl('date', $key); |
|
199 | - $this->addElement($form_date_time, $key, $var); |
|
200 | - unset($form_date_time); |
|
201 | - break; |
|
202 | - |
|
203 | - case XOBJ_DTYPE_TIME_ONLY: |
|
204 | - $form_time = $this->getControl('time', $key); |
|
205 | - $this->addElement($form_time, $key, $var); |
|
206 | - unset($form_time); |
|
207 | - break; |
|
208 | - |
|
209 | - case XOBJ_DTYPE_CURRENCY: |
|
210 | - $this->targetObject->setControl($key, array( |
|
191 | + case XOBJ_DTYPE_LTIME: |
|
192 | + $form_date_time = $this->getControl('date_time', $key); |
|
193 | + $this->addElement($form_date_time, $key, $var); |
|
194 | + unset($form_date_time); |
|
195 | + break; |
|
196 | + |
|
197 | + case XOBJ_DTYPE_STIME: |
|
198 | + $form_date_time = $this->getControl('date', $key); |
|
199 | + $this->addElement($form_date_time, $key, $var); |
|
200 | + unset($form_date_time); |
|
201 | + break; |
|
202 | + |
|
203 | + case XOBJ_DTYPE_TIME_ONLY: |
|
204 | + $form_time = $this->getControl('time', $key); |
|
205 | + $this->addElement($form_time, $key, $var); |
|
206 | + unset($form_time); |
|
207 | + break; |
|
208 | + |
|
209 | + case XOBJ_DTYPE_CURRENCY: |
|
210 | + $this->targetObject->setControl($key, array( |
|
211 | 211 | 'name' => 'text', |
212 | 212 | 'size' => '15' |
213 | 213 | )); |
@@ -216,511 +216,511 @@ discard block |
||
216 | 216 | unset($form_currency); |
217 | 217 | break; |
218 | 218 | |
219 | - case XOBJ_DTYPE_URLLINK: |
|
220 | - $form_urllink = $this->getControl("urllink", $key); |
|
221 | - $this->addElement($form_urllink, $key, $var); |
|
222 | - unset($form_urllink); |
|
223 | - break; |
|
224 | - |
|
225 | - case XOBJ_DTYPE_FILE: |
|
226 | - $form_file = $this->getControl("richfile", $key); |
|
227 | - $this->addElement($form_file, $key, $var); |
|
228 | - unset($form_file); |
|
229 | - break; |
|
230 | - |
|
231 | - case XOBJ_DTYPE_TXTAREA: |
|
232 | - |
|
233 | - $form_text_area = $this->getTextArea($key, $var); |
|
234 | - $this->addElement($form_text_area, $key, $var); |
|
235 | - unset($form_text_area); |
|
236 | - break; |
|
237 | - |
|
238 | - case XOBJ_DTYPE_ARRAY: |
|
239 | - // TODO : To come... |
|
240 | - break; |
|
241 | - case XOBJ_DTYPE_SOURCE: |
|
242 | - // TODO : To come... |
|
243 | - break; |
|
244 | - case XOBJ_DTYPE_FORM_SECTION: |
|
245 | - $section_control = new SmartFormSection($key, $var['value']); |
|
246 | - $this->addElement($section_control, $key, $var); |
|
247 | - unset($section_control); |
|
248 | - break; |
|
249 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
250 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
251 | - $this->addElement($section_control, $key, $var); |
|
252 | - unset($section_control); |
|
253 | - break; |
|
254 | - } |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - // Add an hidden field to store the URL of the page before this form |
|
259 | - $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
260 | - } |
|
261 | - |
|
262 | - function createPermissionControls() { |
|
263 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
264 | - |
|
265 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
266 | - |
|
267 | - if ($permissions) { |
|
268 | - $member_handler = &xoops_gethandler('member'); |
|
269 | - $group_list = $member_handler->getGroupList(); |
|
270 | - asort($group_list); |
|
271 | - foreach($permissions as $permission) { |
|
272 | - if ($this->targetObject->isNew()) { |
|
273 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
274 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
275 | - } |
|
276 | - } else { |
|
277 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
278 | - } |
|
279 | - $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
280 | - $groups_select->setDescription($permission['description']); |
|
281 | - $groups_select->addOptionArray($group_list); |
|
282 | - $this->addElement($groups_select); |
|
283 | - unset($groups_select); |
|
284 | - } |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - function createButtons($form_name, $form_caption, $submit_button_caption = false) { |
|
289 | - |
|
290 | - $button_tray = new XoopsFormElementTray('', ''); |
|
291 | - $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
292 | - if(!$submit_button_caption){ |
|
293 | - if ($this->targetObject->isNew()) { |
|
294 | - $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
295 | - } else { |
|
296 | - $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
297 | - } |
|
298 | - } |
|
299 | - else { |
|
300 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption , 'submit'); |
|
301 | - } |
|
302 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
303 | - $button_tray->addElement($butt_create); |
|
304 | - |
|
305 | - //creating custom buttons |
|
306 | - if ($this->_custom_button) { |
|
307 | - foreach($this->_custom_button as $custom_button) { |
|
308 | - $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
309 | - if ($custom_button['onclick']) { |
|
310 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
311 | - } |
|
312 | - $button_tray->addElement($butt_custom); |
|
313 | - unset($butt_custom); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - // creating the "cancel" button |
|
318 | - $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
319 | - if ($this->_cancel_js_action) { |
|
320 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
321 | - } else { |
|
322 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
323 | - } |
|
324 | - $button_tray->addElement($butt_cancel); |
|
325 | - |
|
326 | - $this->addElement($button_tray); |
|
327 | - } |
|
328 | - |
|
329 | - function getControl($controlName, $key) { |
|
330 | - switch ($controlName) { |
|
331 | - case 'check': |
|
332 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformcheckelement.php"); |
|
333 | - $control = $this->targetObject->getControl($key); |
|
334 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
335 | - $controlObj->addOptionArray($control['options']); |
|
336 | - return $controlObj; |
|
337 | - break; |
|
338 | - |
|
339 | - case 'color': |
|
340 | - $control = $this->targetObject->getControl($key); |
|
341 | - $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
342 | - return $controlObj; |
|
343 | - break; |
|
344 | - |
|
345 | - case 'radio': |
|
346 | - $control = $this->targetObject->getControl($key); |
|
347 | - |
|
348 | - $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
349 | - $controlObj->addOptionArray($control['options']); |
|
350 | - return $controlObj; |
|
351 | - break; |
|
352 | - |
|
353 | - case 'label': |
|
354 | - return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
355 | - break; |
|
356 | - |
|
357 | - case 'textarea' : |
|
358 | - return $this->getTextArea($key); |
|
359 | - |
|
360 | - case 'theme': |
|
361 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
362 | - |
|
363 | - case 'theme_multi': |
|
364 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
365 | - break; |
|
366 | - |
|
367 | - case 'timezone': |
|
368 | - return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
369 | - break; |
|
370 | - |
|
371 | - case 'group': |
|
372 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
373 | - break; |
|
374 | - |
|
375 | - case 'group_multi': |
|
376 | - return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
377 | - break; |
|
378 | - |
|
379 | - /*case 'user': |
|
219 | + case XOBJ_DTYPE_URLLINK: |
|
220 | + $form_urllink = $this->getControl("urllink", $key); |
|
221 | + $this->addElement($form_urllink, $key, $var); |
|
222 | + unset($form_urllink); |
|
223 | + break; |
|
224 | + |
|
225 | + case XOBJ_DTYPE_FILE: |
|
226 | + $form_file = $this->getControl("richfile", $key); |
|
227 | + $this->addElement($form_file, $key, $var); |
|
228 | + unset($form_file); |
|
229 | + break; |
|
230 | + |
|
231 | + case XOBJ_DTYPE_TXTAREA: |
|
232 | + |
|
233 | + $form_text_area = $this->getTextArea($key, $var); |
|
234 | + $this->addElement($form_text_area, $key, $var); |
|
235 | + unset($form_text_area); |
|
236 | + break; |
|
237 | + |
|
238 | + case XOBJ_DTYPE_ARRAY: |
|
239 | + // TODO : To come... |
|
240 | + break; |
|
241 | + case XOBJ_DTYPE_SOURCE: |
|
242 | + // TODO : To come... |
|
243 | + break; |
|
244 | + case XOBJ_DTYPE_FORM_SECTION: |
|
245 | + $section_control = new SmartFormSection($key, $var['value']); |
|
246 | + $this->addElement($section_control, $key, $var); |
|
247 | + unset($section_control); |
|
248 | + break; |
|
249 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
250 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
251 | + $this->addElement($section_control, $key, $var); |
|
252 | + unset($section_control); |
|
253 | + break; |
|
254 | + } |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + // Add an hidden field to store the URL of the page before this form |
|
259 | + $this->addElement(new XoopsFormHidden('smart_page_before_form', smart_get_page_before_form())); |
|
260 | + } |
|
261 | + |
|
262 | + function createPermissionControls() { |
|
263 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
264 | + |
|
265 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
266 | + |
|
267 | + if ($permissions) { |
|
268 | + $member_handler = &xoops_gethandler('member'); |
|
269 | + $group_list = $member_handler->getGroupList(); |
|
270 | + asort($group_list); |
|
271 | + foreach($permissions as $permission) { |
|
272 | + if ($this->targetObject->isNew()) { |
|
273 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
274 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
275 | + } |
|
276 | + } else { |
|
277 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
278 | + } |
|
279 | + $groups_select = new XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
280 | + $groups_select->setDescription($permission['description']); |
|
281 | + $groups_select->addOptionArray($group_list); |
|
282 | + $this->addElement($groups_select); |
|
283 | + unset($groups_select); |
|
284 | + } |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + function createButtons($form_name, $form_caption, $submit_button_caption = false) { |
|
289 | + |
|
290 | + $button_tray = new XoopsFormElementTray('', ''); |
|
291 | + $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
|
292 | + if(!$submit_button_caption){ |
|
293 | + if ($this->targetObject->isNew()) { |
|
294 | + $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
295 | + } else { |
|
296 | + $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
297 | + } |
|
298 | + } |
|
299 | + else { |
|
300 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption , 'submit'); |
|
301 | + } |
|
302 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
303 | + $button_tray->addElement($butt_create); |
|
304 | + |
|
305 | + //creating custom buttons |
|
306 | + if ($this->_custom_button) { |
|
307 | + foreach($this->_custom_button as $custom_button) { |
|
308 | + $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
309 | + if ($custom_button['onclick']) { |
|
310 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
311 | + } |
|
312 | + $button_tray->addElement($butt_custom); |
|
313 | + unset($butt_custom); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + // creating the "cancel" button |
|
318 | + $butt_cancel = new XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
319 | + if ($this->_cancel_js_action) { |
|
320 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
321 | + } else { |
|
322 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
323 | + } |
|
324 | + $button_tray->addElement($butt_cancel); |
|
325 | + |
|
326 | + $this->addElement($button_tray); |
|
327 | + } |
|
328 | + |
|
329 | + function getControl($controlName, $key) { |
|
330 | + switch ($controlName) { |
|
331 | + case 'check': |
|
332 | + include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformcheckelement.php"); |
|
333 | + $control = $this->targetObject->getControl($key); |
|
334 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
335 | + $controlObj->addOptionArray($control['options']); |
|
336 | + return $controlObj; |
|
337 | + break; |
|
338 | + |
|
339 | + case 'color': |
|
340 | + $control = $this->targetObject->getControl($key); |
|
341 | + $controlObj = new XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
342 | + return $controlObj; |
|
343 | + break; |
|
344 | + |
|
345 | + case 'radio': |
|
346 | + $control = $this->targetObject->getControl($key); |
|
347 | + |
|
348 | + $controlObj = new XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
349 | + $controlObj->addOptionArray($control['options']); |
|
350 | + return $controlObj; |
|
351 | + break; |
|
352 | + |
|
353 | + case 'label': |
|
354 | + return new XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
355 | + break; |
|
356 | + |
|
357 | + case 'textarea' : |
|
358 | + return $this->getTextArea($key); |
|
359 | + |
|
360 | + case 'theme': |
|
361 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
362 | + |
|
363 | + case 'theme_multi': |
|
364 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
365 | + break; |
|
366 | + |
|
367 | + case 'timezone': |
|
368 | + return new XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
369 | + break; |
|
370 | + |
|
371 | + case 'group': |
|
372 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
373 | + break; |
|
374 | + |
|
375 | + case 'group_multi': |
|
376 | + return new XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
377 | + break; |
|
378 | + |
|
379 | + /*case 'user': |
|
380 | 380 | return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
381 | 381 | break;*/ |
382 | 382 | |
383 | - case 'user_multi': |
|
384 | - return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
385 | - break; |
|
386 | - |
|
387 | - case 'password': |
|
388 | - return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
389 | - break; |
|
390 | - |
|
391 | - case 'country': |
|
392 | - return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
393 | - break; |
|
394 | - |
|
395 | - case 'urllink': |
|
396 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformurllinkelement.php"); |
|
397 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
398 | - break; |
|
399 | - |
|
400 | - case 'richfile': |
|
401 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformrichfileelement.php"); |
|
402 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
403 | - break; |
|
404 | - case 'section': |
|
405 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformsection.php"); |
|
406 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
407 | - break; |
|
408 | - |
|
409 | - |
|
410 | - default: |
|
411 | - $classname = "SmartForm".ucfirst($controlName)."Element"; |
|
412 | - if (!class_exists($classname)) { |
|
413 | - if (file_exists(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php")) { |
|
414 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php"); |
|
415 | - } else { |
|
416 | - // perhaps this is a control created by the module |
|
417 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
418 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
419 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . "Element"; |
|
420 | - $classFileName = strtolower($classname).".php"; |
|
421 | - |
|
422 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
423 | - include_once($moduleFormElementsPath . $classFileName); |
|
424 | - } else { |
|
425 | - trigger_error($classname." Not found", E_USER_WARNING); |
|
426 | - return new XoopsFormLabel(); //Empty object |
|
427 | - } |
|
428 | - } |
|
429 | - } |
|
430 | - return new $classname($this->targetObject, $key); |
|
431 | - break; |
|
432 | - } |
|
433 | - } |
|
434 | - |
|
435 | - function getTextArea($key) { |
|
436 | - $var = $this->targetObject->vars[$key]; |
|
437 | - |
|
438 | - // if no control has been created, let's create a default one |
|
439 | - if (!isset($this->targetObject->controls[$key])) { |
|
440 | - $control = array('name' => 'textarea', |
|
383 | + case 'user_multi': |
|
384 | + return new XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
385 | + break; |
|
386 | + |
|
387 | + case 'password': |
|
388 | + return new XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
389 | + break; |
|
390 | + |
|
391 | + case 'country': |
|
392 | + return new XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
393 | + break; |
|
394 | + |
|
395 | + case 'urllink': |
|
396 | + include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformurllinkelement.php"); |
|
397 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
398 | + break; |
|
399 | + |
|
400 | + case 'richfile': |
|
401 | + include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformrichfileelement.php"); |
|
402 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
403 | + break; |
|
404 | + case 'section': |
|
405 | + include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformsection.php"); |
|
406 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
407 | + break; |
|
408 | + |
|
409 | + |
|
410 | + default: |
|
411 | + $classname = "SmartForm".ucfirst($controlName)."Element"; |
|
412 | + if (!class_exists($classname)) { |
|
413 | + if (file_exists(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php")) { |
|
414 | + include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php"); |
|
415 | + } else { |
|
416 | + // perhaps this is a control created by the module |
|
417 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
418 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
419 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . "Element"; |
|
420 | + $classFileName = strtolower($classname).".php"; |
|
421 | + |
|
422 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
423 | + include_once($moduleFormElementsPath . $classFileName); |
|
424 | + } else { |
|
425 | + trigger_error($classname." Not found", E_USER_WARNING); |
|
426 | + return new XoopsFormLabel(); //Empty object |
|
427 | + } |
|
428 | + } |
|
429 | + } |
|
430 | + return new $classname($this->targetObject, $key); |
|
431 | + break; |
|
432 | + } |
|
433 | + } |
|
434 | + |
|
435 | + function getTextArea($key) { |
|
436 | + $var = $this->targetObject->vars[$key]; |
|
437 | + |
|
438 | + // if no control has been created, let's create a default one |
|
439 | + if (!isset($this->targetObject->controls[$key])) { |
|
440 | + $control = array('name' => 'textarea', |
|
441 | 441 | 'itemHandler' => false, |
442 | 442 | 'method' => false, |
443 | 443 | 'module' => false, |
444 | 444 | 'form_editor'=>'default'); |
445 | - } else { |
|
446 | - $control = $this->targetObject->controls[$key]; |
|
447 | - } |
|
448 | - $xoops22 = smart_isXoops22(); |
|
449 | - |
|
450 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
451 | - /** |
|
452 | - * If the editor is 'default', retreive the default editor of this module |
|
453 | - */ |
|
454 | - if ($form_editor == 'default') { |
|
455 | - global $xoopsModuleConfig; |
|
456 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
457 | - } |
|
458 | - |
|
459 | - $caption = $var['form_caption']; |
|
460 | - $name = $key; |
|
461 | - |
|
462 | - $value = $this->targetObject->getVar($key); |
|
463 | - |
|
464 | - $value = $this->targetObject->getValueFor($key, true); |
|
465 | - |
|
466 | - $editor_configs=array(); |
|
467 | - $editor_configs["name"] = $name; |
|
468 | - $editor_configs["value"] = $value; |
|
469 | - if ($form_editor != 'textarea') { |
|
470 | - $editor_configs["rows"] = 35; |
|
471 | - $editor_configs["cols"] = 60; |
|
472 | - } |
|
473 | - |
|
474 | - if (isset($control['rows'])) { |
|
475 | - $editor_configs["rows"] = $control['rows']; |
|
476 | - } |
|
477 | - if (isset($control['cols'])) { |
|
478 | - $editor_configs["cols"] = $control['cols']; |
|
479 | - } |
|
480 | - |
|
481 | - $editor_configs["width"] = "100%"; |
|
482 | - $editor_configs["height"] = "400px"; |
|
483 | - |
|
484 | - $dhtml = true; |
|
485 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
486 | - |
|
487 | - if (file_exists($xoopseditorclass)) { |
|
488 | - include_once($xoopseditorclass); |
|
489 | - $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = "textarea"); |
|
490 | - } else { |
|
491 | - |
|
492 | - switch($form_editor) { |
|
493 | - |
|
494 | - case 'tiny' : |
|
495 | - if (!$xoops22) { |
|
496 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php")) { |
|
497 | - include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php"); |
|
498 | - $editor = new XoopsFormTinyTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
499 | - } else { |
|
500 | - if ($dhtml) { |
|
501 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
502 | - } else { |
|
503 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
504 | - } |
|
505 | - } |
|
506 | - } else { |
|
507 | - $editor = new XoopsFormEditor($caption, "tinyeditor", $editor_configs); |
|
508 | - } |
|
509 | - break; |
|
510 | - |
|
511 | - case 'dhtmltextarea' : |
|
512 | - case 'dhtmltext' : |
|
513 | - $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
514 | - if ($var['form_dsc']) { |
|
515 | - $editor->setDescription($var['form_dsc']); |
|
516 | - } |
|
517 | - break; |
|
518 | - |
|
519 | - case 'fckeditor' : |
|
520 | - if (!$xoops22) { |
|
521 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php")) { |
|
522 | - include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php"); |
|
523 | - $editor = new XoopsFormFckeditor(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
524 | - } else { |
|
525 | - if ($dhtml) { |
|
526 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
527 | - } else { |
|
528 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
529 | - } |
|
530 | - } |
|
531 | - } else { |
|
532 | - $editor = new XoopsFormEditor($caption, "fckeditor", $editor_configs); |
|
533 | - } |
|
534 | - break; |
|
535 | - |
|
536 | - case 'inbetween' : |
|
537 | - if (!$xoops22) { |
|
538 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php")) { |
|
539 | - include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php"); |
|
540 | - $editor = new XoopsFormInbetweenTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
541 | - } else { |
|
542 | - if ($dhtml) { |
|
543 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
544 | - } else { |
|
545 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
546 | - } |
|
547 | - } |
|
548 | - } else { |
|
549 | - $editor = new XoopsFormEditor($caption, "inbetween", $editor_configs); |
|
550 | - } |
|
551 | - break; |
|
552 | - |
|
553 | - case 'koivi' : |
|
554 | - if (!$xoops22) { |
|
555 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) { |
|
556 | - include_once(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php"); |
|
557 | - $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
558 | - } else { |
|
559 | - if ($dhtml) { |
|
560 | - $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
561 | - } else { |
|
562 | - $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
563 | - } |
|
564 | - } |
|
565 | - } else { |
|
566 | - $editor = new XoopsFormEditor($caption, "koivi", $editor_configs); |
|
567 | - } |
|
568 | - break; |
|
569 | - |
|
570 | - case "spaw": |
|
571 | - if(!$xoops22) { |
|
572 | - if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) { |
|
573 | - include_once(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php"); |
|
574 | - $editor = new XoopsFormSpaw($caption, $name, $value); |
|
575 | - } |
|
576 | - } else { |
|
577 | - $editor = new XoopsFormEditor($caption, "spaw", $editor_configs); |
|
578 | - } |
|
579 | - break; |
|
580 | - |
|
581 | - case "htmlarea": |
|
582 | - if(!$xoops22) { |
|
583 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) { |
|
584 | - include_once(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php"); |
|
585 | - $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
586 | - } |
|
587 | - } else { |
|
588 | - $editor = new XoopsFormEditor($caption, "htmlarea", $editor_configs); |
|
589 | - } |
|
590 | - break; |
|
591 | - |
|
592 | - default: |
|
593 | - case 'textarea': |
|
594 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
595 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
596 | - |
|
597 | - $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
598 | - if ($var['form_dsc']) { |
|
599 | - $editor->setDescription($var['form_dsc']); |
|
600 | - } |
|
601 | - break; |
|
602 | - |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - return $editor; |
|
607 | - } |
|
608 | - |
|
609 | - function getThemeSelect($key, $var, $multiple=false) { |
|
610 | - |
|
611 | - $size = $multiple ? 5 : 1; |
|
612 | - $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
613 | - |
|
614 | - $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
615 | - $dirlist = array(); |
|
616 | - while (false !== ($file = readdir($handle))) { |
|
617 | - if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/",$file) && strtolower($file) != 'cvs') { |
|
618 | - $dirlist[$file]=$file; |
|
619 | - } |
|
620 | - } |
|
621 | - closedir($handle); |
|
622 | - if (!empty($dirlist)) { |
|
623 | - asort($dirlist); |
|
624 | - $theme_select->addOptionArray($dirlist); |
|
625 | - } |
|
626 | - |
|
627 | - return $theme_select; |
|
628 | - } |
|
629 | - |
|
630 | - function &getElementById($keyname) { |
|
631 | - foreach ($this->_elements as $eleObj) { |
|
632 | - if ($eleObj->getName() == $keyname) { |
|
633 | - $ret =& $eleObj; |
|
634 | - break; |
|
635 | - } |
|
636 | - } |
|
637 | - return isset($ret) ? $ret : false; |
|
638 | - } |
|
639 | - |
|
640 | - /** |
|
641 | - * create HTML to output the form as a theme-enabled table with validation. |
|
642 | - * |
|
643 | - * @return string |
|
644 | - */ |
|
645 | - function render() |
|
646 | - { |
|
647 | - $required =& $this->getRequired(); |
|
648 | - $ret = " |
|
445 | + } else { |
|
446 | + $control = $this->targetObject->controls[$key]; |
|
447 | + } |
|
448 | + $xoops22 = smart_isXoops22(); |
|
449 | + |
|
450 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
451 | + /** |
|
452 | + * If the editor is 'default', retreive the default editor of this module |
|
453 | + */ |
|
454 | + if ($form_editor == 'default') { |
|
455 | + global $xoopsModuleConfig; |
|
456 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
457 | + } |
|
458 | + |
|
459 | + $caption = $var['form_caption']; |
|
460 | + $name = $key; |
|
461 | + |
|
462 | + $value = $this->targetObject->getVar($key); |
|
463 | + |
|
464 | + $value = $this->targetObject->getValueFor($key, true); |
|
465 | + |
|
466 | + $editor_configs=array(); |
|
467 | + $editor_configs["name"] = $name; |
|
468 | + $editor_configs["value"] = $value; |
|
469 | + if ($form_editor != 'textarea') { |
|
470 | + $editor_configs["rows"] = 35; |
|
471 | + $editor_configs["cols"] = 60; |
|
472 | + } |
|
473 | + |
|
474 | + if (isset($control['rows'])) { |
|
475 | + $editor_configs["rows"] = $control['rows']; |
|
476 | + } |
|
477 | + if (isset($control['cols'])) { |
|
478 | + $editor_configs["cols"] = $control['cols']; |
|
479 | + } |
|
480 | + |
|
481 | + $editor_configs["width"] = "100%"; |
|
482 | + $editor_configs["height"] = "400px"; |
|
483 | + |
|
484 | + $dhtml = true; |
|
485 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
486 | + |
|
487 | + if (file_exists($xoopseditorclass)) { |
|
488 | + include_once($xoopseditorclass); |
|
489 | + $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = "textarea"); |
|
490 | + } else { |
|
491 | + |
|
492 | + switch($form_editor) { |
|
493 | + |
|
494 | + case 'tiny' : |
|
495 | + if (!$xoops22) { |
|
496 | + if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php")) { |
|
497 | + include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php"); |
|
498 | + $editor = new XoopsFormTinyTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
499 | + } else { |
|
500 | + if ($dhtml) { |
|
501 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
502 | + } else { |
|
503 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
504 | + } |
|
505 | + } |
|
506 | + } else { |
|
507 | + $editor = new XoopsFormEditor($caption, "tinyeditor", $editor_configs); |
|
508 | + } |
|
509 | + break; |
|
510 | + |
|
511 | + case 'dhtmltextarea' : |
|
512 | + case 'dhtmltext' : |
|
513 | + $editor = new XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
514 | + if ($var['form_dsc']) { |
|
515 | + $editor->setDescription($var['form_dsc']); |
|
516 | + } |
|
517 | + break; |
|
518 | + |
|
519 | + case 'fckeditor' : |
|
520 | + if (!$xoops22) { |
|
521 | + if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php")) { |
|
522 | + include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php"); |
|
523 | + $editor = new XoopsFormFckeditor(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
524 | + } else { |
|
525 | + if ($dhtml) { |
|
526 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
527 | + } else { |
|
528 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
529 | + } |
|
530 | + } |
|
531 | + } else { |
|
532 | + $editor = new XoopsFormEditor($caption, "fckeditor", $editor_configs); |
|
533 | + } |
|
534 | + break; |
|
535 | + |
|
536 | + case 'inbetween' : |
|
537 | + if (!$xoops22) { |
|
538 | + if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php")) { |
|
539 | + include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php"); |
|
540 | + $editor = new XoopsFormInbetweenTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
541 | + } else { |
|
542 | + if ($dhtml) { |
|
543 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
544 | + } else { |
|
545 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
546 | + } |
|
547 | + } |
|
548 | + } else { |
|
549 | + $editor = new XoopsFormEditor($caption, "inbetween", $editor_configs); |
|
550 | + } |
|
551 | + break; |
|
552 | + |
|
553 | + case 'koivi' : |
|
554 | + if (!$xoops22) { |
|
555 | + if ( is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) { |
|
556 | + include_once(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php"); |
|
557 | + $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
|
558 | + } else { |
|
559 | + if ($dhtml) { |
|
560 | + $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
561 | + } else { |
|
562 | + $editor = new XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
563 | + } |
|
564 | + } |
|
565 | + } else { |
|
566 | + $editor = new XoopsFormEditor($caption, "koivi", $editor_configs); |
|
567 | + } |
|
568 | + break; |
|
569 | + |
|
570 | + case "spaw": |
|
571 | + if(!$xoops22) { |
|
572 | + if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) { |
|
573 | + include_once(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php"); |
|
574 | + $editor = new XoopsFormSpaw($caption, $name, $value); |
|
575 | + } |
|
576 | + } else { |
|
577 | + $editor = new XoopsFormEditor($caption, "spaw", $editor_configs); |
|
578 | + } |
|
579 | + break; |
|
580 | + |
|
581 | + case "htmlarea": |
|
582 | + if(!$xoops22) { |
|
583 | + if ( is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) { |
|
584 | + include_once(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php"); |
|
585 | + $editor = new XoopsFormHtmlarea($caption, $name, $value); |
|
586 | + } |
|
587 | + } else { |
|
588 | + $editor = new XoopsFormEditor($caption, "htmlarea", $editor_configs); |
|
589 | + } |
|
590 | + break; |
|
591 | + |
|
592 | + default: |
|
593 | + case 'textarea': |
|
594 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
595 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
596 | + |
|
597 | + $editor = new XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
598 | + if ($var['form_dsc']) { |
|
599 | + $editor->setDescription($var['form_dsc']); |
|
600 | + } |
|
601 | + break; |
|
602 | + |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + return $editor; |
|
607 | + } |
|
608 | + |
|
609 | + function getThemeSelect($key, $var, $multiple=false) { |
|
610 | + |
|
611 | + $size = $multiple ? 5 : 1; |
|
612 | + $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
613 | + |
|
614 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
615 | + $dirlist = array(); |
|
616 | + while (false !== ($file = readdir($handle))) { |
|
617 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/",$file) && strtolower($file) != 'cvs') { |
|
618 | + $dirlist[$file]=$file; |
|
619 | + } |
|
620 | + } |
|
621 | + closedir($handle); |
|
622 | + if (!empty($dirlist)) { |
|
623 | + asort($dirlist); |
|
624 | + $theme_select->addOptionArray($dirlist); |
|
625 | + } |
|
626 | + |
|
627 | + return $theme_select; |
|
628 | + } |
|
629 | + |
|
630 | + function &getElementById($keyname) { |
|
631 | + foreach ($this->_elements as $eleObj) { |
|
632 | + if ($eleObj->getName() == $keyname) { |
|
633 | + $ret =& $eleObj; |
|
634 | + break; |
|
635 | + } |
|
636 | + } |
|
637 | + return isset($ret) ? $ret : false; |
|
638 | + } |
|
639 | + |
|
640 | + /** |
|
641 | + * create HTML to output the form as a theme-enabled table with validation. |
|
642 | + * |
|
643 | + * @return string |
|
644 | + */ |
|
645 | + function render() |
|
646 | + { |
|
647 | + $required =& $this->getRequired(); |
|
648 | + $ret = " |
|
649 | 649 | <form name='".$this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
650 | 650 | <table width='100%' class='outer' cellspacing='1'> |
651 | 651 | <tr><th colspan='2'>".$this->getTitle()."</th></tr> |
652 | 652 | "; |
653 | - $hidden = ''; |
|
654 | - $class ='even'; |
|
655 | - foreach ( $this->getElements() as $ele ) { |
|
656 | - if (!is_object($ele)) { |
|
657 | - $ret .= $ele; |
|
658 | - } elseif ( !$ele->isHidden() ) { |
|
659 | - //$class = ( $class == 'even' ) ? 'odd' : 'even'; |
|
660 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
661 | - if ($ele->getDescription() != '') { |
|
662 | - $ret .= '<br /><br /><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
663 | - } |
|
664 | - $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
665 | - } else { |
|
666 | - $hidden .= $ele->render(); |
|
667 | - } |
|
668 | - } |
|
669 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
670 | - $ret .= $this->renderValidationJS( true ); |
|
671 | - return $ret; |
|
672 | - } |
|
673 | - |
|
674 | - /** |
|
675 | - * assign to smarty form template instead of displaying directly |
|
676 | - * |
|
677 | - * @param object &$tpl reference to a {@link Smarty} object |
|
678 | - * @see Smarty |
|
679 | - */ |
|
680 | - function assign(&$tpl, $smartyName=false){ |
|
681 | - $i = 0; |
|
682 | - $elements = array(); |
|
683 | - foreach ( $this->getElements() as $ele ) { |
|
684 | - $n = ($ele->getName() != "") ? $ele->getName() : $i; |
|
685 | - $elements[$n]['name'] = $ele->getName(); |
|
686 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
687 | - $elements[$n]['body'] = $ele->render(); |
|
688 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
689 | - $elements[$n]['section'] = strToLower(get_class($ele)) == strToLower('SmartFormSection'); |
|
690 | - $elements[$n]['section_close'] = get_class($ele) == 'SmartFormSectionClose'; |
|
691 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
692 | - if ($ele->getDescription() != '') { |
|
693 | - $elements[$n]['description'] = $ele->getDescription(); |
|
694 | - } |
|
695 | - $i++; |
|
696 | - } |
|
697 | - $js = $this->renderValidationJS(); |
|
698 | - if (!$smartyName) { |
|
699 | - $smartyName = $this->getName(); |
|
700 | - } |
|
701 | - |
|
702 | - $tpl->assign($smartyName, array('title' => $this->getTitle(), 'name' => $this->getName(), 'action' => $this->getAction(), 'method' => $this->getMethod(), 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), 'javascript' => $js, 'elements' => $elements)); |
|
703 | - } |
|
704 | - |
|
705 | - |
|
706 | - function renderValidationJS( $withtags = true ) { |
|
707 | - $js = ""; |
|
708 | - if ( $withtags ) { |
|
709 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
710 | - } |
|
711 | - $myts =& MyTextSanitizer::getInstance(); |
|
712 | - $formname = $this->getName(); |
|
713 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
714 | - // First, output code to check required elements |
|
715 | - $elements = $this->getRequired(); |
|
716 | - foreach ( $elements as $elt ) { |
|
717 | - $eltname = $elt->getName(); |
|
718 | - $eltcaption = trim( $elt->getCaption() ); |
|
719 | - $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption ); |
|
720 | - $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) ); |
|
721 | - if (strtolower(get_class($elt)) == 'xoopsformradio') { |
|
722 | - $js .= "var myOption = -1;"; |
|
723 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
653 | + $hidden = ''; |
|
654 | + $class ='even'; |
|
655 | + foreach ( $this->getElements() as $ele ) { |
|
656 | + if (!is_object($ele)) { |
|
657 | + $ret .= $ele; |
|
658 | + } elseif ( !$ele->isHidden() ) { |
|
659 | + //$class = ( $class == 'even' ) ? 'odd' : 'even'; |
|
660 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
661 | + if ($ele->getDescription() != '') { |
|
662 | + $ret .= '<br /><br /><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
663 | + } |
|
664 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
665 | + } else { |
|
666 | + $hidden .= $ele->render(); |
|
667 | + } |
|
668 | + } |
|
669 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
670 | + $ret .= $this->renderValidationJS( true ); |
|
671 | + return $ret; |
|
672 | + } |
|
673 | + |
|
674 | + /** |
|
675 | + * assign to smarty form template instead of displaying directly |
|
676 | + * |
|
677 | + * @param object &$tpl reference to a {@link Smarty} object |
|
678 | + * @see Smarty |
|
679 | + */ |
|
680 | + function assign(&$tpl, $smartyName=false){ |
|
681 | + $i = 0; |
|
682 | + $elements = array(); |
|
683 | + foreach ( $this->getElements() as $ele ) { |
|
684 | + $n = ($ele->getName() != "") ? $ele->getName() : $i; |
|
685 | + $elements[$n]['name'] = $ele->getName(); |
|
686 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
687 | + $elements[$n]['body'] = $ele->render(); |
|
688 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
689 | + $elements[$n]['section'] = strToLower(get_class($ele)) == strToLower('SmartFormSection'); |
|
690 | + $elements[$n]['section_close'] = get_class($ele) == 'SmartFormSectionClose'; |
|
691 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
692 | + if ($ele->getDescription() != '') { |
|
693 | + $elements[$n]['description'] = $ele->getDescription(); |
|
694 | + } |
|
695 | + $i++; |
|
696 | + } |
|
697 | + $js = $this->renderValidationJS(); |
|
698 | + if (!$smartyName) { |
|
699 | + $smartyName = $this->getName(); |
|
700 | + } |
|
701 | + |
|
702 | + $tpl->assign($smartyName, array('title' => $this->getTitle(), 'name' => $this->getName(), 'action' => $this->getAction(), 'method' => $this->getMethod(), 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), 'javascript' => $js, 'elements' => $elements)); |
|
703 | + } |
|
704 | + |
|
705 | + |
|
706 | + function renderValidationJS( $withtags = true ) { |
|
707 | + $js = ""; |
|
708 | + if ( $withtags ) { |
|
709 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
710 | + } |
|
711 | + $myts =& MyTextSanitizer::getInstance(); |
|
712 | + $formname = $this->getName(); |
|
713 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
714 | + // First, output code to check required elements |
|
715 | + $elements = $this->getRequired(); |
|
716 | + foreach ( $elements as $elt ) { |
|
717 | + $eltname = $elt->getName(); |
|
718 | + $eltcaption = trim( $elt->getCaption() ); |
|
719 | + $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption ); |
|
720 | + $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) ); |
|
721 | + if (strtolower(get_class($elt)) == 'xoopsformradio') { |
|
722 | + $js .= "var myOption = -1;"; |
|
723 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
724 | 724 | if (myform.{$eltname}[i].checked) { |
725 | 725 | myOption = i; i = -1; |
726 | 726 | } |
@@ -728,9 +728,9 @@ discard block |
||
728 | 728 | if (myOption == -1) { |
729 | 729 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
730 | 730 | |
731 | - }elseif (strtolower(get_class($elt)) == 'smartformselect_multielement') { |
|
732 | - $js .= "var hasSelections = false;"; |
|
733 | - $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
|
731 | + }elseif (strtolower(get_class($elt)) == 'smartformselect_multielement') { |
|
732 | + $js .= "var hasSelections = false;"; |
|
733 | + $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
|
734 | 734 | if (myform['{$eltname}[]'].options[i].selected) { |
735 | 735 | hasSelections = true; |
736 | 736 | } |
@@ -739,11 +739,11 @@ discard block |
||
739 | 739 | if (hasSelections == false) { |
740 | 740 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
741 | 741 | |
742 | - }elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement' ) { |
|
743 | - $js .= "var hasSelections = false;"; |
|
744 | - //sometimes, there is an implicit '[]', sometimes not |
|
745 | - if(strpos($eltname, '[') === false){ |
|
746 | - $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
|
742 | + }elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement' ) { |
|
743 | + $js .= "var hasSelections = false;"; |
|
744 | + //sometimes, there is an implicit '[]', sometimes not |
|
745 | + if(strpos($eltname, '[') === false){ |
|
746 | + $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
|
747 | 747 | if (myform['{$eltname}[]'][i].checked) { |
748 | 748 | hasSelections = true; |
749 | 749 | } |
@@ -751,8 +751,8 @@ discard block |
||
751 | 751 | } |
752 | 752 | if (hasSelections == false) { |
753 | 753 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
754 | - }else{ |
|
755 | - $js .= "for(var i = 0; i < myform['{$eltname}'].length; i++){ |
|
754 | + }else{ |
|
755 | + $js .= "for(var i = 0; i < myform['{$eltname}'].length; i++){ |
|
756 | 756 | if (myform['{$eltname}'][i].checked) { |
757 | 757 | hasSelections = true; |
758 | 758 | } |
@@ -760,27 +760,27 @@ discard block |
||
760 | 760 | } |
761 | 761 | if (hasSelections == false) { |
762 | 762 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
763 | - } |
|
764 | - |
|
765 | - }else{ |
|
766 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " |
|
767 | - . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
768 | - } |
|
769 | - } |
|
770 | - // Now, handle custom validation code |
|
771 | - $elements = $this->getElements( true ); |
|
772 | - foreach ( $elements as $elt ) { |
|
773 | - if ( method_exists( $elt, 'renderValidationJS') && strtolower(get_class($elt)) != 'xoopsformcheckbox') { |
|
774 | - if ( $eltjs = $elt->renderValidationJS() ) { |
|
775 | - $js .= $eltjs . "\n"; |
|
776 | - } |
|
777 | - } |
|
778 | - } |
|
779 | - $js .= "return true;\n}\n"; |
|
780 | - if ( $withtags ) { |
|
781 | - $js .= "//--></script>\n<!-- End Form Vaidation JavaScript //-->\n"; |
|
782 | - } |
|
783 | - return $js; |
|
784 | - } |
|
763 | + } |
|
764 | + |
|
765 | + }else{ |
|
766 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " |
|
767 | + . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
768 | + } |
|
769 | + } |
|
770 | + // Now, handle custom validation code |
|
771 | + $elements = $this->getElements( true ); |
|
772 | + foreach ( $elements as $elt ) { |
|
773 | + if ( method_exists( $elt, 'renderValidationJS') && strtolower(get_class($elt)) != 'xoopsformcheckbox') { |
|
774 | + if ( $eltjs = $elt->renderValidationJS() ) { |
|
775 | + $js .= $eltjs . "\n"; |
|
776 | + } |
|
777 | + } |
|
778 | + } |
|
779 | + $js .= "return true;\n}\n"; |
|
780 | + if ( $withtags ) { |
|
781 | + $js .= "//--></script>\n<!-- End Form Vaidation JavaScript //-->\n"; |
|
782 | + } |
|
783 | + return $js; |
|
784 | + } |
|
785 | 785 | } |
786 | 786 | ?> |
787 | 787 | \ No newline at end of file |
@@ -35,28 +35,28 @@ discard block |
||
35 | 35 | |
36 | 36 | var $targetObject = null; |
37 | 37 | var $form_fields = null; |
38 | - var $_cancel_js_action=false; |
|
39 | - var $_custom_button=false; |
|
40 | - var $_captcha=false; |
|
41 | - var $_form_name=false; |
|
42 | - var $_form_caption=false; |
|
43 | - var $_submit_button_caption=false; |
|
38 | + var $_cancel_js_action = false; |
|
39 | + var $_custom_button = false; |
|
40 | + var $_captcha = false; |
|
41 | + var $_form_name = false; |
|
42 | + var $_form_caption = false; |
|
43 | + var $_submit_button_caption = false; |
|
44 | 44 | |
45 | - function SmartobjectForm(&$target, $form_name, $form_caption, $form_action, $form_fields=null, $submit_button_caption = false, $cancel_js_action=false, $captcha=false) { |
|
45 | + function SmartobjectForm(&$target, $form_name, $form_caption, $form_action, $form_fields = null, $submit_button_caption = false, $cancel_js_action = false, $captcha = false) { |
|
46 | 46 | |
47 | - $this->targetObject =& $target; |
|
47 | + $this->targetObject = & $target; |
|
48 | 48 | $this->form_fields = $form_fields; |
49 | 49 | $this->_cancel_js_action = $cancel_js_action; |
50 | - $this->_captcha= $captcha; |
|
51 | - $this->_form_name= $form_name; |
|
52 | - $this->_form_caption= $form_caption; |
|
53 | - $this->_submit_button_caption= $submit_button_caption; |
|
50 | + $this->_captcha = $captcha; |
|
51 | + $this->_form_name = $form_name; |
|
52 | + $this->_form_caption = $form_caption; |
|
53 | + $this->_submit_button_caption = $submit_button_caption; |
|
54 | 54 | |
55 | 55 | if (!isset($form_action)) { |
56 | 56 | $form_action = xoops_getenv('PHP_SELF'); |
57 | 57 | } |
58 | 58 | |
59 | - $this->XoopsForm( $form_caption, $form_name, $form_action); |
|
59 | + $this->XoopsForm($form_caption, $form_name, $form_action); |
|
60 | 60 | $this->setExtra('enctype="multipart/form-data"'); |
61 | 61 | |
62 | 62 | $this->createElements(); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->addElement(new XoopsFormCaptcha(), true); |
76 | 76 | } |
77 | 77 | |
78 | - function addCustomButton($name, $caption, $onclick=false) { |
|
78 | + function addCustomButton($name, $caption, $onclick = false) { |
|
79 | 79 | $custom_button_array = array( |
80 | 80 | 'name' => $name, |
81 | 81 | 'caption' => $caption, |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param object &$formElement reference to a {@link XoopsFormElement} |
91 | 91 | * @param bool $required is this a "required" element? |
92 | 92 | */ |
93 | - function addElement(&$formElement, $key=false, $var=false, $required='notset'){ |
|
93 | + function addElement(&$formElement, $key = false, $var = false, $required = 'notset') { |
|
94 | 94 | if ($key) { |
95 | 95 | if ($this->targetObject->vars[$key]['readonly']) { |
96 | 96 | $formElement->setExtra('disabled="disabled"'); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | } |
113 | 113 | } |
114 | 114 | $controls = $this->targetObject->controls; |
115 | - if(isset($controls[$key]['js'])){ |
|
115 | + if (isset($controls[$key]['js'])) { |
|
116 | 116 | $formElement->customValidationCode[] = $controls[$key]['js']; |
117 | 117 | } |
118 | 118 | parent::AddElement($formElement, $required == 'notset' ? $var['required'] : $required); |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | $member_handler = &xoops_gethandler('member'); |
269 | 269 | $group_list = $member_handler->getGroupList(); |
270 | 270 | asort($group_list); |
271 | - foreach($permissions as $permission) { |
|
271 | + foreach ($permissions as $permission) { |
|
272 | 272 | if ($this->targetObject->isNew()) { |
273 | 273 | if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
274 | 274 | $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | |
290 | 290 | $button_tray = new XoopsFormElementTray('', ''); |
291 | 291 | $button_tray->addElement(new XoopsFormHidden('op', $form_name)); |
292 | - if(!$submit_button_caption){ |
|
292 | + if (!$submit_button_caption) { |
|
293 | 293 | if ($this->targetObject->isNew()) { |
294 | 294 | $butt_create = new XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
295 | 295 | } else { |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | } |
298 | 298 | } |
299 | 299 | else { |
300 | - $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption , 'submit'); |
|
300 | + $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
301 | 301 | } |
302 | 302 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
303 | 303 | $button_tray->addElement($butt_create); |
304 | 304 | |
305 | 305 | //creating custom buttons |
306 | 306 | if ($this->_custom_button) { |
307 | - foreach($this->_custom_button as $custom_button) { |
|
307 | + foreach ($this->_custom_button as $custom_button) { |
|
308 | 308 | $butt_custom = new XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
309 | 309 | if ($custom_button['onclick']) { |
310 | 310 | $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | function getControl($controlName, $key) { |
330 | 330 | switch ($controlName) { |
331 | 331 | case 'check': |
332 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformcheckelement.php"); |
|
332 | + include_once(SMARTOBJECT_ROOT_PATH . "class/form/elements/smartformcheckelement.php"); |
|
333 | 333 | $control = $this->targetObject->getControl($key); |
334 | 334 | $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
335 | 335 | $controlObj->addOptionArray($control['options']); |
@@ -393,36 +393,36 @@ discard block |
||
393 | 393 | break; |
394 | 394 | |
395 | 395 | case 'urllink': |
396 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformurllinkelement.php"); |
|
396 | + include_once(SMARTOBJECT_ROOT_PATH . "class/form/elements/smartformurllinkelement.php"); |
|
397 | 397 | return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
398 | 398 | break; |
399 | 399 | |
400 | 400 | case 'richfile': |
401 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformrichfileelement.php"); |
|
401 | + include_once(SMARTOBJECT_ROOT_PATH . "class/form/elements/smartformrichfileelement.php"); |
|
402 | 402 | return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
403 | 403 | break; |
404 | 404 | case 'section': |
405 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/smartformsection.php"); |
|
405 | + include_once(SMARTOBJECT_ROOT_PATH . "class/form/elements/smartformsection.php"); |
|
406 | 406 | return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
407 | 407 | break; |
408 | 408 | |
409 | 409 | |
410 | 410 | default: |
411 | - $classname = "SmartForm".ucfirst($controlName)."Element"; |
|
411 | + $classname = "SmartForm" . ucfirst($controlName) . "Element"; |
|
412 | 412 | if (!class_exists($classname)) { |
413 | - if (file_exists(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php")) { |
|
414 | - include_once(SMARTOBJECT_ROOT_PATH."class/form/elements/".strtolower($classname).".php"); |
|
413 | + if (file_exists(SMARTOBJECT_ROOT_PATH . "class/form/elements/" . strtolower($classname) . ".php")) { |
|
414 | + include_once(SMARTOBJECT_ROOT_PATH . "class/form/elements/" . strtolower($classname) . ".php"); |
|
415 | 415 | } else { |
416 | 416 | // perhaps this is a control created by the module |
417 | 417 | $moduleName = $this->targetObject->handler->_moduleName; |
418 | 418 | $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
419 | 419 | $classname = ucfirst($moduleName) . ucfirst($controlName) . "Element"; |
420 | - $classFileName = strtolower($classname).".php"; |
|
420 | + $classFileName = strtolower($classname) . ".php"; |
|
421 | 421 | |
422 | 422 | if (file_exists($moduleFormElementsPath . $classFileName)) { |
423 | 423 | include_once($moduleFormElementsPath . $classFileName); |
424 | 424 | } else { |
425 | - trigger_error($classname." Not found", E_USER_WARNING); |
|
425 | + trigger_error($classname . " Not found", E_USER_WARNING); |
|
426 | 426 | return new XoopsFormLabel(); //Empty object |
427 | 427 | } |
428 | 428 | } |
@@ -463,7 +463,7 @@ discard block |
||
463 | 463 | |
464 | 464 | $value = $this->targetObject->getValueFor($key, true); |
465 | 465 | |
466 | - $editor_configs=array(); |
|
466 | + $editor_configs = array(); |
|
467 | 467 | $editor_configs["name"] = $name; |
468 | 468 | $editor_configs["value"] = $value; |
469 | 469 | if ($form_editor != 'textarea') { |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | $editor = new XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = "textarea"); |
490 | 490 | } else { |
491 | 491 | |
492 | - switch($form_editor) { |
|
492 | + switch ($form_editor) { |
|
493 | 493 | |
494 | 494 | case 'tiny' : |
495 | 495 | if (!$xoops22) { |
496 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php")) { |
|
496 | + if (is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php")) { |
|
497 | 497 | include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/tinyeditor/formtinytextarea.php"); |
498 | - $editor = new XoopsFormTinyTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
498 | + $editor = new XoopsFormTinyTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'), true); |
|
499 | 499 | } else { |
500 | 500 | if ($dhtml) { |
501 | 501 | $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
@@ -518,9 +518,9 @@ discard block |
||
518 | 518 | |
519 | 519 | case 'fckeditor' : |
520 | 520 | if (!$xoops22) { |
521 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php")) { |
|
521 | + if (is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php")) { |
|
522 | 522 | include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/fckeditor/formfckeditor.php"); |
523 | - $editor = new XoopsFormFckeditor(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
523 | + $editor = new XoopsFormFckeditor(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'), true); |
|
524 | 524 | } else { |
525 | 525 | if ($dhtml) { |
526 | 526 | $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
@@ -535,9 +535,9 @@ discard block |
||
535 | 535 | |
536 | 536 | case 'inbetween' : |
537 | 537 | if (!$xoops22) { |
538 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php")) { |
|
538 | + if (is_readable(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php")) { |
|
539 | 539 | include_once(XOOPS_ROOT_PATH . "/class/xoopseditor/inbetween/forminbetweentextarea.php"); |
540 | - $editor = new XoopsFormInbetweenTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'),true); |
|
540 | + $editor = new XoopsFormInbetweenTextArea(array('caption'=> $caption, 'name'=>$name, 'value'=>$value, 'width'=>'100%', 'height'=>'300px'), true); |
|
541 | 541 | } else { |
542 | 542 | if ($dhtml) { |
543 | 543 | $editor = new XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | |
553 | 553 | case 'koivi' : |
554 | 554 | if (!$xoops22) { |
555 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) { |
|
555 | + if (is_readable(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php")) { |
|
556 | 556 | include_once(XOOPS_ROOT_PATH . "/class/wysiwyg/formwysiwygtextarea.php"); |
557 | 557 | $editor = new XoopsFormWysiwygTextArea($caption, $name, $value, '100%', '400px'); |
558 | 558 | } else { |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | break; |
569 | 569 | |
570 | 570 | case "spaw": |
571 | - if(!$xoops22) { |
|
572 | - if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) { |
|
571 | + if (!$xoops22) { |
|
572 | + if (is_readable(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php")) { |
|
573 | 573 | include_once(XOOPS_ROOT_PATH . "/class/spaw/formspaw.php"); |
574 | 574 | $editor = new XoopsFormSpaw($caption, $name, $value); |
575 | 575 | } |
@@ -579,8 +579,8 @@ discard block |
||
579 | 579 | break; |
580 | 580 | |
581 | 581 | case "htmlarea": |
582 | - if(!$xoops22) { |
|
583 | - if ( is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) { |
|
582 | + if (!$xoops22) { |
|
583 | + if (is_readable(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php")) { |
|
584 | 584 | include_once(XOOPS_ROOT_PATH . "/class/htmlarea/formhtmlarea.php"); |
585 | 585 | $editor = new XoopsFormHtmlarea($caption, $name, $value); |
586 | 586 | } |
@@ -606,16 +606,16 @@ discard block |
||
606 | 606 | return $editor; |
607 | 607 | } |
608 | 608 | |
609 | - function getThemeSelect($key, $var, $multiple=false) { |
|
609 | + function getThemeSelect($key, $var, $multiple = false) { |
|
610 | 610 | |
611 | 611 | $size = $multiple ? 5 : 1; |
612 | 612 | $theme_select = new XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
613 | 613 | |
614 | - $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
614 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
615 | 615 | $dirlist = array(); |
616 | 616 | while (false !== ($file = readdir($handle))) { |
617 | - if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match("/^[.]{1,2}$/",$file) && strtolower($file) != 'cvs') { |
|
618 | - $dirlist[$file]=$file; |
|
617 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match("/^[.]{1,2}$/", $file) && strtolower($file) != 'cvs') { |
|
618 | + $dirlist[$file] = $file; |
|
619 | 619 | } |
620 | 620 | } |
621 | 621 | closedir($handle); |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | function &getElementById($keyname) { |
631 | 631 | foreach ($this->_elements as $eleObj) { |
632 | 632 | if ($eleObj->getName() == $keyname) { |
633 | - $ret =& $eleObj; |
|
633 | + $ret = & $eleObj; |
|
634 | 634 | break; |
635 | 635 | } |
636 | 636 | } |
@@ -644,30 +644,30 @@ discard block |
||
644 | 644 | */ |
645 | 645 | function render() |
646 | 646 | { |
647 | - $required =& $this->getRequired(); |
|
647 | + $required = & $this->getRequired(); |
|
648 | 648 | $ret = " |
649 | - <form name='".$this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
649 | + <form name='".$this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
650 | 650 | <table width='100%' class='outer' cellspacing='1'> |
651 | - <tr><th colspan='2'>".$this->getTitle()."</th></tr> |
|
651 | + <tr><th colspan='2'>".$this->getTitle() . "</th></tr> |
|
652 | 652 | "; |
653 | 653 | $hidden = ''; |
654 | - $class ='even'; |
|
655 | - foreach ( $this->getElements() as $ele ) { |
|
654 | + $class = 'even'; |
|
655 | + foreach ($this->getElements() as $ele) { |
|
656 | 656 | if (!is_object($ele)) { |
657 | 657 | $ret .= $ele; |
658 | - } elseif ( !$ele->isHidden() ) { |
|
658 | + } elseif (!$ele->isHidden()) { |
|
659 | 659 | //$class = ( $class == 'even' ) ? 'odd' : 'even'; |
660 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
660 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
661 | 661 | if ($ele->getDescription() != '') { |
662 | - $ret .= '<br /><br /><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
662 | + $ret .= '<br /><br /><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
663 | 663 | } |
664 | - $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
664 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
665 | 665 | } else { |
666 | 666 | $hidden .= $ele->render(); |
667 | 667 | } |
668 | 668 | } |
669 | 669 | $ret .= "</table>\n$hidden\n</form>\n"; |
670 | - $ret .= $this->renderValidationJS( true ); |
|
670 | + $ret .= $this->renderValidationJS(true); |
|
671 | 671 | return $ret; |
672 | 672 | } |
673 | 673 | |
@@ -677,20 +677,20 @@ discard block |
||
677 | 677 | * @param object &$tpl reference to a {@link Smarty} object |
678 | 678 | * @see Smarty |
679 | 679 | */ |
680 | - function assign(&$tpl, $smartyName=false){ |
|
680 | + function assign(&$tpl, $smartyName = false) { |
|
681 | 681 | $i = 0; |
682 | 682 | $elements = array(); |
683 | - foreach ( $this->getElements() as $ele ) { |
|
683 | + foreach ($this->getElements() as $ele) { |
|
684 | 684 | $n = ($ele->getName() != "") ? $ele->getName() : $i; |
685 | 685 | $elements[$n]['name'] = $ele->getName(); |
686 | 686 | $elements[$n]['caption'] = $ele->getCaption(); |
687 | 687 | $elements[$n]['body'] = $ele->render(); |
688 | 688 | $elements[$n]['hidden'] = $ele->isHidden(); |
689 | 689 | $elements[$n]['section'] = strToLower(get_class($ele)) == strToLower('SmartFormSection'); |
690 | - $elements[$n]['section_close'] = get_class($ele) == 'SmartFormSectionClose'; |
|
690 | + $elements[$n]['section_close'] = get_class($ele) == 'SmartFormSectionClose'; |
|
691 | 691 | $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
692 | 692 | if ($ele->getDescription() != '') { |
693 | - $elements[$n]['description'] = $ele->getDescription(); |
|
693 | + $elements[$n]['description'] = $ele->getDescription(); |
|
694 | 694 | } |
695 | 695 | $i++; |
696 | 696 | } |
@@ -699,25 +699,25 @@ discard block |
||
699 | 699 | $smartyName = $this->getName(); |
700 | 700 | } |
701 | 701 | |
702 | - $tpl->assign($smartyName, array('title' => $this->getTitle(), 'name' => $this->getName(), 'action' => $this->getAction(), 'method' => $this->getMethod(), 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), 'javascript' => $js, 'elements' => $elements)); |
|
702 | + $tpl->assign($smartyName, array('title' => $this->getTitle(), 'name' => $this->getName(), 'action' => $this->getAction(), 'method' => $this->getMethod(), 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), 'javascript' => $js, 'elements' => $elements)); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | |
706 | - function renderValidationJS( $withtags = true ) { |
|
706 | + function renderValidationJS($withtags = true) { |
|
707 | 707 | $js = ""; |
708 | - if ( $withtags ) { |
|
708 | + if ($withtags) { |
|
709 | 709 | $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
710 | 710 | } |
711 | - $myts =& MyTextSanitizer::getInstance(); |
|
711 | + $myts = & MyTextSanitizer::getInstance(); |
|
712 | 712 | $formname = $this->getName(); |
713 | 713 | $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
714 | 714 | // First, output code to check required elements |
715 | 715 | $elements = $this->getRequired(); |
716 | - foreach ( $elements as $elt ) { |
|
716 | + foreach ($elements as $elt) { |
|
717 | 717 | $eltname = $elt->getName(); |
718 | - $eltcaption = trim( $elt->getCaption() ); |
|
719 | - $eltmsg = empty($eltcaption) ? sprintf( _FORM_ENTER, $eltname ) : sprintf( _FORM_ENTER, $eltcaption ); |
|
720 | - $eltmsg = str_replace('"', '\"', stripslashes( $eltmsg ) ); |
|
718 | + $eltcaption = trim($elt->getCaption()); |
|
719 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
720 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
721 | 721 | if (strtolower(get_class($elt)) == 'xoopsformradio') { |
722 | 722 | $js .= "var myOption = -1;"; |
723 | 723 | $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
@@ -739,10 +739,10 @@ discard block |
||
739 | 739 | if (hasSelections == false) { |
740 | 740 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
741 | 741 | |
742 | - }elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement' ) { |
|
742 | + }elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement') { |
|
743 | 743 | $js .= "var hasSelections = false;"; |
744 | 744 | //sometimes, there is an implicit '[]', sometimes not |
745 | - if(strpos($eltname, '[') === false){ |
|
745 | + if (strpos($eltname, '[') === false) { |
|
746 | 746 | $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
747 | 747 | if (myform['{$eltname}[]'][i].checked) { |
748 | 748 | hasSelections = true; |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | } |
752 | 752 | if (hasSelections == false) { |
753 | 753 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
754 | - }else{ |
|
754 | + } else { |
|
755 | 755 | $js .= "for(var i = 0; i < myform['{$eltname}'].length; i++){ |
756 | 756 | if (myform['{$eltname}'][i].checked) { |
757 | 757 | hasSelections = true; |
@@ -762,22 +762,22 @@ discard block |
||
762 | 762 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
763 | 763 | } |
764 | 764 | |
765 | - }else{ |
|
765 | + } else { |
|
766 | 766 | $js .= "if ( myform.{$eltname}.value == \"\" ) " |
767 | 767 | . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
768 | 768 | } |
769 | 769 | } |
770 | 770 | // Now, handle custom validation code |
771 | - $elements = $this->getElements( true ); |
|
772 | - foreach ( $elements as $elt ) { |
|
773 | - if ( method_exists( $elt, 'renderValidationJS') && strtolower(get_class($elt)) != 'xoopsformcheckbox') { |
|
774 | - if ( $eltjs = $elt->renderValidationJS() ) { |
|
771 | + $elements = $this->getElements(true); |
|
772 | + foreach ($elements as $elt) { |
|
773 | + if (method_exists($elt, 'renderValidationJS') && strtolower(get_class($elt)) != 'xoopsformcheckbox') { |
|
774 | + if ($eltjs = $elt->renderValidationJS()) { |
|
775 | 775 | $js .= $eltjs . "\n"; |
776 | 776 | } |
777 | 777 | } |
778 | 778 | } |
779 | 779 | $js .= "return true;\n}\n"; |
780 | - if ( $withtags ) { |
|
780 | + if ($withtags) { |
|
781 | 781 | $js .= "//--></script>\n<!-- End Form Vaidation JavaScript //-->\n"; |
782 | 782 | } |
783 | 783 | return $js; |
@@ -295,8 +295,7 @@ discard block |
||
295 | 295 | } else { |
296 | 296 | $butt_create = new XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
297 | 297 | } |
298 | - } |
|
299 | - else { |
|
298 | + } else { |
|
300 | 299 | $butt_create = new XoopsFormButton('', 'modify_button', $submit_button_caption , 'submit'); |
301 | 300 | } |
302 | 301 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
@@ -728,7 +727,7 @@ discard block |
||
728 | 727 | if (myOption == -1) { |
729 | 728 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
730 | 729 | |
731 | - }elseif (strtolower(get_class($elt)) == 'smartformselect_multielement') { |
|
730 | + } elseif (strtolower(get_class($elt)) == 'smartformselect_multielement') { |
|
732 | 731 | $js .= "var hasSelections = false;"; |
733 | 732 | $js .= "for(var i = 0; i < myform['{$eltname}[]'].length; i++){ |
734 | 733 | if (myform['{$eltname}[]'].options[i].selected) { |
@@ -739,7 +738,7 @@ discard block |
||
739 | 738 | if (hasSelections == false) { |
740 | 739 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
741 | 740 | |
742 | - }elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement' ) { |
|
741 | + } elseif (strtolower(get_class($elt)) == 'xoopsformcheckbox' || strtolower(get_class($elt)) == 'smartformcheckelement' ) { |
|
743 | 742 | $js .= "var hasSelections = false;"; |
744 | 743 | //sometimes, there is an implicit '[]', sometimes not |
745 | 744 | if(strpos($eltname, '[') === false){ |
@@ -751,7 +750,7 @@ discard block |
||
751 | 750 | } |
752 | 751 | if (hasSelections == false) { |
753 | 752 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
754 | - }else{ |
|
753 | + } else{ |
|
755 | 754 | $js .= "for(var i = 0; i < myform['{$eltname}'].length; i++){ |
756 | 755 | if (myform['{$eltname}'][i].checked) { |
757 | 756 | hasSelections = true; |
@@ -762,7 +761,7 @@ discard block |
||
762 | 761 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
763 | 762 | } |
764 | 763 | |
765 | - }else{ |
|
764 | + } else{ |
|
766 | 765 | $js .= "if ( myform.{$eltname}.value == \"\" ) " |
767 | 766 | . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
768 | 767 | } |
@@ -65,6 +65,9 @@ |
||
65 | 65 | 'method' => 'getRateList')); |
66 | 66 | } |
67 | 67 | |
68 | + /** |
|
69 | + * @param string $key |
|
70 | + */ |
|
68 | 71 | function getVar($key, $format = 's') { |
69 | 72 | if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
70 | 73 | return call_user_func(array($this,$key)); |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | // -------------------------------------------------------------------------// |
29 | 29 | |
30 | 30 | if (!defined("XOOPS_ROOT_PATH")) { |
31 | - die("XOOPS root path not defined"); |
|
31 | + die("XOOPS root path not defined"); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | var $_modulePlugin=false; |
40 | 40 | |
41 | - function SmartobjectRating() { |
|
42 | - $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
41 | + function SmartobjectRating() { |
|
42 | + $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
|
43 | 43 | $this->quickInitVar('dirname', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_DIRNAME); |
44 | 44 | $this->quickInitVar('item', XOBJ_DTYPE_TXTBOX, true, _CO_SOBJECT_RATING_ITEM); |
45 | 45 | $this->quickInitVar('itemid', XOBJ_DTYPE_INT, true, _CO_SOBJECT_RATING_ITEMID); |
@@ -49,47 +49,47 @@ discard block |
||
49 | 49 | |
50 | 50 | $this->initNonPersistableVar('name', XOBJ_DTYPE_TXTBOX, 'user', _CO_SOBJECT_RATING_NAME); |
51 | 51 | |
52 | - $this->setControl('dirname', array( |
|
53 | - 'handler' => 'rating', |
|
54 | - 'method' => 'getModuleList', |
|
52 | + $this->setControl('dirname', array( |
|
53 | + 'handler' => 'rating', |
|
54 | + 'method' => 'getModuleList', |
|
55 | 55 | 'onSelect' => 'submit')); |
56 | 56 | |
57 | - $this->setControl('item', array( |
|
58 | - 'object' => &$this, |
|
59 | - 'method' => 'getItemList')); |
|
57 | + $this->setControl('item', array( |
|
58 | + 'object' => &$this, |
|
59 | + 'method' => 'getItemList')); |
|
60 | 60 | |
61 | - $this->setControl('uid', 'user'); |
|
61 | + $this->setControl('uid', 'user'); |
|
62 | 62 | |
63 | - $this->setControl('rate', array( |
|
64 | - 'handler' => 'rating', |
|
65 | - 'method' => 'getRateList')); |
|
66 | - } |
|
63 | + $this->setControl('rate', array( |
|
64 | + 'handler' => 'rating', |
|
65 | + 'method' => 'getRateList')); |
|
66 | + } |
|
67 | 67 | |
68 | - function getVar($key, $format = 's') { |
|
69 | - if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
|
70 | - return call_user_func(array($this,$key)); |
|
71 | - } |
|
72 | - return parent::getVar($key, $format); |
|
73 | - } |
|
68 | + function getVar($key, $format = 's') { |
|
69 | + if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
|
70 | + return call_user_func(array($this,$key)); |
|
71 | + } |
|
72 | + return parent::getVar($key, $format); |
|
73 | + } |
|
74 | 74 | |
75 | - function name() { |
|
76 | - $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
75 | + function name() { |
|
76 | + $ret = smart_getLinkedUnameFromId($this->getVar('uid', 'e'), true, array()); |
|
77 | 77 | |
78 | - return $ret; |
|
79 | - } |
|
78 | + return $ret; |
|
79 | + } |
|
80 | 80 | |
81 | - function dirname() { |
|
82 | - global $smartobject_rating_handler; |
|
83 | - $moduleArray = $smartobject_rating_handler->getModuleList(); |
|
84 | - return $moduleArray[$this->getVar('dirname', 'n')]; |
|
85 | - } |
|
81 | + function dirname() { |
|
82 | + global $smartobject_rating_handler; |
|
83 | + $moduleArray = $smartobject_rating_handler->getModuleList(); |
|
84 | + return $moduleArray[$this->getVar('dirname', 'n')]; |
|
85 | + } |
|
86 | 86 | |
87 | - function getItemList() { |
|
88 | - $plugin = $this->getModulePlugin(); |
|
89 | - return $plugin->getItemList(); |
|
90 | - } |
|
87 | + function getItemList() { |
|
88 | + $plugin = $this->getModulePlugin(); |
|
89 | + return $plugin->getItemList(); |
|
90 | + } |
|
91 | 91 | |
92 | - function getItemValue() { |
|
92 | + function getItemValue() { |
|
93 | 93 | $moduleUrl = XOOPS_URL . '/modules/' . $this->getVar('dirname', 'n') . '/'; |
94 | 94 | $plugin = $this->getModulePlugin(); |
95 | 95 | $pluginItemInfo = $plugin->getItemInfo($this->getVar('item')); |
@@ -99,19 +99,19 @@ discard block |
||
99 | 99 | $itemPath = sprintf($pluginItemInfo['url'], $this->getVar('itemid')); |
100 | 100 | $ret = '<a href="' . $moduleUrl . $itemPath . '">' . $pluginItemInfo['caption'] . '</a>'; |
101 | 101 | return $ret; |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - function getRateValue() { |
|
105 | - return $this->getVar('rate'); |
|
106 | - } |
|
104 | + function getRateValue() { |
|
105 | + return $this->getVar('rate'); |
|
106 | + } |
|
107 | 107 | |
108 | - function getModulePlugin() { |
|
108 | + function getModulePlugin() { |
|
109 | 109 | if (!$this->_modulePlugin) { |
110 | 110 | global $smartobject_rating_handler; |
111 | 111 | $this->_modulePlugin = $smartobject_rating_handler->pluginsObject->getPlugin($this->getVar('dirname', 'n')); |
112 | 112 | } |
113 | 113 | return $this->_modulePlugin; |
114 | - } |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler { |
117 | 117 | |
@@ -119,18 +119,18 @@ discard block |
||
119 | 119 | var $_moduleList=false; |
120 | 120 | var $pluginsObject; |
121 | 121 | |
122 | - function SmartobjectRatingHandler($db) { |
|
123 | - $this->SmartPersistableObjectHandler($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
122 | + function SmartobjectRatingHandler($db) { |
|
123 | + $this->SmartPersistableObjectHandler($db, 'rating', 'ratingid', 'rate', '', 'smartobject'); |
|
124 | 124 | $this->generalSQL = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname . ' INNER JOIN ' . $this->db->prefix('users') . ' AS user ON ' . $this->_itemname . '.uid=user.uid'; |
125 | 125 | |
126 | - $this->_rateOptions[1] = 1; |
|
127 | - $this->_rateOptions[2] = 2; |
|
128 | - $this->_rateOptions[3] = 3; |
|
129 | - $this->_rateOptions[4] = 4; |
|
130 | - $this->_rateOptions[5] = 5; |
|
126 | + $this->_rateOptions[1] = 1; |
|
127 | + $this->_rateOptions[2] = 2; |
|
128 | + $this->_rateOptions[3] = 3; |
|
129 | + $this->_rateOptions[4] = 4; |
|
130 | + $this->_rateOptions[5] = 5; |
|
131 | 131 | |
132 | - $this->pluginsObject = new SmartPluginHandler(); |
|
133 | - } |
|
132 | + $this->pluginsObject = new SmartPluginHandler(); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | function getModuleList() { |
136 | 136 | if (!$this->_moduleList) { |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | $sql = "SELECT AVG(rate), COUNT(ratingid) FROM " . $this->table . " WHERE itemid=$itemid AND dirname='$dirname' AND item='$item' GROUP BY itemid"; |
152 | 152 | $result = $this->db->query($sql); |
153 | 153 | if (!$result) { |
154 | - return 0; |
|
155 | - } |
|
156 | - list($average, $sum) = $this->db->fetchRow($result); |
|
157 | - $ret['average'] = isset($average) ? $average : 0; |
|
158 | - $ret['sum'] = isset($sum) ? $sum : 0; |
|
159 | - return $ret; |
|
154 | + return 0; |
|
155 | + } |
|
156 | + list($average, $sum) = $this->db->fetchRow($result); |
|
157 | + $ret['average'] = isset($average) ? $average : 0; |
|
158 | + $ret['sum'] = isset($sum) ? $sum : 0; |
|
159 | + return $ret; |
|
160 | 160 | } |
161 | 161 | function already_rated($item, $itemid, $dirname, $uid){ |
162 | 162 |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | die("XOOPS root path not defined"); |
32 | 32 | } |
33 | 33 | |
34 | -include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartobject.php"; |
|
35 | -include_once XOOPS_ROOT_PATH."/modules/smartobject/class/smartplugins.php"; |
|
34 | +include_once XOOPS_ROOT_PATH . "/modules/smartobject/class/smartobject.php"; |
|
35 | +include_once XOOPS_ROOT_PATH . "/modules/smartobject/class/smartplugins.php"; |
|
36 | 36 | |
37 | 37 | class SmartobjectRating extends SmartObject { |
38 | 38 | |
39 | - var $_modulePlugin=false; |
|
39 | + var $_modulePlugin = false; |
|
40 | 40 | |
41 | 41 | function SmartobjectRating() { |
42 | 42 | $this->quickInitVar('ratingid', XOBJ_DTYPE_INT, true); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | |
68 | 68 | function getVar($key, $format = 's') { |
69 | 69 | if ($format == 's' && in_array($key, array('name', 'dirname'))) { |
70 | - return call_user_func(array($this,$key)); |
|
70 | + return call_user_func(array($this, $key)); |
|
71 | 71 | } |
72 | 72 | return parent::getVar($key, $format); |
73 | 73 | } |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | } |
116 | 116 | class SmartobjectRatingHandler extends SmartPersistableObjectHandler { |
117 | 117 | |
118 | - var $_rateOptions=array(); |
|
119 | - var $_moduleList=false; |
|
118 | + var $_rateOptions = array(); |
|
119 | + var $_moduleList = false; |
|
120 | 120 | var $pluginsObject; |
121 | 121 | |
122 | 122 | function SmartobjectRatingHandler($db) { |
@@ -158,19 +158,19 @@ discard block |
||
158 | 158 | $ret['sum'] = isset($sum) ? $sum : 0; |
159 | 159 | return $ret; |
160 | 160 | } |
161 | - function already_rated($item, $itemid, $dirname, $uid){ |
|
161 | + function already_rated($item, $itemid, $dirname, $uid) { |
|
162 | 162 | |
163 | 163 | $criteria = new CriteriaCompo(); |
164 | - $criteria->add(new Criteria('item',$item )); |
|
165 | - $criteria->add(new Criteria('itemid',$itemid )); |
|
164 | + $criteria->add(new Criteria('item', $item)); |
|
165 | + $criteria->add(new Criteria('itemid', $itemid)); |
|
166 | 166 | $criteria->add(new Criteria('dirname', $dirname)); |
167 | 167 | $criteria->add(new Criteria('user.uid', $uid)); |
168 | 168 | |
169 | 169 | $ret = $this->getObjects($criteria); |
170 | 170 | |
171 | - if(!$ret){ |
|
171 | + if (!$ret) { |
|
172 | 172 | return false; |
173 | - }else{ |
|
173 | + } else { |
|
174 | 174 | return $ret[0]; |
175 | 175 | } |
176 | 176 |
@@ -170,7 +170,7 @@ |
||
170 | 170 | |
171 | 171 | if(!$ret){ |
172 | 172 | return false; |
173 | - }else{ |
|
173 | + } else{ |
|
174 | 174 | return $ret[0]; |
175 | 175 | } |
176 | 176 |
@@ -129,6 +129,10 @@ discard block |
||
129 | 129 | } |
130 | 130 | return $fields; |
131 | 131 | } |
132 | + |
|
133 | + /** |
|
134 | + * @param string $field |
|
135 | + */ |
|
132 | 136 | function fieldExists($field) { |
133 | 137 | $existingFields = $this->getExistingFieldsArray(); |
134 | 138 | return isset ($existingFields[$field]); |
@@ -541,7 +545,7 @@ discard block |
||
541 | 545 | /** |
542 | 546 | * Use to update a table |
543 | 547 | * |
544 | - * @param object $table {@link SmartDbTable} that will be updated |
|
548 | + * @param SmartDbTable $table {@link SmartDbTable} that will be updated |
|
545 | 549 | * |
546 | 550 | * @see SmartDbTable |
547 | 551 | * |
@@ -601,6 +605,9 @@ discard block |
||
601 | 605 | return $ret; |
602 | 606 | } |
603 | 607 | |
608 | + /** |
|
609 | + * @return string |
|
610 | + */ |
|
604 | 611 | function getFieldDefaultFromVar($var, $key = false) { |
605 | 612 | if ($var['value']) { |
606 | 613 | return $var['value']; |
@@ -1,756 +1,756 @@ |
||
1 | 1 | <?php |
2 | 2 | /** |
3 | - * Contains the classes for updating database tables |
|
4 | - * |
|
5 | - * @license GNU |
|
6 | - * @author marcan <[email protected]> |
|
7 | - * @version $Id: smartdbupdater.php 799 2008-02-04 22:14:27Z malanciault $ |
|
8 | - * @link http://www.smartfactory.ca The SmartFactory |
|
9 | - * @package SmartObject |
|
10 | - */ |
|
3 | + * Contains the classes for updating database tables |
|
4 | + * |
|
5 | + * @license GNU |
|
6 | + * @author marcan <[email protected]> |
|
7 | + * @version $Id: smartdbupdater.php 799 2008-02-04 22:14:27Z malanciault $ |
|
8 | + * @link http://www.smartfactory.ca The SmartFactory |
|
9 | + * @package SmartObject |
|
10 | + */ |
|
11 | 11 | /** |
12 | - * SmartDbTable class |
|
13 | - * |
|
14 | - * Information about an individual table |
|
15 | - * |
|
16 | - * @package SmartObject |
|
17 | - * @author marcan <[email protected]> |
|
18 | - * @link http://www.smartfactory.ca The SmartFactory |
|
19 | - */ |
|
12 | + * SmartDbTable class |
|
13 | + * |
|
14 | + * Information about an individual table |
|
15 | + * |
|
16 | + * @package SmartObject |
|
17 | + * @author marcan <[email protected]> |
|
18 | + * @link http://www.smartfactory.ca The SmartFactory |
|
19 | + */ |
|
20 | 20 | if (!defined("XOOPS_ROOT_PATH")) { |
21 | - die("XOOPS root path not defined"); |
|
21 | + die("XOOPS root path not defined"); |
|
22 | 22 | } |
23 | 23 | if (!defined("SMARTOBJECT_ROOT_PATH")) { |
24 | - include_once (XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
24 | + include_once (XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'); |
|
25 | 25 | } |
26 | 26 | /** |
27 | - * Include the language constants for the SmartObjectDBUpdater |
|
28 | - */ |
|
27 | + * Include the language constants for the SmartObjectDBUpdater |
|
28 | + */ |
|
29 | 29 | global $xoopsConfig; |
30 | 30 | $common_file = SMARTOBJECT_ROOT_PATH . "language/" . $xoopsConfig['language'] . "/smartdbupdater.php"; |
31 | 31 | if (!file_exists($common_file)) { |
32 | - $common_file = SMARTOBJECT_ROOT_PATH . "language/english/smartdbupdater.php"; |
|
32 | + $common_file = SMARTOBJECT_ROOT_PATH . "language/english/smartdbupdater.php"; |
|
33 | 33 | } |
34 | 34 | include ($common_file); |
35 | 35 | class SmartDbTable { |
36 | - /** |
|
37 | - * @var string $_name name of the table |
|
38 | - */ |
|
39 | - var $_name; |
|
40 | - /** |
|
41 | - * @var string $_structure structure of the table |
|
42 | - */ |
|
43 | - var $_structure; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array $_data containing valued of each records to be added |
|
47 | - */ |
|
48 | - var $_data; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var array $_alteredFields containing fields to be altered |
|
52 | - */ |
|
53 | - var $_alteredFields; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var array $_newFields containing new fields to be added |
|
57 | - */ |
|
58 | - var $_newFields; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array $_dropedFields containing fields to be droped |
|
62 | - */ |
|
63 | - var $_dropedFields; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var array $_flagForDrop flag table to drop it |
|
67 | - */ |
|
68 | - var $_flagForDrop = false; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var array $_updatedFields containing fields which values will be updated |
|
72 | - */ |
|
73 | - var $_updatedFields; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var array $_updatedFields containing fields which values will be updated |
|
77 | - */ //felix |
|
78 | - var $_updatedWhere; |
|
79 | - |
|
80 | - var $_existingFieldsArray=false; |
|
81 | - |
|
82 | - /** |
|
83 | - * Constructor |
|
84 | - * |
|
85 | - * @param string $name name of the table |
|
86 | - * |
|
87 | - */ |
|
88 | - function SmartDbTable($name) { |
|
89 | - $this->_name = $name; |
|
90 | - $this->_data = array (); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Return the table name, prefixed with site table prefix |
|
95 | - * |
|
96 | - * @return string table name |
|
97 | - * |
|
98 | - */ |
|
99 | - function name() { |
|
100 | - global $xoopsDB; |
|
101 | - return $xoopsDB->prefix($this->_name); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Checks if the table already exists in the database |
|
106 | - * |
|
107 | - * @return bool TRUE if it exists, FALSE if not |
|
108 | - * |
|
109 | - */ |
|
110 | - function exists() { |
|
111 | - return smart_TableExists($this->_name); |
|
112 | - } |
|
113 | - |
|
114 | - function getExistingFieldsArray() { |
|
115 | - |
|
116 | - global $xoopsDB; |
|
117 | - $result = $xoopsDB->query("SHOW COLUMNS FROM " . $this->name()); |
|
118 | - while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
119 | - $fields[$existing_field['Field']] = $existing_field['Type']; |
|
120 | - if ($existing_field['Null'] != "YES") { |
|
121 | - $fields[$existing_field['Field']] .= " NOT NULL"; |
|
122 | - } |
|
123 | - if ($existing_field['Extra']) { |
|
124 | - $fields[$existing_field['Field']] .= " " . $existing_field['Extra']; |
|
125 | - } |
|
126 | - if (!($existing_field['Default'] === NULL) && ($existing_field['Default'] || $existing_field['Default'] == '' || $existing_field['Default'] == 0)) { |
|
127 | - $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
128 | - } |
|
129 | - } |
|
130 | - return $fields; |
|
131 | - } |
|
132 | - function fieldExists($field) { |
|
133 | - $existingFields = $this->getExistingFieldsArray(); |
|
134 | - return isset ($existingFields[$field]); |
|
135 | - } |
|
136 | - /** |
|
137 | - * Set the table structure |
|
138 | - * |
|
139 | - * Example : |
|
140 | - * |
|
141 | - * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
142 | - * `date` int(11) NOT NULL default '0', |
|
143 | - * `status` int(1) NOT NULL default '-1', |
|
144 | - * `itemid` int(11) NOT NULL default '0', |
|
145 | - * `uid` int(11) NOT NULL default '0', |
|
146 | - * `price` float NOT NULL default '0', |
|
147 | - * `currency` varchar(100) NOT NULL default '', |
|
148 | - * PRIMARY KEY (`transactionid`)"); |
|
149 | - * |
|
150 | - * @param string $structure table structure |
|
151 | - * |
|
152 | - */ |
|
153 | - function setStructure($structure) { |
|
154 | - $this->_structure = $structure; |
|
155 | - } |
|
156 | - /** |
|
157 | - * Return the table structure |
|
158 | - * |
|
159 | - * @return string table structure |
|
160 | - * |
|
161 | - */ |
|
162 | - function getStructure() { |
|
163 | - return sprintf($this->_structure, $this->name()); |
|
164 | - } |
|
165 | - /** |
|
166 | - * Add values of a record to be added |
|
167 | - * |
|
168 | - * @param string $data values of a record |
|
169 | - * |
|
170 | - */ |
|
171 | - function setData($data) { |
|
172 | - $this->_data[] = $data; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Get the data array |
|
177 | - * |
|
178 | - * @return array containing the records values to be added |
|
179 | - * |
|
180 | - */ |
|
181 | - function getData() { |
|
182 | - return $this->_data; |
|
183 | - } |
|
184 | - /** |
|
185 | - * Use to insert data in a table |
|
186 | - * |
|
187 | - * @return bool true if success, false if an error occured |
|
188 | - * |
|
189 | - */ |
|
190 | - function addData() { |
|
191 | - global $xoopsDB; |
|
192 | - foreach ($this->getData() as $data) { |
|
193 | - $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
194 | - $ret = $xoopsDB->query($query); |
|
195 | - if (!$ret) { |
|
196 | - echo " " . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . "<br />"; |
|
197 | - } else { |
|
198 | - echo " " . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . "<br />"; |
|
199 | - } |
|
200 | - } |
|
201 | - return $ret; |
|
202 | - } |
|
203 | - /** |
|
204 | - * Add a field to be added |
|
205 | - * |
|
206 | - * @param string $name name of the field |
|
207 | - * @param string $properties properties of the field |
|
208 | - * |
|
209 | - */ |
|
210 | - function addAlteredField($name, $properties, $newname=false, $showerror = true) { |
|
211 | - $field['name'] = $name; |
|
212 | - $field['properties'] = $properties; |
|
213 | - $field['showerror'] = $showerror; |
|
214 | - $field['newname'] = $newname; |
|
215 | - $this->_alteredFields[] = $field; |
|
216 | - } |
|
217 | - /** |
|
218 | - * Invert values 0 to 1 and 1 to 0 |
|
219 | - * |
|
220 | - * @param string $name name of the field |
|
221 | - * @param string $old old propertie |
|
222 | - * @param string $new new propertie |
|
223 | - * |
|
224 | - */ //felix |
|
225 | - function addUpdatedWhere($name, $newValue, $oldValue) { |
|
226 | - $field['name'] = $name; |
|
227 | - $field['value'] = $newValue; |
|
228 | - $field['where'] = $oldValue; |
|
229 | - $this->_updatedWhere[] = $field; |
|
230 | - } |
|
231 | - /** |
|
232 | - * Add new field of a record to be added |
|
233 | - * |
|
234 | - * @param string $name name of the field |
|
235 | - * @param string $properties properties of the field |
|
236 | - * |
|
237 | - */ |
|
238 | - function addNewField($name, $properties) { |
|
239 | - $field['name'] = $name; |
|
240 | - $field['properties'] = $properties; |
|
241 | - $this->_newFields[] = $field; |
|
242 | - } |
|
243 | - /** |
|
244 | - * Get fields that need to be altered |
|
245 | - * |
|
246 | - * @return array fields that need to be altered |
|
247 | - * |
|
248 | - */ |
|
249 | - function getAlteredFields() { |
|
250 | - return $this->_alteredFields; |
|
251 | - } |
|
252 | - /** |
|
253 | - * Add field for which the value will be updated |
|
254 | - * |
|
255 | - * @param string $name name of the field |
|
256 | - * @param string $value value to be set |
|
257 | - * |
|
258 | - */ |
|
259 | - function addUpdatedField($name, $value) { |
|
260 | - $field['name'] = $name; |
|
261 | - $field['value'] = $value; |
|
262 | - $this->_updatedFields[] = $field; |
|
263 | - } |
|
264 | - /** |
|
265 | - * Get new fields to be added |
|
266 | - * |
|
267 | - * @return array fields to be added |
|
268 | - * |
|
269 | - */ |
|
270 | - function getNewFields() { |
|
271 | - return $this->_newFields; |
|
272 | - } |
|
273 | - /** |
|
274 | - * Get fields which values need to be updated |
|
275 | - * |
|
276 | - * @return array fields which values need to be updated |
|
277 | - * |
|
278 | - */ |
|
279 | - function getUpdatedFields() { |
|
280 | - return $this->_updatedFields; |
|
281 | - } |
|
282 | - /** |
|
283 | - * Get fields which values need to be updated |
|
284 | - * |
|
285 | - * @return array fields which values need to be updated |
|
286 | - * |
|
287 | - */ //felix |
|
288 | - function getUpdatedWhere() { |
|
289 | - return $this->_updatedWhere; |
|
290 | - } |
|
291 | - /** |
|
292 | - * Add values of a record to be added |
|
293 | - * |
|
294 | - * @param string $name name of the field |
|
295 | - * |
|
296 | - */ |
|
297 | - function addDropedField($name) { |
|
298 | - $this->_dropedFields[] = $name; |
|
299 | - } |
|
300 | - /** |
|
301 | - * Get fields that need to be droped |
|
302 | - * |
|
303 | - * @return array fields that need to be droped |
|
304 | - * |
|
305 | - */ |
|
306 | - function getDropedFields() { |
|
307 | - return $this->_dropedFields; |
|
308 | - } |
|
309 | - /** |
|
310 | - * Set the flag to drop the table |
|
311 | - * |
|
312 | - */ |
|
313 | - function setFlagForDrop() { |
|
314 | - $this->_flagForDrop = true; |
|
315 | - } |
|
316 | - /** |
|
317 | - * Use to create a table |
|
318 | - * |
|
319 | - * @return bool true if success, false if an error occured |
|
320 | - * |
|
321 | - */ |
|
322 | - function createTable() { |
|
323 | - global $xoopsDB; |
|
324 | - $query = $this->getStructure(); |
|
325 | - $query = "CREATE TABLE `" . $this->name() . "` (" . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
326 | - //xoops_debug($query); |
|
327 | - $ret = $xoopsDB->query($query); |
|
328 | - if (!$ret) { |
|
329 | - echo " " . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
330 | - |
|
331 | - } else { |
|
332 | - echo " " . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . "<br />"; |
|
333 | - } |
|
334 | - return $ret; |
|
335 | - } |
|
336 | - /** |
|
337 | - * Use to drop a table |
|
338 | - * |
|
339 | - * @return bool true if success, false if an error occured |
|
340 | - * |
|
341 | - */ |
|
342 | - function dropTable() { |
|
343 | - global $xoopsDB; |
|
344 | - $query = sprintf("DROP TABLE %s", $this->name()); |
|
345 | - $ret = $xoopsDB->query($query); |
|
346 | - if (!$ret) { |
|
347 | - echo " " . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
348 | - return false; |
|
349 | - } else { |
|
350 | - echo " " . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . "<br />"; |
|
351 | - return true; |
|
352 | - } |
|
353 | - } |
|
354 | - /** |
|
355 | - * Use to alter a table |
|
356 | - * |
|
357 | - * @return bool true if success, false if an error occured |
|
358 | - * |
|
359 | - */ |
|
360 | - function alterTable() { |
|
361 | - global $xoopsDB; |
|
362 | - $ret = true; |
|
363 | - |
|
364 | - foreach ($this->getAlteredFields() as $alteredField) { |
|
365 | - if (!$alteredField['newname']) { |
|
366 | - $alteredField['newname'] = $alteredField['name']; |
|
367 | - } |
|
368 | - |
|
369 | - $query = sprintf("ALTER TABLE `%s` CHANGE `%s` `%s` %s", $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
370 | - $ret = $ret && $xoopsDB->query($query); |
|
371 | - if ($alteredField['showerror']) { |
|
372 | - if (!$ret) { |
|
373 | - echo " " . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
374 | - } else { |
|
375 | - echo " " . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . "<br />"; |
|
376 | - } |
|
377 | - } |
|
378 | - } |
|
379 | - |
|
380 | - return $ret; |
|
381 | - } |
|
382 | - /** |
|
383 | - * Use to add new fileds in the table |
|
384 | - * |
|
385 | - * @return bool true if success, false if an error occured |
|
386 | - * |
|
387 | - */ |
|
388 | - function addNewFields() { |
|
389 | - global $xoopsDB; |
|
390 | - $ret = true; |
|
391 | - foreach ($this->getNewFields() as $newField) { |
|
392 | - $query = sprintf("ALTER TABLE `%s` ADD `%s` %s", $this->name(), $newField['name'], $newField['properties']); |
|
393 | - //echo $query; |
|
394 | - $ret = $ret && $xoopsDB->query($query); |
|
395 | - if (!$ret) { |
|
396 | - echo " " . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . "<br />"; |
|
397 | - } else { |
|
398 | - echo " " . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . "<br />"; |
|
399 | - } |
|
400 | - } |
|
401 | - return $ret; |
|
402 | - } |
|
403 | - /** |
|
404 | - * Use to update fields values |
|
405 | - * |
|
406 | - * @return bool true if success, false if an error occured |
|
407 | - * |
|
408 | - */ |
|
409 | - function updateFieldsValues() { |
|
410 | - global $xoopsDB; |
|
411 | - $ret = true; |
|
412 | - foreach ($this->getUpdatedFields() as $updatedField) { |
|
413 | - $query = sprintf("UPDATE %s SET %s = %s", $this->name(), $updatedField['name'], $updatedField['value']); |
|
414 | - $ret = $ret && $xoopsDB->query($query); |
|
415 | - if (!$ret) { |
|
416 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
417 | - } else { |
|
418 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
|
419 | - } |
|
420 | - } |
|
421 | - return $ret; |
|
422 | - } |
|
423 | - /** |
|
424 | - * Use to update fields values |
|
425 | - * |
|
426 | - * @return bool true if success, false if an error occured |
|
427 | - * |
|
428 | - */ //felix |
|
429 | - function updateWhereValues() { |
|
430 | - global $xoopsDB; |
|
431 | - $ret = true; |
|
432 | - foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
433 | - $query = sprintf("UPDATE %s SET %s = %s WHERE %s %s", $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
434 | - //echo $query."<br>"; |
|
435 | - $ret = $ret && $xoopsDB->query($query); |
|
436 | - if (!$ret) { |
|
437 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
438 | - } else { |
|
439 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
|
440 | - } |
|
441 | - } |
|
442 | - return $ret; |
|
443 | - } |
|
444 | - /** |
|
445 | - * Use to drop fields |
|
446 | - * |
|
447 | - * @return bool true if success, false if an error occured |
|
448 | - * |
|
449 | - */ |
|
450 | - function dropFields() { |
|
451 | - global $xoopsDB; |
|
452 | - $ret = true; |
|
453 | - foreach ($this->getdropedFields() as $dropedField) { |
|
454 | - $query = sprintf("ALTER TABLE %s DROP %s", $this->name(), $dropedField); |
|
455 | - $ret = $ret && $xoopsDB->query($query); |
|
456 | - if (!$ret) { |
|
457 | - echo " " . sprintf(_SDU_MSG_DROPFIELD_ERR, $dropedField, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
458 | - } else { |
|
459 | - echo " " . sprintf(_SDU_MSG_DROPFIELD, $dropedField, $this->name()) . "<br />"; |
|
460 | - } |
|
461 | - } |
|
462 | - return $ret; |
|
463 | - } |
|
36 | + /** |
|
37 | + * @var string $_name name of the table |
|
38 | + */ |
|
39 | + var $_name; |
|
40 | + /** |
|
41 | + * @var string $_structure structure of the table |
|
42 | + */ |
|
43 | + var $_structure; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array $_data containing valued of each records to be added |
|
47 | + */ |
|
48 | + var $_data; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var array $_alteredFields containing fields to be altered |
|
52 | + */ |
|
53 | + var $_alteredFields; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var array $_newFields containing new fields to be added |
|
57 | + */ |
|
58 | + var $_newFields; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array $_dropedFields containing fields to be droped |
|
62 | + */ |
|
63 | + var $_dropedFields; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var array $_flagForDrop flag table to drop it |
|
67 | + */ |
|
68 | + var $_flagForDrop = false; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var array $_updatedFields containing fields which values will be updated |
|
72 | + */ |
|
73 | + var $_updatedFields; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var array $_updatedFields containing fields which values will be updated |
|
77 | + */ //felix |
|
78 | + var $_updatedWhere; |
|
79 | + |
|
80 | + var $_existingFieldsArray=false; |
|
81 | + |
|
82 | + /** |
|
83 | + * Constructor |
|
84 | + * |
|
85 | + * @param string $name name of the table |
|
86 | + * |
|
87 | + */ |
|
88 | + function SmartDbTable($name) { |
|
89 | + $this->_name = $name; |
|
90 | + $this->_data = array (); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Return the table name, prefixed with site table prefix |
|
95 | + * |
|
96 | + * @return string table name |
|
97 | + * |
|
98 | + */ |
|
99 | + function name() { |
|
100 | + global $xoopsDB; |
|
101 | + return $xoopsDB->prefix($this->_name); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Checks if the table already exists in the database |
|
106 | + * |
|
107 | + * @return bool TRUE if it exists, FALSE if not |
|
108 | + * |
|
109 | + */ |
|
110 | + function exists() { |
|
111 | + return smart_TableExists($this->_name); |
|
112 | + } |
|
113 | + |
|
114 | + function getExistingFieldsArray() { |
|
115 | + |
|
116 | + global $xoopsDB; |
|
117 | + $result = $xoopsDB->query("SHOW COLUMNS FROM " . $this->name()); |
|
118 | + while ($existing_field = $xoopsDB->fetchArray($result)) { |
|
119 | + $fields[$existing_field['Field']] = $existing_field['Type']; |
|
120 | + if ($existing_field['Null'] != "YES") { |
|
121 | + $fields[$existing_field['Field']] .= " NOT NULL"; |
|
122 | + } |
|
123 | + if ($existing_field['Extra']) { |
|
124 | + $fields[$existing_field['Field']] .= " " . $existing_field['Extra']; |
|
125 | + } |
|
126 | + if (!($existing_field['Default'] === NULL) && ($existing_field['Default'] || $existing_field['Default'] == '' || $existing_field['Default'] == 0)) { |
|
127 | + $fields[$existing_field['Field']] .= " default '" . $existing_field['Default'] . "'"; |
|
128 | + } |
|
129 | + } |
|
130 | + return $fields; |
|
131 | + } |
|
132 | + function fieldExists($field) { |
|
133 | + $existingFields = $this->getExistingFieldsArray(); |
|
134 | + return isset ($existingFields[$field]); |
|
135 | + } |
|
136 | + /** |
|
137 | + * Set the table structure |
|
138 | + * |
|
139 | + * Example : |
|
140 | + * |
|
141 | + * $table->setStructure("`transactionid` int(11) NOT NULL auto_increment, |
|
142 | + * `date` int(11) NOT NULL default '0', |
|
143 | + * `status` int(1) NOT NULL default '-1', |
|
144 | + * `itemid` int(11) NOT NULL default '0', |
|
145 | + * `uid` int(11) NOT NULL default '0', |
|
146 | + * `price` float NOT NULL default '0', |
|
147 | + * `currency` varchar(100) NOT NULL default '', |
|
148 | + * PRIMARY KEY (`transactionid`)"); |
|
149 | + * |
|
150 | + * @param string $structure table structure |
|
151 | + * |
|
152 | + */ |
|
153 | + function setStructure($structure) { |
|
154 | + $this->_structure = $structure; |
|
155 | + } |
|
156 | + /** |
|
157 | + * Return the table structure |
|
158 | + * |
|
159 | + * @return string table structure |
|
160 | + * |
|
161 | + */ |
|
162 | + function getStructure() { |
|
163 | + return sprintf($this->_structure, $this->name()); |
|
164 | + } |
|
165 | + /** |
|
166 | + * Add values of a record to be added |
|
167 | + * |
|
168 | + * @param string $data values of a record |
|
169 | + * |
|
170 | + */ |
|
171 | + function setData($data) { |
|
172 | + $this->_data[] = $data; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Get the data array |
|
177 | + * |
|
178 | + * @return array containing the records values to be added |
|
179 | + * |
|
180 | + */ |
|
181 | + function getData() { |
|
182 | + return $this->_data; |
|
183 | + } |
|
184 | + /** |
|
185 | + * Use to insert data in a table |
|
186 | + * |
|
187 | + * @return bool true if success, false if an error occured |
|
188 | + * |
|
189 | + */ |
|
190 | + function addData() { |
|
191 | + global $xoopsDB; |
|
192 | + foreach ($this->getData() as $data) { |
|
193 | + $query = sprintf('INSERT INTO %s VALUES (%s)', $this->name(), $data); |
|
194 | + $ret = $xoopsDB->query($query); |
|
195 | + if (!$ret) { |
|
196 | + echo " " . sprintf(_SDU_MSG_ADD_DATA_ERR, $this->name()) . "<br />"; |
|
197 | + } else { |
|
198 | + echo " " . sprintf(_SDU_MSG_ADD_DATA, $this->name()) . "<br />"; |
|
199 | + } |
|
200 | + } |
|
201 | + return $ret; |
|
202 | + } |
|
203 | + /** |
|
204 | + * Add a field to be added |
|
205 | + * |
|
206 | + * @param string $name name of the field |
|
207 | + * @param string $properties properties of the field |
|
208 | + * |
|
209 | + */ |
|
210 | + function addAlteredField($name, $properties, $newname=false, $showerror = true) { |
|
211 | + $field['name'] = $name; |
|
212 | + $field['properties'] = $properties; |
|
213 | + $field['showerror'] = $showerror; |
|
214 | + $field['newname'] = $newname; |
|
215 | + $this->_alteredFields[] = $field; |
|
216 | + } |
|
217 | + /** |
|
218 | + * Invert values 0 to 1 and 1 to 0 |
|
219 | + * |
|
220 | + * @param string $name name of the field |
|
221 | + * @param string $old old propertie |
|
222 | + * @param string $new new propertie |
|
223 | + * |
|
224 | + */ //felix |
|
225 | + function addUpdatedWhere($name, $newValue, $oldValue) { |
|
226 | + $field['name'] = $name; |
|
227 | + $field['value'] = $newValue; |
|
228 | + $field['where'] = $oldValue; |
|
229 | + $this->_updatedWhere[] = $field; |
|
230 | + } |
|
231 | + /** |
|
232 | + * Add new field of a record to be added |
|
233 | + * |
|
234 | + * @param string $name name of the field |
|
235 | + * @param string $properties properties of the field |
|
236 | + * |
|
237 | + */ |
|
238 | + function addNewField($name, $properties) { |
|
239 | + $field['name'] = $name; |
|
240 | + $field['properties'] = $properties; |
|
241 | + $this->_newFields[] = $field; |
|
242 | + } |
|
243 | + /** |
|
244 | + * Get fields that need to be altered |
|
245 | + * |
|
246 | + * @return array fields that need to be altered |
|
247 | + * |
|
248 | + */ |
|
249 | + function getAlteredFields() { |
|
250 | + return $this->_alteredFields; |
|
251 | + } |
|
252 | + /** |
|
253 | + * Add field for which the value will be updated |
|
254 | + * |
|
255 | + * @param string $name name of the field |
|
256 | + * @param string $value value to be set |
|
257 | + * |
|
258 | + */ |
|
259 | + function addUpdatedField($name, $value) { |
|
260 | + $field['name'] = $name; |
|
261 | + $field['value'] = $value; |
|
262 | + $this->_updatedFields[] = $field; |
|
263 | + } |
|
264 | + /** |
|
265 | + * Get new fields to be added |
|
266 | + * |
|
267 | + * @return array fields to be added |
|
268 | + * |
|
269 | + */ |
|
270 | + function getNewFields() { |
|
271 | + return $this->_newFields; |
|
272 | + } |
|
273 | + /** |
|
274 | + * Get fields which values need to be updated |
|
275 | + * |
|
276 | + * @return array fields which values need to be updated |
|
277 | + * |
|
278 | + */ |
|
279 | + function getUpdatedFields() { |
|
280 | + return $this->_updatedFields; |
|
281 | + } |
|
282 | + /** |
|
283 | + * Get fields which values need to be updated |
|
284 | + * |
|
285 | + * @return array fields which values need to be updated |
|
286 | + * |
|
287 | + */ //felix |
|
288 | + function getUpdatedWhere() { |
|
289 | + return $this->_updatedWhere; |
|
290 | + } |
|
291 | + /** |
|
292 | + * Add values of a record to be added |
|
293 | + * |
|
294 | + * @param string $name name of the field |
|
295 | + * |
|
296 | + */ |
|
297 | + function addDropedField($name) { |
|
298 | + $this->_dropedFields[] = $name; |
|
299 | + } |
|
300 | + /** |
|
301 | + * Get fields that need to be droped |
|
302 | + * |
|
303 | + * @return array fields that need to be droped |
|
304 | + * |
|
305 | + */ |
|
306 | + function getDropedFields() { |
|
307 | + return $this->_dropedFields; |
|
308 | + } |
|
309 | + /** |
|
310 | + * Set the flag to drop the table |
|
311 | + * |
|
312 | + */ |
|
313 | + function setFlagForDrop() { |
|
314 | + $this->_flagForDrop = true; |
|
315 | + } |
|
316 | + /** |
|
317 | + * Use to create a table |
|
318 | + * |
|
319 | + * @return bool true if success, false if an error occured |
|
320 | + * |
|
321 | + */ |
|
322 | + function createTable() { |
|
323 | + global $xoopsDB; |
|
324 | + $query = $this->getStructure(); |
|
325 | + $query = "CREATE TABLE `" . $this->name() . "` (" . $query . ") ENGINE=MyISAM COMMENT='The SmartFactory <www.smartfactory.ca>'"; |
|
326 | + //xoops_debug($query); |
|
327 | + $ret = $xoopsDB->query($query); |
|
328 | + if (!$ret) { |
|
329 | + echo " " . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
330 | + |
|
331 | + } else { |
|
332 | + echo " " . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . "<br />"; |
|
333 | + } |
|
334 | + return $ret; |
|
335 | + } |
|
336 | + /** |
|
337 | + * Use to drop a table |
|
338 | + * |
|
339 | + * @return bool true if success, false if an error occured |
|
340 | + * |
|
341 | + */ |
|
342 | + function dropTable() { |
|
343 | + global $xoopsDB; |
|
344 | + $query = sprintf("DROP TABLE %s", $this->name()); |
|
345 | + $ret = $xoopsDB->query($query); |
|
346 | + if (!$ret) { |
|
347 | + echo " " . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
348 | + return false; |
|
349 | + } else { |
|
350 | + echo " " . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . "<br />"; |
|
351 | + return true; |
|
352 | + } |
|
353 | + } |
|
354 | + /** |
|
355 | + * Use to alter a table |
|
356 | + * |
|
357 | + * @return bool true if success, false if an error occured |
|
358 | + * |
|
359 | + */ |
|
360 | + function alterTable() { |
|
361 | + global $xoopsDB; |
|
362 | + $ret = true; |
|
363 | + |
|
364 | + foreach ($this->getAlteredFields() as $alteredField) { |
|
365 | + if (!$alteredField['newname']) { |
|
366 | + $alteredField['newname'] = $alteredField['name']; |
|
367 | + } |
|
368 | + |
|
369 | + $query = sprintf("ALTER TABLE `%s` CHANGE `%s` `%s` %s", $this->name(), $alteredField['name'], $alteredField['newname'], $alteredField['properties']); |
|
370 | + $ret = $ret && $xoopsDB->query($query); |
|
371 | + if ($alteredField['showerror']) { |
|
372 | + if (!$ret) { |
|
373 | + echo " " . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
374 | + } else { |
|
375 | + echo " " . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . "<br />"; |
|
376 | + } |
|
377 | + } |
|
378 | + } |
|
379 | + |
|
380 | + return $ret; |
|
381 | + } |
|
382 | + /** |
|
383 | + * Use to add new fileds in the table |
|
384 | + * |
|
385 | + * @return bool true if success, false if an error occured |
|
386 | + * |
|
387 | + */ |
|
388 | + function addNewFields() { |
|
389 | + global $xoopsDB; |
|
390 | + $ret = true; |
|
391 | + foreach ($this->getNewFields() as $newField) { |
|
392 | + $query = sprintf("ALTER TABLE `%s` ADD `%s` %s", $this->name(), $newField['name'], $newField['properties']); |
|
393 | + //echo $query; |
|
394 | + $ret = $ret && $xoopsDB->query($query); |
|
395 | + if (!$ret) { |
|
396 | + echo " " . sprintf(_SDU_MSG_NEWFIELD_ERR, $newField['name'], $this->name()) . "<br />"; |
|
397 | + } else { |
|
398 | + echo " " . sprintf(_SDU_MSG_NEWFIELD, $newField['name'], $this->name()) . "<br />"; |
|
399 | + } |
|
400 | + } |
|
401 | + return $ret; |
|
402 | + } |
|
403 | + /** |
|
404 | + * Use to update fields values |
|
405 | + * |
|
406 | + * @return bool true if success, false if an error occured |
|
407 | + * |
|
408 | + */ |
|
409 | + function updateFieldsValues() { |
|
410 | + global $xoopsDB; |
|
411 | + $ret = true; |
|
412 | + foreach ($this->getUpdatedFields() as $updatedField) { |
|
413 | + $query = sprintf("UPDATE %s SET %s = %s", $this->name(), $updatedField['name'], $updatedField['value']); |
|
414 | + $ret = $ret && $xoopsDB->query($query); |
|
415 | + if (!$ret) { |
|
416 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
417 | + } else { |
|
418 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
|
419 | + } |
|
420 | + } |
|
421 | + return $ret; |
|
422 | + } |
|
423 | + /** |
|
424 | + * Use to update fields values |
|
425 | + * |
|
426 | + * @return bool true if success, false if an error occured |
|
427 | + * |
|
428 | + */ //felix |
|
429 | + function updateWhereValues() { |
|
430 | + global $xoopsDB; |
|
431 | + $ret = true; |
|
432 | + foreach ($this->getUpdatedWhere() as $updatedWhere) { |
|
433 | + $query = sprintf("UPDATE %s SET %s = %s WHERE %s %s", $this->name(), $updatedWhere['name'], $updatedWhere['value'], $updatedWhere['name'], $updatedWhere['where']); |
|
434 | + //echo $query."<br>"; |
|
435 | + $ret = $ret && $xoopsDB->query($query); |
|
436 | + if (!$ret) { |
|
437 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
438 | + } else { |
|
439 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
|
440 | + } |
|
441 | + } |
|
442 | + return $ret; |
|
443 | + } |
|
444 | + /** |
|
445 | + * Use to drop fields |
|
446 | + * |
|
447 | + * @return bool true if success, false if an error occured |
|
448 | + * |
|
449 | + */ |
|
450 | + function dropFields() { |
|
451 | + global $xoopsDB; |
|
452 | + $ret = true; |
|
453 | + foreach ($this->getdropedFields() as $dropedField) { |
|
454 | + $query = sprintf("ALTER TABLE %s DROP %s", $this->name(), $dropedField); |
|
455 | + $ret = $ret && $xoopsDB->query($query); |
|
456 | + if (!$ret) { |
|
457 | + echo " " . sprintf(_SDU_MSG_DROPFIELD_ERR, $dropedField, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
458 | + } else { |
|
459 | + echo " " . sprintf(_SDU_MSG_DROPFIELD, $dropedField, $this->name()) . "<br />"; |
|
460 | + } |
|
461 | + } |
|
462 | + return $ret; |
|
463 | + } |
|
464 | 464 | } |
465 | 465 | /** |
466 | - * SmartobjectDbupdater class |
|
467 | - * |
|
468 | - * Class performing the database update for the module |
|
469 | - * |
|
470 | - * @package SmartObject |
|
471 | - * @author marcan <[email protected]> |
|
472 | - * @link http://www.smartfactory.ca The SmartFactory |
|
473 | - */ |
|
466 | + * SmartobjectDbupdater class |
|
467 | + * |
|
468 | + * Class performing the database update for the module |
|
469 | + * |
|
470 | + * @package SmartObject |
|
471 | + * @author marcan <[email protected]> |
|
472 | + * @link http://www.smartfactory.ca The SmartFactory |
|
473 | + */ |
|
474 | 474 | class SmartobjectDbupdater { |
475 | 475 | |
476 | - var $_dbTypesArray; |
|
477 | - |
|
478 | - function SmartobjectDbupdater() { |
|
479 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
480 | - $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
481 | - $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
482 | - $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
483 | - $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
484 | - $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
485 | - $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
486 | - $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
487 | - $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
488 | - $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
489 | - $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
490 | - $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
491 | - $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
492 | - $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
493 | - $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
494 | - $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
495 | - $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
496 | - $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
497 | - } |
|
498 | - /** |
|
499 | - * Use to execute a general query |
|
500 | - * |
|
501 | - * @param string $query query that will be executed |
|
502 | - * @param string $goodmsg message displayed on success |
|
503 | - * @param string $badmsg message displayed on error |
|
504 | - * |
|
505 | - * @return bool true if success, false if an error occured |
|
506 | - * |
|
507 | - */ |
|
508 | - function runQuery($query, $goodmsg, $badmsg) { |
|
509 | - global $xoopsDB; |
|
510 | - $ret = $xoopsDB->query($query); |
|
511 | - if (!$ret) { |
|
512 | - echo " $badmsg<br />"; |
|
513 | - return false; |
|
514 | - } else { |
|
515 | - echo " $goodmsg<br />"; |
|
516 | - return true; |
|
517 | - } |
|
518 | - } |
|
519 | - /** |
|
520 | - * Use to rename a table |
|
521 | - * |
|
522 | - * @param string $from name of the table to rename |
|
523 | - * @param string $to new name of the renamed table |
|
524 | - * |
|
525 | - * @return bool true if success, false if an error occured |
|
526 | - */ |
|
527 | - function renameTable($from, $to) { |
|
528 | - global $xoopsDB; |
|
529 | - $from = $xoopsDB->prefix($from); |
|
530 | - $to = $xoopsDB->prefix($to); |
|
531 | - $query = sprintf("ALTER TABLE %s RENAME %s", $from, $to); |
|
532 | - $ret = $xoopsDB->query($query); |
|
533 | - if (!$ret) { |
|
534 | - echo " " . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . "<br />"; |
|
535 | - return false; |
|
536 | - } else { |
|
537 | - echo " " . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . "<br />"; |
|
538 | - return true; |
|
539 | - } |
|
540 | - } |
|
541 | - /** |
|
542 | - * Use to update a table |
|
543 | - * |
|
544 | - * @param object $table {@link SmartDbTable} that will be updated |
|
545 | - * |
|
546 | - * @see SmartDbTable |
|
547 | - * |
|
548 | - * @return bool true if success, false if an error occured |
|
549 | - */ |
|
550 | - function updateTable($table) { |
|
551 | - global $xoopsDB; |
|
552 | - $ret = true; |
|
553 | - // If table has a structure, create the table |
|
554 | - if ($table->getStructure()) { |
|
555 | - $ret = $table->createTable() && $ret; |
|
556 | - } |
|
557 | - // If table is flag for drop, drop it |
|
558 | - if ($table->_flagForDrop) { |
|
559 | - $ret = $table->dropTable() && $ret; |
|
560 | - } |
|
561 | - // If table has data, insert it |
|
562 | - if ($table->getData()) { |
|
563 | - $ret = $table->addData() && $ret; |
|
564 | - } |
|
565 | - // If table has new fields to be added, add them |
|
566 | - if ($table->getNewFields()) { |
|
567 | - $ret = $table->addNewFields() && $ret; |
|
568 | - } |
|
569 | - // If table has altered field, alter the table |
|
570 | - if ($table->getAlteredFields()) { |
|
571 | - $ret = $table->alterTable() && $ret; |
|
572 | - } |
|
573 | - // If table has updated field values, update the table |
|
574 | - if ($table->getUpdatedFields()) { |
|
575 | - $ret = $table->updateFieldsValues($table) && $ret; |
|
576 | - } |
|
577 | - // If table has droped field, alter the table |
|
578 | - if ($table->getDropedFields()) { |
|
579 | - $ret = $table->dropFields($table) && $ret; |
|
580 | - } |
|
581 | - //felix |
|
582 | - // If table has updated field values, update the table |
|
583 | - if ($table->getUpdatedWhere()) { |
|
584 | - $ret = $table->UpdateWhereValues($table) && $ret; |
|
585 | - } |
|
586 | - return $ret; |
|
587 | - } |
|
588 | - |
|
589 | - function automaticUpgrade($module, $item) { |
|
590 | - if (is_array($item)) { |
|
591 | - foreach($item as $v) { |
|
592 | - $this->upgradeObjectItem($module, $v); |
|
593 | - } |
|
594 | - } else { |
|
595 | - $this->upgradeObjectItem($module, $item); |
|
596 | - } |
|
597 | - } |
|
598 | - |
|
599 | - function getFieldTypeFromVar($var) { |
|
600 | - $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
601 | - return $ret; |
|
602 | - } |
|
603 | - |
|
604 | - function getFieldDefaultFromVar($var, $key = false) { |
|
605 | - if ($var['value']) { |
|
606 | - return $var['value']; |
|
607 | - } else { |
|
608 | - if (in_array($var['data_type'], array( |
|
609 | - XOBJ_DTYPE_INT, |
|
610 | - XOBJ_DTYPE_STIME, |
|
611 | - XOBJ_DTYPE_MTIME, |
|
612 | - XOBJ_DTYPE_LTIME, |
|
613 | - XOBJ_DTYPE_TIME_ONLY, |
|
614 | - XOBJ_DTYPE_URLLINK, |
|
615 | - XOBJ_DTYPE_FILE |
|
616 | - ))) { |
|
617 | - return '0'; |
|
618 | - } else { |
|
619 | - return ''; |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - |
|
624 | - function upgradeObjectItem($module, $item) { |
|
625 | - $module_handler = xoops_getModuleHandler($item, $module); |
|
626 | - if (!$module_handler) { |
|
627 | - return false; |
|
628 | - } |
|
629 | - |
|
630 | - $table = new SmartDbTable($module . '_' . $item); |
|
631 | - $object = $module_handler->create(); |
|
632 | - $objectVars = $object->getVars(); |
|
633 | - |
|
634 | - if (!$table->exists()) { |
|
635 | - // table was never created, let's do it |
|
636 | - $structure = ""; |
|
637 | - foreach($objectVars as $key=>$var) { |
|
638 | - if ($var['persistent']) { |
|
639 | - $type = $this->getFieldTypeFromVar($var); |
|
640 | - if ($key == $module_handler->keyName) { |
|
641 | - $extra = "auto_increment"; |
|
642 | - } else { |
|
643 | - $default = $this->getFieldDefaultFromVar($var); |
|
644 | - $extra = "default '$default' |
|
476 | + var $_dbTypesArray; |
|
477 | + |
|
478 | + function SmartobjectDbupdater() { |
|
479 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTBOX] = 'varchar(255)'; |
|
480 | + $this->_dbTypesArray[XOBJ_DTYPE_TXTAREA] = 'text'; |
|
481 | + $this->_dbTypesArray[XOBJ_DTYPE_INT] = 'int(11)'; |
|
482 | + $this->_dbTypesArray[XOBJ_DTYPE_URL] = 'varchar(255)'; |
|
483 | + $this->_dbTypesArray[XOBJ_DTYPE_EMAIL] = 'varchar(255)'; |
|
484 | + $this->_dbTypesArray[XOBJ_DTYPE_ARRAY] = 'text'; |
|
485 | + $this->_dbTypesArray[XOBJ_DTYPE_OTHER] = 'text'; |
|
486 | + $this->_dbTypesArray[XOBJ_DTYPE_SOURCE] = 'text'; |
|
487 | + $this->_dbTypesArray[XOBJ_DTYPE_STIME] = 'int(11)'; |
|
488 | + $this->_dbTypesArray[XOBJ_DTYPE_MTIME] = 'int(11)'; |
|
489 | + $this->_dbTypesArray[XOBJ_DTYPE_LTIME] = 'int(11)'; |
|
490 | + $this->_dbTypesArray[XOBJ_DTYPE_SIMPLE_ARRAY] = 'text'; |
|
491 | + $this->_dbTypesArray[XOBJ_DTYPE_CURRENCY] = 'text'; |
|
492 | + $this->_dbTypesArray[XOBJ_DTYPE_FLOAT] = 'float'; |
|
493 | + $this->_dbTypesArray[XOBJ_DTYPE_TIME_ONLY] = 'int(11)'; |
|
494 | + $this->_dbTypesArray[XOBJ_DTYPE_URLLINK] = 'int(11)'; |
|
495 | + $this->_dbTypesArray[XOBJ_DTYPE_FILE] = 'int(11)'; |
|
496 | + $this->_dbTypesArray[XOBJ_DTYPE_IMAGE] = 'varchar(255)'; |
|
497 | + } |
|
498 | + /** |
|
499 | + * Use to execute a general query |
|
500 | + * |
|
501 | + * @param string $query query that will be executed |
|
502 | + * @param string $goodmsg message displayed on success |
|
503 | + * @param string $badmsg message displayed on error |
|
504 | + * |
|
505 | + * @return bool true if success, false if an error occured |
|
506 | + * |
|
507 | + */ |
|
508 | + function runQuery($query, $goodmsg, $badmsg) { |
|
509 | + global $xoopsDB; |
|
510 | + $ret = $xoopsDB->query($query); |
|
511 | + if (!$ret) { |
|
512 | + echo " $badmsg<br />"; |
|
513 | + return false; |
|
514 | + } else { |
|
515 | + echo " $goodmsg<br />"; |
|
516 | + return true; |
|
517 | + } |
|
518 | + } |
|
519 | + /** |
|
520 | + * Use to rename a table |
|
521 | + * |
|
522 | + * @param string $from name of the table to rename |
|
523 | + * @param string $to new name of the renamed table |
|
524 | + * |
|
525 | + * @return bool true if success, false if an error occured |
|
526 | + */ |
|
527 | + function renameTable($from, $to) { |
|
528 | + global $xoopsDB; |
|
529 | + $from = $xoopsDB->prefix($from); |
|
530 | + $to = $xoopsDB->prefix($to); |
|
531 | + $query = sprintf("ALTER TABLE %s RENAME %s", $from, $to); |
|
532 | + $ret = $xoopsDB->query($query); |
|
533 | + if (!$ret) { |
|
534 | + echo " " . sprintf(_SDU_MSG_RENAME_TABLE_ERR, $from) . "<br />"; |
|
535 | + return false; |
|
536 | + } else { |
|
537 | + echo " " . sprintf(_SDU_MSG_RENAME_TABLE, $from, $to) . "<br />"; |
|
538 | + return true; |
|
539 | + } |
|
540 | + } |
|
541 | + /** |
|
542 | + * Use to update a table |
|
543 | + * |
|
544 | + * @param object $table {@link SmartDbTable} that will be updated |
|
545 | + * |
|
546 | + * @see SmartDbTable |
|
547 | + * |
|
548 | + * @return bool true if success, false if an error occured |
|
549 | + */ |
|
550 | + function updateTable($table) { |
|
551 | + global $xoopsDB; |
|
552 | + $ret = true; |
|
553 | + // If table has a structure, create the table |
|
554 | + if ($table->getStructure()) { |
|
555 | + $ret = $table->createTable() && $ret; |
|
556 | + } |
|
557 | + // If table is flag for drop, drop it |
|
558 | + if ($table->_flagForDrop) { |
|
559 | + $ret = $table->dropTable() && $ret; |
|
560 | + } |
|
561 | + // If table has data, insert it |
|
562 | + if ($table->getData()) { |
|
563 | + $ret = $table->addData() && $ret; |
|
564 | + } |
|
565 | + // If table has new fields to be added, add them |
|
566 | + if ($table->getNewFields()) { |
|
567 | + $ret = $table->addNewFields() && $ret; |
|
568 | + } |
|
569 | + // If table has altered field, alter the table |
|
570 | + if ($table->getAlteredFields()) { |
|
571 | + $ret = $table->alterTable() && $ret; |
|
572 | + } |
|
573 | + // If table has updated field values, update the table |
|
574 | + if ($table->getUpdatedFields()) { |
|
575 | + $ret = $table->updateFieldsValues($table) && $ret; |
|
576 | + } |
|
577 | + // If table has droped field, alter the table |
|
578 | + if ($table->getDropedFields()) { |
|
579 | + $ret = $table->dropFields($table) && $ret; |
|
580 | + } |
|
581 | + //felix |
|
582 | + // If table has updated field values, update the table |
|
583 | + if ($table->getUpdatedWhere()) { |
|
584 | + $ret = $table->UpdateWhereValues($table) && $ret; |
|
585 | + } |
|
586 | + return $ret; |
|
587 | + } |
|
588 | + |
|
589 | + function automaticUpgrade($module, $item) { |
|
590 | + if (is_array($item)) { |
|
591 | + foreach($item as $v) { |
|
592 | + $this->upgradeObjectItem($module, $v); |
|
593 | + } |
|
594 | + } else { |
|
595 | + $this->upgradeObjectItem($module, $item); |
|
596 | + } |
|
597 | + } |
|
598 | + |
|
599 | + function getFieldTypeFromVar($var) { |
|
600 | + $ret = isset($this->_dbTypesArray[$var['data_type']]) ? $this->_dbTypesArray[$var['data_type']] : 'text'; |
|
601 | + return $ret; |
|
602 | + } |
|
603 | + |
|
604 | + function getFieldDefaultFromVar($var, $key = false) { |
|
605 | + if ($var['value']) { |
|
606 | + return $var['value']; |
|
607 | + } else { |
|
608 | + if (in_array($var['data_type'], array( |
|
609 | + XOBJ_DTYPE_INT, |
|
610 | + XOBJ_DTYPE_STIME, |
|
611 | + XOBJ_DTYPE_MTIME, |
|
612 | + XOBJ_DTYPE_LTIME, |
|
613 | + XOBJ_DTYPE_TIME_ONLY, |
|
614 | + XOBJ_DTYPE_URLLINK, |
|
615 | + XOBJ_DTYPE_FILE |
|
616 | + ))) { |
|
617 | + return '0'; |
|
618 | + } else { |
|
619 | + return ''; |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + |
|
624 | + function upgradeObjectItem($module, $item) { |
|
625 | + $module_handler = xoops_getModuleHandler($item, $module); |
|
626 | + if (!$module_handler) { |
|
627 | + return false; |
|
628 | + } |
|
629 | + |
|
630 | + $table = new SmartDbTable($module . '_' . $item); |
|
631 | + $object = $module_handler->create(); |
|
632 | + $objectVars = $object->getVars(); |
|
633 | + |
|
634 | + if (!$table->exists()) { |
|
635 | + // table was never created, let's do it |
|
636 | + $structure = ""; |
|
637 | + foreach($objectVars as $key=>$var) { |
|
638 | + if ($var['persistent']) { |
|
639 | + $type = $this->getFieldTypeFromVar($var); |
|
640 | + if ($key == $module_handler->keyName) { |
|
641 | + $extra = "auto_increment"; |
|
642 | + } else { |
|
643 | + $default = $this->getFieldDefaultFromVar($var); |
|
644 | + $extra = "default '$default' |
|
645 | 645 | "; |
646 | - } |
|
647 | - $structure .= "`$key` $type not null $extra, |
|
646 | + } |
|
647 | + $structure .= "`$key` $type not null $extra, |
|
648 | 648 | "; |
649 | - } |
|
650 | - } |
|
651 | - $structure .= "PRIMARY KEY (`" . $module_handler->keyName . "`) |
|
649 | + } |
|
650 | + } |
|
651 | + $structure .= "PRIMARY KEY (`" . $module_handler->keyName . "`) |
|
652 | 652 | "; |
653 | - $table->setStructure($structure); |
|
654 | - if (!$this->updateTable($table)) { |
|
655 | - /** |
|
656 | - * @todo trap the errors |
|
657 | - */ |
|
658 | - } |
|
659 | - } else { |
|
660 | - $existingFieldsArray = $table->getExistingFieldsArray(); |
|
661 | - foreach($objectVars as $key=>$var) { |
|
662 | - if ($var['persistent']) { |
|
663 | - if (!isset($existingFieldsArray[$key])) { |
|
664 | - // the fiels does not exist, let's create it |
|
665 | - $type = $this->getFieldTypeFromVar($var); |
|
666 | - $default = $this->getFieldDefaultFromVar($var); |
|
667 | - $table->addNewField($key, "$type not null default '$default'"); |
|
668 | - } else { |
|
669 | - // if field already exists, let's check if the definition is correct |
|
670 | - $definition = strtolower($existingFieldsArray[$key]); |
|
671 | - $type = $this->getFieldTypeFromVar($var); |
|
672 | - if ($key == $module_handler->keyName) { |
|
673 | - $extra = "auto_increment"; |
|
674 | - } else { |
|
675 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
676 | - $extra = "default '$default'"; |
|
677 | - } |
|
678 | - $actual_definition = "$type not null $extra"; |
|
679 | - if ($definition != $actual_definition) { |
|
680 | - $table->addAlteredField($key, $actual_definition); |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - |
|
686 | - // check to see if there are some unused fields left in the table |
|
687 | - foreach ($existingFieldsArray as $key=>$v) { |
|
688 | - if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
689 | - $table->addDropedField($key); |
|
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - if (!$this->updateTable($table)) { |
|
694 | - /** |
|
695 | - * @todo trap the errors |
|
696 | - */ |
|
697 | - } |
|
698 | - } |
|
699 | - } |
|
700 | - function moduleUpgrade(&$module) { |
|
701 | - $dirname = $module->getVar('dirname'); |
|
702 | - |
|
703 | - ob_start(); |
|
704 | - |
|
705 | - $table = new SmartDbTable($dirname . '_meta'); |
|
706 | - if (!$table->exists()) { |
|
707 | - $table->setStructure(" |
|
653 | + $table->setStructure($structure); |
|
654 | + if (!$this->updateTable($table)) { |
|
655 | + /** |
|
656 | + * @todo trap the errors |
|
657 | + */ |
|
658 | + } |
|
659 | + } else { |
|
660 | + $existingFieldsArray = $table->getExistingFieldsArray(); |
|
661 | + foreach($objectVars as $key=>$var) { |
|
662 | + if ($var['persistent']) { |
|
663 | + if (!isset($existingFieldsArray[$key])) { |
|
664 | + // the fiels does not exist, let's create it |
|
665 | + $type = $this->getFieldTypeFromVar($var); |
|
666 | + $default = $this->getFieldDefaultFromVar($var); |
|
667 | + $table->addNewField($key, "$type not null default '$default'"); |
|
668 | + } else { |
|
669 | + // if field already exists, let's check if the definition is correct |
|
670 | + $definition = strtolower($existingFieldsArray[$key]); |
|
671 | + $type = $this->getFieldTypeFromVar($var); |
|
672 | + if ($key == $module_handler->keyName) { |
|
673 | + $extra = "auto_increment"; |
|
674 | + } else { |
|
675 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
676 | + $extra = "default '$default'"; |
|
677 | + } |
|
678 | + $actual_definition = "$type not null $extra"; |
|
679 | + if ($definition != $actual_definition) { |
|
680 | + $table->addAlteredField($key, $actual_definition); |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + |
|
686 | + // check to see if there are some unused fields left in the table |
|
687 | + foreach ($existingFieldsArray as $key=>$v) { |
|
688 | + if (!isset($objectVars[$key]) || !$objectVars[$key]['persistent']) { |
|
689 | + $table->addDropedField($key); |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + if (!$this->updateTable($table)) { |
|
694 | + /** |
|
695 | + * @todo trap the errors |
|
696 | + */ |
|
697 | + } |
|
698 | + } |
|
699 | + } |
|
700 | + function moduleUpgrade(&$module) { |
|
701 | + $dirname = $module->getVar('dirname'); |
|
702 | + |
|
703 | + ob_start(); |
|
704 | + |
|
705 | + $table = new SmartDbTable($dirname . '_meta'); |
|
706 | + if (!$table->exists()) { |
|
707 | + $table->setStructure(" |
|
708 | 708 | `metakey` varchar(50) NOT NULL default '', |
709 | 709 | `metavalue` varchar(255) NOT NULL default '', |
710 | 710 | PRIMARY KEY (`metakey`)"); |
711 | - $table->setData("'version',0"); |
|
712 | - if (!$this->updateTable($table)) { |
|
713 | - /** |
|
714 | - * @todo trap the errors |
|
715 | - */ |
|
716 | - } |
|
717 | - } |
|
718 | - |
|
719 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
720 | - if (!$dbVersion) { |
|
721 | - $dbVersion = 0; |
|
722 | - } |
|
723 | - $newDbVersion = constant(strtoupper($dirname . '_db_version')) ? constant(strtoupper($dirname . '_db_version')) : 0; |
|
724 | - echo 'Database version : ' . $dbVersion . '<br />'; |
|
725 | - echo 'New database version : ' . $newDbVersion . '<br />'; |
|
726 | - |
|
727 | - if ($newDbVersion > $dbVersion) { |
|
728 | - for($i=$dbVersion+1;$i<=$newDbVersion; $i++) { |
|
729 | - $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
730 | - if (function_exists($upgrade_function)) { |
|
731 | - $upgrade_function(); |
|
732 | - } |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />"; |
|
737 | - |
|
738 | - // if there is a function to execute for this DB version, let's do it |
|
739 | - //$function_ |
|
740 | - |
|
741 | - $module_info = smart_getModuleInfo($dirname); |
|
742 | - $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
743 | - |
|
744 | - echo "</code>"; |
|
745 | - |
|
746 | - $feedback = ob_get_clean(); |
|
747 | - if (method_exists($module, "setMessage")) { |
|
748 | - $module->setMessage($feedback); |
|
749 | - } else { |
|
750 | - echo $feedback; |
|
751 | - } |
|
752 | - smart_SetMeta("version", $newDbVersion, $dirname); //Set meta version to current |
|
753 | - return true; |
|
754 | - } |
|
711 | + $table->setData("'version',0"); |
|
712 | + if (!$this->updateTable($table)) { |
|
713 | + /** |
|
714 | + * @todo trap the errors |
|
715 | + */ |
|
716 | + } |
|
717 | + } |
|
718 | + |
|
719 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
720 | + if (!$dbVersion) { |
|
721 | + $dbVersion = 0; |
|
722 | + } |
|
723 | + $newDbVersion = constant(strtoupper($dirname . '_db_version')) ? constant(strtoupper($dirname . '_db_version')) : 0; |
|
724 | + echo 'Database version : ' . $dbVersion . '<br />'; |
|
725 | + echo 'New database version : ' . $newDbVersion . '<br />'; |
|
726 | + |
|
727 | + if ($newDbVersion > $dbVersion) { |
|
728 | + for($i=$dbVersion+1;$i<=$newDbVersion; $i++) { |
|
729 | + $upgrade_function = $dirname . '_db_upgrade_' . $i; |
|
730 | + if (function_exists($upgrade_function)) { |
|
731 | + $upgrade_function(); |
|
732 | + } |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + echo "<code>" . _SDU_UPDATE_UPDATING_DATABASE . "<br />"; |
|
737 | + |
|
738 | + // if there is a function to execute for this DB version, let's do it |
|
739 | + //$function_ |
|
740 | + |
|
741 | + $module_info = smart_getModuleInfo($dirname); |
|
742 | + $this->automaticUpgrade($dirname, $module_info->modinfo['object_items']); |
|
743 | + |
|
744 | + echo "</code>"; |
|
745 | + |
|
746 | + $feedback = ob_get_clean(); |
|
747 | + if (method_exists($module, "setMessage")) { |
|
748 | + $module->setMessage($feedback); |
|
749 | + } else { |
|
750 | + echo $feedback; |
|
751 | + } |
|
752 | + smart_SetMeta("version", $newDbVersion, $dirname); //Set meta version to current |
|
753 | + return true; |
|
754 | + } |
|
755 | 755 | } |
756 | 756 | ?> |
757 | 757 | \ No newline at end of file |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ //felix |
78 | 78 | var $_updatedWhere; |
79 | 79 | |
80 | - var $_existingFieldsArray=false; |
|
80 | + var $_existingFieldsArray = false; |
|
81 | 81 | |
82 | 82 | /** |
83 | 83 | * Constructor |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function SmartDbTable($name) { |
89 | 89 | $this->_name = $name; |
90 | - $this->_data = array (); |
|
90 | + $this->_data = array(); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * @param string $properties properties of the field |
208 | 208 | * |
209 | 209 | */ |
210 | - function addAlteredField($name, $properties, $newname=false, $showerror = true) { |
|
210 | + function addAlteredField($name, $properties, $newname = false, $showerror = true) { |
|
211 | 211 | $field['name'] = $name; |
212 | 212 | $field['properties'] = $properties; |
213 | 213 | $field['showerror'] = $showerror; |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | //xoops_debug($query); |
327 | 327 | $ret = $xoopsDB->query($query); |
328 | 328 | if (!$ret) { |
329 | - echo " " . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
329 | + echo " " . sprintf(_SDU_MSG_CREATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
330 | 330 | |
331 | 331 | } else { |
332 | 332 | echo " " . sprintf(_SDU_MSG_CREATE_TABLE, $this->name()) . "<br />"; |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | $query = sprintf("DROP TABLE %s", $this->name()); |
345 | 345 | $ret = $xoopsDB->query($query); |
346 | 346 | if (!$ret) { |
347 | - echo " " . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
347 | + echo " " . sprintf(_SDU_MSG_DROP_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
348 | 348 | return false; |
349 | 349 | } else { |
350 | 350 | echo " " . sprintf(_SDU_MSG_DROP_TABLE, $this->name()) . "<br />"; |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $ret = $ret && $xoopsDB->query($query); |
371 | 371 | if ($alteredField['showerror']) { |
372 | 372 | if (!$ret) { |
373 | - echo " " . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
373 | + echo " " . sprintf(_SDU_MSG_CHGFIELD_ERR, $alteredField['name'], $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
374 | 374 | } else { |
375 | 375 | echo " " . sprintf(_SDU_MSG_CHGFIELD, $alteredField['name'], $this->name()) . "<br />"; |
376 | 376 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | $query = sprintf("UPDATE %s SET %s = %s", $this->name(), $updatedField['name'], $updatedField['value']); |
414 | 414 | $ret = $ret && $xoopsDB->query($query); |
415 | 415 | if (!$ret) { |
416 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
416 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
417 | 417 | } else { |
418 | 418 | echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
419 | 419 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | //echo $query."<br>"; |
435 | 435 | $ret = $ret && $xoopsDB->query($query); |
436 | 436 | if (!$ret) { |
437 | - echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
437 | + echo " " . sprintf(_SDU_MSG_UPDATE_TABLE_ERR, $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
438 | 438 | } else { |
439 | 439 | echo " " . sprintf(_SDU_MSG_UPDATE_TABLE, $this->name()) . "<br />"; |
440 | 440 | } |
@@ -454,7 +454,7 @@ discard block |
||
454 | 454 | $query = sprintf("ALTER TABLE %s DROP %s", $this->name(), $dropedField); |
455 | 455 | $ret = $ret && $xoopsDB->query($query); |
456 | 456 | if (!$ret) { |
457 | - echo " " . sprintf(_SDU_MSG_DROPFIELD_ERR, $dropedField, $this->name()) . " (" . $xoopsDB->error(). ")<br />"; |
|
457 | + echo " " . sprintf(_SDU_MSG_DROPFIELD_ERR, $dropedField, $this->name()) . " (" . $xoopsDB->error() . ")<br />"; |
|
458 | 458 | } else { |
459 | 459 | echo " " . sprintf(_SDU_MSG_DROPFIELD, $dropedField, $this->name()) . "<br />"; |
460 | 460 | } |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | |
589 | 589 | function automaticUpgrade($module, $item) { |
590 | 590 | if (is_array($item)) { |
591 | - foreach($item as $v) { |
|
591 | + foreach ($item as $v) { |
|
592 | 592 | $this->upgradeObjectItem($module, $v); |
593 | 593 | } |
594 | 594 | } else { |
@@ -634,13 +634,13 @@ discard block |
||
634 | 634 | if (!$table->exists()) { |
635 | 635 | // table was never created, let's do it |
636 | 636 | $structure = ""; |
637 | - foreach($objectVars as $key=>$var) { |
|
637 | + foreach ($objectVars as $key=>$var) { |
|
638 | 638 | if ($var['persistent']) { |
639 | 639 | $type = $this->getFieldTypeFromVar($var); |
640 | 640 | if ($key == $module_handler->keyName) { |
641 | 641 | $extra = "auto_increment"; |
642 | 642 | } else { |
643 | - $default = $this->getFieldDefaultFromVar($var); |
|
643 | + $default = $this->getFieldDefaultFromVar($var); |
|
644 | 644 | $extra = "default '$default' |
645 | 645 | "; |
646 | 646 | } |
@@ -658,21 +658,21 @@ discard block |
||
658 | 658 | } |
659 | 659 | } else { |
660 | 660 | $existingFieldsArray = $table->getExistingFieldsArray(); |
661 | - foreach($objectVars as $key=>$var) { |
|
661 | + foreach ($objectVars as $key=>$var) { |
|
662 | 662 | if ($var['persistent']) { |
663 | 663 | if (!isset($existingFieldsArray[$key])) { |
664 | 664 | // the fiels does not exist, let's create it |
665 | 665 | $type = $this->getFieldTypeFromVar($var); |
666 | - $default = $this->getFieldDefaultFromVar($var); |
|
666 | + $default = $this->getFieldDefaultFromVar($var); |
|
667 | 667 | $table->addNewField($key, "$type not null default '$default'"); |
668 | 668 | } else { |
669 | 669 | // if field already exists, let's check if the definition is correct |
670 | - $definition = strtolower($existingFieldsArray[$key]); |
|
670 | + $definition = strtolower($existingFieldsArray[$key]); |
|
671 | 671 | $type = $this->getFieldTypeFromVar($var); |
672 | 672 | if ($key == $module_handler->keyName) { |
673 | 673 | $extra = "auto_increment"; |
674 | 674 | } else { |
675 | - $default = $this->getFieldDefaultFromVar($var, $key); |
|
675 | + $default = $this->getFieldDefaultFromVar($var, $key); |
|
676 | 676 | $extra = "default '$default'"; |
677 | 677 | } |
678 | 678 | $actual_definition = "$type not null $extra"; |
@@ -716,7 +716,7 @@ discard block |
||
716 | 716 | } |
717 | 717 | } |
718 | 718 | |
719 | - $dbVersion = smart_GetMeta('version', $dirname); |
|
719 | + $dbVersion = smart_GetMeta('version', $dirname); |
|
720 | 720 | if (!$dbVersion) { |
721 | 721 | $dbVersion = 0; |
722 | 722 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | echo 'New database version : ' . $newDbVersion . '<br />'; |
726 | 726 | |
727 | 727 | if ($newDbVersion > $dbVersion) { |
728 | - for($i=$dbVersion+1;$i<=$newDbVersion; $i++) { |
|
728 | + for ($i = $dbVersion + 1; $i <= $newDbVersion; $i++) { |
|
729 | 729 | $upgrade_function = $dirname . '_db_upgrade_' . $i; |
730 | 730 | if (function_exists($upgrade_function)) { |
731 | 731 | $upgrade_function(); |
@@ -177,6 +177,10 @@ discard block |
||
177 | 177 | return implode($separator, $ret); |
178 | 178 | |
179 | 179 | } |
180 | + |
|
181 | + /** |
|
182 | + * @param false|string $trimFunction |
|
183 | + */ |
|
180 | 184 | function valToCsvHelper($val, $separator, $trimFunction) { |
181 | 185 | if ($trimFunction) |
182 | 186 | $val = $trimFunction ($val); |
@@ -221,6 +225,9 @@ discard block |
||
221 | 225 | $this->saveExportFile($exportFileData); |
222 | 226 | } |
223 | 227 | |
228 | + /** |
|
229 | + * @param string $content |
|
230 | + */ |
|
224 | 231 | function saveExportFile($content) { |
225 | 232 | switch ($this->format) { |
226 | 233 | case 'csv': |
@@ -246,37 +246,37 @@ |
||
246 | 246 | trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
247 | 247 | } else { |
248 | 248 | $mimeType = 'text/csv'; |
249 | - $file = strrev($this->filename); |
|
250 | - $temp_name = strtolower(strrev(substr($file,0,strpos($file,"--"))) ); |
|
249 | + $file = strrev($this->filename); |
|
250 | + $temp_name = strtolower(strrev(substr($file,0,strpos($file,"--"))) ); |
|
251 | 251 | if ($temp_name == '') { |
252 | 252 | $file_name = $this->filename; |
253 | 253 | } else { |
254 | 254 | $file_name = $temp_name; |
255 | 255 | } |
256 | - $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
256 | + $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
|
257 | 257 | |
258 | - if(ini_get('zlib.output_compression')) { |
|
259 | - ini_set('zlib.output_compression', 'Off'); |
|
260 | - } |
|
258 | + if(ini_get('zlib.output_compression')) { |
|
259 | + ini_set('zlib.output_compression', 'Off'); |
|
260 | + } |
|
261 | 261 | |
262 | - header("Pragma: public"); |
|
263 | - header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
|
264 | - header("Cache-Control: private",false); |
|
265 | - header("Content-Transfer-Encoding: binary"); |
|
266 | - if(isset($mimeType)) { |
|
267 | - header("Content-Type: " . $mimeType); |
|
268 | - } |
|
262 | + header("Pragma: public"); |
|
263 | + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
|
264 | + header("Cache-Control: private",false); |
|
265 | + header("Content-Transfer-Encoding: binary"); |
|
266 | + if(isset($mimeType)) { |
|
267 | + header("Content-Type: " . $mimeType); |
|
268 | + } |
|
269 | 269 | |
270 | - header("Content-Disposition: attachment; filename=" . $file_name); |
|
270 | + header("Content-Disposition: attachment; filename=" . $file_name); |
|
271 | 271 | |
272 | - if(isset($mimeType) && strstr($mimeType, "text/")) { |
|
273 | - $fp = fopen($fullFileName, "r"); |
|
274 | - } |
|
275 | - else { |
|
276 | - $fp = fopen($fullFileName, "rb"); |
|
277 | - } |
|
278 | - fpassthru($fp); |
|
279 | - exit(); |
|
272 | + if(isset($mimeType) && strstr($mimeType, "text/")) { |
|
273 | + $fp = fopen($fullFileName, "r"); |
|
274 | + } |
|
275 | + else { |
|
276 | + $fp = fopen($fullFileName, "rb"); |
|
277 | + } |
|
278 | + fpassthru($fp); |
|
279 | + exit(); |
|
280 | 280 | } |
281 | 281 | fclose($handle); |
282 | 282 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | var $filename; |
28 | 28 | var $filepath; |
29 | 29 | var $options; |
30 | - var $outputMethods=false; |
|
30 | + var $outputMethods = false; |
|
31 | 31 | var $notDisplayFields; |
32 | 32 | |
33 | 33 | /** |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * @param string $format format of the ouputed export. Currently only supports CSV |
42 | 42 | * @param array $options options of the format to be exported in |
43 | 43 | */ |
44 | - function SmartObjectExport(&$objectHandler, $criteria=null, $fields=false, $filename=false, $filepath=false, $format='csv', $options=false) { |
|
44 | + function SmartObjectExport(&$objectHandler, $criteria = null, $fields = false, $filename = false, $filepath = false, $format = 'csv', $options = false) { |
|
45 | 45 | $this->handler = $objectHandler; |
46 | 46 | $this->criteria = $criteria; |
47 | 47 | $this->fields = $fields; |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | /* |
102 | 102 | * Set an array of fields that we don't want in export |
103 | 103 | */ |
104 | - function setNotDisplayFields($fields){ |
|
105 | - if(!$this->notDisplayFields){ |
|
106 | - if(is_array($fields)){ |
|
104 | + function setNotDisplayFields($fields) { |
|
105 | + if (!$this->notDisplayFields) { |
|
106 | + if (is_array($fields)) { |
|
107 | 107 | $this->notDisplayFields = $fields; |
108 | - }else{ |
|
108 | + } else { |
|
109 | 109 | $this->notDisplayFields = array($fields); |
110 | 110 | } |
111 | - }else{ |
|
112 | - if(is_array($fields)){ |
|
111 | + } else { |
|
112 | + if (is_array($fields)) { |
|
113 | 113 | $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
114 | - }else{ |
|
114 | + } else { |
|
115 | 115 | $this->notDisplayFields[] = $fields; |
116 | 116 | } |
117 | 117 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param string $filepath path where the file will be saved |
145 | 145 | * @param array $options options of the format to be exported in |
146 | 146 | */ |
147 | - function SmartExportRenderer($data, $filename=false, $filepath=false, $format='csv', $options=array('separator'=>';')) { |
|
147 | + function SmartExportRenderer($data, $filename = false, $filepath = false, $format = 'csv', $options = array('separator'=>';')) { |
|
148 | 148 | $this->data = $data; |
149 | 149 | $this->format = $format; |
150 | 150 | $this->filename = $filename; |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | $trimFunction = 'trim'; |
170 | 170 | break; |
171 | 171 | } |
172 | - $ret = array (); |
|
173 | - foreach($dataArray as $key=>$field){ |
|
172 | + $ret = array(); |
|
173 | + foreach ($dataArray as $key=>$field) { |
|
174 | 174 | $ret[$key] = $this->valToCsvHelper($field, $separator, $trimFunction); |
175 | 175 | } |
176 | 176 | |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | function valToCsvHelper($val, $separator, $trimFunction) { |
181 | 181 | if ($trimFunction) |
182 | - $val = $trimFunction ($val); |
|
182 | + $val = $trimFunction($val); |
|
183 | 183 | //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
184 | 184 | $needQuote = FALSE; |
185 | 185 | do { |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | $firstRow = implode($separator, $this->data['columnsHeaders']); |
214 | 214 | $exportFileData .= $firstRow . "\r\n"; |
215 | 215 | |
216 | - foreach($this->data['rows'] as $cols) { |
|
216 | + foreach ($this->data['rows'] as $cols) { |
|
217 | 217 | $exportFileData .= $this->arrayToCsvString($cols, $separator) . "\r\n"; |
218 | 218 | } |
219 | 219 | break; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | } else { |
248 | 248 | $mimeType = 'text/csv'; |
249 | 249 | $file = strrev($this->filename); |
250 | - $temp_name = strtolower(strrev(substr($file,0,strpos($file,"--"))) ); |
|
250 | + $temp_name = strtolower(strrev(substr($file, 0, strpos($file, "--")))); |
|
251 | 251 | if ($temp_name == '') { |
252 | 252 | $file_name = $this->filename; |
253 | 253 | } else { |
@@ -255,21 +255,21 @@ discard block |
||
255 | 255 | } |
256 | 256 | $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
257 | 257 | |
258 | - if(ini_get('zlib.output_compression')) { |
|
258 | + if (ini_get('zlib.output_compression')) { |
|
259 | 259 | ini_set('zlib.output_compression', 'Off'); |
260 | 260 | } |
261 | 261 | |
262 | 262 | header("Pragma: public"); |
263 | 263 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); |
264 | - header("Cache-Control: private",false); |
|
264 | + header("Cache-Control: private", false); |
|
265 | 265 | header("Content-Transfer-Encoding: binary"); |
266 | - if(isset($mimeType)) { |
|
266 | + if (isset($mimeType)) { |
|
267 | 267 | header("Content-Type: " . $mimeType); |
268 | 268 | } |
269 | 269 | |
270 | 270 | header("Content-Disposition: attachment; filename=" . $file_name); |
271 | 271 | |
272 | - if(isset($mimeType) && strstr($mimeType, "text/")) { |
|
272 | + if (isset($mimeType) && strstr($mimeType, "text/")) { |
|
273 | 273 | $fp = fopen($fullFileName, "r"); |
274 | 274 | } |
275 | 275 | else { |
@@ -105,13 +105,13 @@ discard block |
||
105 | 105 | if(!$this->notDisplayFields){ |
106 | 106 | if(is_array($fields)){ |
107 | 107 | $this->notDisplayFields = $fields; |
108 | - }else{ |
|
108 | + } else{ |
|
109 | 109 | $this->notDisplayFields = array($fields); |
110 | 110 | } |
111 | - }else{ |
|
111 | + } else{ |
|
112 | 112 | if(is_array($fields)){ |
113 | 113 | $this->notDisplayFields = array_merge($this->notDisplayFields, $fields); |
114 | - }else{ |
|
114 | + } else{ |
|
115 | 115 | $this->notDisplayFields[] = $fields; |
116 | 116 | } |
117 | 117 | } |
@@ -153,8 +153,9 @@ discard block |
||
153 | 153 | } |
154 | 154 | |
155 | 155 | function arrayToCsvString($dataArray, $separator, $trim = 'both', $removeEmptyLines = TRUE) { |
156 | - if (!is_array($dataArray) || empty ($dataArray)) |
|
157 | - return ''; |
|
156 | + if (!is_array($dataArray) || empty ($dataArray)) { |
|
157 | + return ''; |
|
158 | + } |
|
158 | 159 | switch ($trim) { |
159 | 160 | case 'none' : |
160 | 161 | $trimFunction = FALSE; |
@@ -178,8 +179,9 @@ discard block |
||
178 | 179 | |
179 | 180 | } |
180 | 181 | function valToCsvHelper($val, $separator, $trimFunction) { |
181 | - if ($trimFunction) |
|
182 | - $val = $trimFunction ($val); |
|
182 | + if ($trimFunction) { |
|
183 | + $val = $trimFunction ($val); |
|
184 | + } |
|
183 | 185 | //If there is a separator (;) or a quote (") or a linebreak in the string, we need to quote it. |
184 | 186 | $needQuote = FALSE; |
185 | 187 | do { |
@@ -271,8 +273,7 @@ discard block |
||
271 | 273 | |
272 | 274 | if(isset($mimeType) && strstr($mimeType, "text/")) { |
273 | 275 | $fp = fopen($fullFileName, "r"); |
274 | - } |
|
275 | - else { |
|
276 | + } else { |
|
276 | 277 | $fp = fopen($fullFileName, "rb"); |
277 | 278 | } |
278 | 279 | fpassthru($fp); |