mambax7 /
extcal
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | **/ |
||
| 4 | |||
| 5 | // defined('XOOPS_ROOT_PATH') || die('XOOPS Root Path not defined'); |
||
| 6 | |||
| 7 | xoops_load('XoopsForm'); |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Form that will output as a theme-enabled HTML table. |
||
| 11 | * |
||
| 12 | * Also adds JavaScript to validate required fields |
||
| 13 | */ |
||
| 14 | class XoopsTableForm extends XoopsForm |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * ad the balise html "table" to render. |
||
| 18 | * |
||
| 19 | * @var bool|string |
||
| 20 | */ |
||
| 21 | public $_addBaliseTable = ''; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Gets the "value" attribute of a form element. |
||
| 25 | * |
||
| 26 | * @param $addBaliseTable |
||
| 27 | * |
||
| 28 | * @internal param string $name the "name" attribute of a form element |
||
| 29 | * @internal param bool $encode To sanitizer the text? |
||
| 30 | * |
||
| 31 | * @return string the "value" attribute assigned to a form element, null if not set |
||
| 32 | */ |
||
| 33 | public function setAddBaliseTable($addBaliseTable) |
||
| 34 | { |
||
| 35 | $this->_addBaliseTable = $addBaliseTable; |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * gets the "value" attribute of all form elements. |
||
| 40 | * |
||
| 41 | * @internal param bool $encode To sanitizer the text? |
||
| 42 | * |
||
| 43 | * @return array array of name/value pairs assigned to form elements |
||
| 44 | */ |
||
| 45 | public function getAddBaliseTable() |
||
| 46 | { |
||
| 47 | return $this->_addBaliseTable; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Insert an empty row in the table to serve as a seperator. |
||
| 52 | * |
||
| 53 | * @param string $extra HTML to be displayed in the empty row. |
||
| 54 | * @param string $class CSS class name for <td> tag |
||
| 55 | */ |
||
| 56 | public function insertBreak($extra = '', $class = '') |
||
| 57 | { |
||
| 58 | $class = ('' != $class) ? " class='" . preg_replace('/[^A-Za-z0-9\s\s_-]/i', '', $class) . "'" : ''; |
||
| 59 | // Fix for $extra tag not showing |
||
| 60 | if ($extra) { |
||
| 61 | $extra = '<tr><td colspan="2" ' . $class . '>' . $extra . '</td></tr>'; |
||
| 62 | $this->addElement($extra); |
||
| 63 | } else { |
||
| 64 | $extra = '<tr><td colspan="2" ' . $class . '> </td></tr>'; |
||
| 65 | $this->addElement($extra); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * create HTML to output the form as a theme-enabled table with validation. |
||
| 71 | * |
||
| 72 | * YOU SHOULD AVOID TO USE THE FOLLOWING Nocolspan METHOD, IT WILL BE REMOVED |
||
| 73 | * |
||
| 74 | * To use the noColspan simply use the following example: |
||
| 75 | * |
||
| 76 | * $colspan = new XoopsFormDhtmlTextArea( '', 'key', $value, '100%', '100%' ); |
||
| 77 | * $colspan->setNocolspan(); |
||
| 78 | * $form->addElement( $colspan ); |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function render() |
||
| 83 | { |
||
| 84 | $addBaliseTable = $this->_addBaliseTable; |
||
| 85 | $title = $this->getTitle(); |
||
| 86 | $ret = ''; |
||
| 87 | |||
| 88 | if ($addBaliseTable) { |
||
| 89 | $ret .= '<table width="100%" class="outer" cellspacing="1"> '; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ('' != $title) { |
||
| 93 | $ret .= '<tr><th colspan="2">' . $title . '</th></tr>'; |
||
| 94 | } |
||
| 95 | |||
| 96 | $hidden = ''; |
||
| 97 | $class = 'even'; |
||
| 98 | foreach ($this->getElements() as $ele) { |
||
| 99 | if (!is_object($ele)) { |
||
| 100 | $ret .= $ele; |
||
| 101 | } elseif (!$ele->isHidden()) { |
||
| 102 | if (!$ele->getNocolspan()) { |
||
| 103 | $ret .= '<tr valign="top" align="left"><td class="head">'; |
||
| 104 | View Code Duplication | if ('' != ($caption = $ele->getCaption())) { |
|
|
0 ignored issues
–
show
|
|||
| 105 | $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; |
||
| 106 | $ret .= '<span class="caption-text">' . $caption . '</span>'; |
||
| 107 | $ret .= '<span class="caption-marker">*</span>'; |
||
| 108 | $ret .= '</div>'; |
||
| 109 | } |
||
| 110 | if ('' != ($desc = $ele->getDescription())) { |
||
| 111 | $ret .= '<div class="xoops-form-element-help">' . $desc . '</div>'; |
||
| 112 | } |
||
| 113 | $ret .= '</td><td class="' . $class . '">' . $ele->render() . '</td></tr>' . NWLINE; |
||
| 114 | } else { |
||
| 115 | $ret .= '<tr valign="top" align="left"><td class="head" colspan="2">'; |
||
| 116 | View Code Duplication | if ('' != ($caption = $ele->getCaption())) { |
|
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 117 | $ret .= '<div class="xoops-form-element-caption' . ($ele->isRequired() ? '-required' : '') . '">'; |
||
| 118 | $ret .= '<span class="caption-text">' . $caption . '</span>'; |
||
| 119 | $ret .= '<span class="caption-marker">*</span>'; |
||
| 120 | $ret .= '</div>'; |
||
| 121 | } |
||
| 122 | $ret .= '</td></tr><tr valign="top" align="left"><td class="' . $class . '" colspan="2">' . $ele->render() . '</td></tr>'; |
||
| 123 | } |
||
| 124 | } else { |
||
| 125 | $hidden .= $ele->render(); |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($addBaliseTable) { |
||
| 130 | $ret .= '</table>'; |
||
| 131 | } |
||
| 132 | |||
| 133 | $ret .= NWLINE . ' ' . $hidden . NWLINE; |
||
| 134 | |||
| 135 | return $ret; |
||
| 136 | } |
||
| 137 | } // fin de la classe |
||
| 138 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.