@@ -30,117 +30,117 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class AdsenseHandler extends Smartobject\PersistableObjectHandler |
| 32 | 32 | { |
| 33 | - public $adFormats; |
|
| 34 | - public $adFormatsList; |
|
| 35 | - public $objects = false; |
|
| 33 | + public $adFormats; |
|
| 34 | + public $adFormatsList; |
|
| 35 | + public $objects = false; |
|
| 36 | 36 | // public $classname = Adsense::class; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * SmartobjectAdsenseHandler constructor. |
|
| 40 | - * @param \XoopsDatabase $db |
|
| 41 | - */ |
|
| 42 | - public function __construct(\XoopsDatabase $db) |
|
| 43 | - { |
|
| 44 | - parent::__construct($db, Adsense::class, 'adsenseid', 'description', '', 'smartobject'); |
|
| 45 | - $this->adFormats = []; |
|
| 46 | - $this->adFormatsList = []; |
|
| 47 | - |
|
| 48 | - $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 49 | - $this->adFormats['728x90_as']['width'] = 728; |
|
| 50 | - $this->adFormats['728x90_as']['height'] = 90; |
|
| 51 | - $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 52 | - |
|
| 53 | - $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 54 | - $this->adFormats['468x60_as']['width'] = 468; |
|
| 55 | - $this->adFormats['468x60_as']['height'] = 60; |
|
| 56 | - $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 57 | - |
|
| 58 | - $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 59 | - $this->adFormats['234x60_as']['width'] = 234; |
|
| 60 | - $this->adFormats['234x60_as']['height'] = 60; |
|
| 61 | - $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 62 | - |
|
| 63 | - $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 64 | - $this->adFormats['120x600_as']['width'] = 120; |
|
| 65 | - $this->adFormats['120x600_as']['height'] = 600; |
|
| 66 | - $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 67 | - |
|
| 68 | - $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 69 | - $this->adFormats['160x600_as']['width'] = 160; |
|
| 70 | - $this->adFormats['160x600_as']['height'] = 600; |
|
| 71 | - $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 72 | - |
|
| 73 | - $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 74 | - $this->adFormats['120x240_as']['width'] = 120; |
|
| 75 | - $this->adFormats['120x240_as']['height'] = 240; |
|
| 76 | - $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 77 | - |
|
| 78 | - $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 79 | - $this->adFormats['336x280_as']['width'] = 136; |
|
| 80 | - $this->adFormats['336x280_as']['height'] = 280; |
|
| 81 | - $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 82 | - |
|
| 83 | - $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 84 | - $this->adFormats['300x250_as']['width'] = 300; |
|
| 85 | - $this->adFormats['300x250_as']['height'] = 250; |
|
| 86 | - $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 87 | - |
|
| 88 | - $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 89 | - $this->adFormats['250x250_as']['width'] = 250; |
|
| 90 | - $this->adFormats['250x250_as']['height'] = 250; |
|
| 91 | - $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 92 | - |
|
| 93 | - $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 94 | - $this->adFormats['200x200_as']['width'] = 200; |
|
| 95 | - $this->adFormats['200x200_as']['height'] = 200; |
|
| 96 | - $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 97 | - |
|
| 98 | - $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 99 | - $this->adFormats['180x150_as']['width'] = 180; |
|
| 100 | - $this->adFormats['180x150_as']['height'] = 150; |
|
| 101 | - $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 102 | - |
|
| 103 | - $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 104 | - $this->adFormats['125x125_as']['width'] = 125; |
|
| 105 | - $this->adFormats['125x125_as']['height'] = 125; |
|
| 106 | - $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return array |
|
| 111 | - */ |
|
| 112 | - public function getFormats() |
|
| 113 | - { |
|
| 114 | - return $this->adFormatsList; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @param $obj |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function beforeSave($obj) |
|
| 122 | - { |
|
| 123 | - if ('' === $obj->getVar('tag')) { |
|
| 124 | - $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return true; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return array|bool |
|
| 132 | - */ |
|
| 133 | - public function getAdsensesByTag() |
|
| 134 | - { |
|
| 135 | - if (!$this->objects) { |
|
| 136 | - $adsensesObj =& $this->getObjects(null, true); |
|
| 137 | - $ret = []; |
|
| 138 | - foreach ($adsensesObj as $adsenseObj) { |
|
| 139 | - $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 140 | - } |
|
| 141 | - $this->objects = $ret; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $this->objects; |
|
| 145 | - } |
|
| 38 | + /** |
|
| 39 | + * SmartobjectAdsenseHandler constructor. |
|
| 40 | + * @param \XoopsDatabase $db |
|
| 41 | + */ |
|
| 42 | + public function __construct(\XoopsDatabase $db) |
|
| 43 | + { |
|
| 44 | + parent::__construct($db, Adsense::class, 'adsenseid', 'description', '', 'smartobject'); |
|
| 45 | + $this->adFormats = []; |
|
| 46 | + $this->adFormatsList = []; |
|
| 47 | + |
|
| 48 | + $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard'; |
|
| 49 | + $this->adFormats['728x90_as']['width'] = 728; |
|
| 50 | + $this->adFormats['728x90_as']['height'] = 90; |
|
| 51 | + $this->adFormatsList['728x90_as'] = $this->adFormats['728x90_as']['caption']; |
|
| 52 | + |
|
| 53 | + $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner'; |
|
| 54 | + $this->adFormats['468x60_as']['width'] = 468; |
|
| 55 | + $this->adFormats['468x60_as']['height'] = 60; |
|
| 56 | + $this->adFormatsList['468x60_as'] = $this->adFormats['468x60_as']['caption']; |
|
| 57 | + |
|
| 58 | + $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner'; |
|
| 59 | + $this->adFormats['234x60_as']['width'] = 234; |
|
| 60 | + $this->adFormats['234x60_as']['height'] = 60; |
|
| 61 | + $this->adFormatsList['234x60_as'] = $this->adFormats['234x60_as']['caption']; |
|
| 62 | + |
|
| 63 | + $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper'; |
|
| 64 | + $this->adFormats['120x600_as']['width'] = 120; |
|
| 65 | + $this->adFormats['120x600_as']['height'] = 600; |
|
| 66 | + $this->adFormatsList['120x600_as'] = $this->adFormats['120x600_as']['caption']; |
|
| 67 | + |
|
| 68 | + $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper'; |
|
| 69 | + $this->adFormats['160x600_as']['width'] = 160; |
|
| 70 | + $this->adFormats['160x600_as']['height'] = 600; |
|
| 71 | + $this->adFormatsList['160x600_as'] = $this->adFormats['160x600_as']['caption']; |
|
| 72 | + |
|
| 73 | + $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner'; |
|
| 74 | + $this->adFormats['120x240_as']['width'] = 120; |
|
| 75 | + $this->adFormats['120x240_as']['height'] = 240; |
|
| 76 | + $this->adFormatsList['120x240_as'] = $this->adFormats['120x240_as']['caption']; |
|
| 77 | + |
|
| 78 | + $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle'; |
|
| 79 | + $this->adFormats['336x280_as']['width'] = 136; |
|
| 80 | + $this->adFormats['336x280_as']['height'] = 280; |
|
| 81 | + $this->adFormatsList['336x280_as'] = $this->adFormats['336x280_as']['caption']; |
|
| 82 | + |
|
| 83 | + $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle'; |
|
| 84 | + $this->adFormats['300x250_as']['width'] = 300; |
|
| 85 | + $this->adFormats['300x250_as']['height'] = 250; |
|
| 86 | + $this->adFormatsList['300x250_as'] = $this->adFormats['300x250_as']['caption']; |
|
| 87 | + |
|
| 88 | + $this->adFormats['250x250_as']['caption'] = '250 X 250 Square'; |
|
| 89 | + $this->adFormats['250x250_as']['width'] = 250; |
|
| 90 | + $this->adFormats['250x250_as']['height'] = 250; |
|
| 91 | + $this->adFormatsList['250x250_as'] = $this->adFormats['250x250_as']['caption']; |
|
| 92 | + |
|
| 93 | + $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square'; |
|
| 94 | + $this->adFormats['200x200_as']['width'] = 200; |
|
| 95 | + $this->adFormats['200x200_as']['height'] = 200; |
|
| 96 | + $this->adFormatsList['200x200_as'] = $this->adFormats['200x200_as']['caption']; |
|
| 97 | + |
|
| 98 | + $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle'; |
|
| 99 | + $this->adFormats['180x150_as']['width'] = 180; |
|
| 100 | + $this->adFormats['180x150_as']['height'] = 150; |
|
| 101 | + $this->adFormatsList['180x150_as'] = $this->adFormats['180x150_as']['caption']; |
|
| 102 | + |
|
| 103 | + $this->adFormats['125x125_as']['caption'] = '125 X 125 Button'; |
|
| 104 | + $this->adFormats['125x125_as']['width'] = 125; |
|
| 105 | + $this->adFormats['125x125_as']['height'] = 125; |
|
| 106 | + $this->adFormatsList['125x125_as'] = $this->adFormats['125x125_as']['caption']; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return array |
|
| 111 | + */ |
|
| 112 | + public function getFormats() |
|
| 113 | + { |
|
| 114 | + return $this->adFormatsList; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @param $obj |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function beforeSave($obj) |
|
| 122 | + { |
|
| 123 | + if ('' === $obj->getVar('tag')) { |
|
| 124 | + $obj->setVar('tag', $title = $obj->generateTag()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return true; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return array|bool |
|
| 132 | + */ |
|
| 133 | + public function getAdsensesByTag() |
|
| 134 | + { |
|
| 135 | + if (!$this->objects) { |
|
| 136 | + $adsensesObj =& $this->getObjects(null, true); |
|
| 137 | + $ret = []; |
|
| 138 | + foreach ($adsensesObj as $adsenseObj) { |
|
| 139 | + $ret[$adsenseObj->getVar('tag')] = $adsenseObj; |
|
| 140 | + } |
|
| 141 | + $this->objects = $ret; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $this->objects; |
|
| 145 | + } |
|
| 146 | 146 | } |
@@ -29,152 +29,152 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Link extends Smartobject\BaseSmartObject |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * Link constructor. |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 38 | - $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 39 | - $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 40 | - $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 41 | - $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 42 | - $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 43 | - $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 44 | - $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 45 | - $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 46 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 47 | - $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 48 | - $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 49 | - $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * returns a specific variable for the object in a proper format |
|
| 54 | - * |
|
| 55 | - * @access public |
|
| 56 | - * @param string $key key of the object's variable to be returned |
|
| 57 | - * @param string $format format to use for the output |
|
| 58 | - * @return mixed formatted value of the variable |
|
| 59 | - */ |
|
| 60 | - public function getVar($key, $format = 's') |
|
| 61 | - { |
|
| 62 | - if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 63 | - // return call_user_func(array($this, $key)); |
|
| 64 | - return $this->{$key}(); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return parent::getVar($key, $format); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - public function from_uid() |
|
| 74 | - { |
|
| 75 | - $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 76 | - |
|
| 77 | - return $ret; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @param bool $withContact |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function to_uid($withContact = false) |
|
| 85 | - { |
|
| 86 | - $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 87 | - |
|
| 88 | - return $ret; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @return string |
|
| 93 | - */ |
|
| 94 | - public function date() |
|
| 95 | - { |
|
| 96 | - $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 97 | - |
|
| 98 | - return $ret; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param bool $full |
|
| 103 | - * @return mixed|string |
|
| 104 | - */ |
|
| 105 | - public function link($full = false) |
|
| 106 | - { |
|
| 107 | - $ret = $this->getVar('link', 'e'); |
|
| 108 | - if ($full) { |
|
| 109 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 110 | - $ret = $myts->displayTarea($ret); |
|
| 111 | - |
|
| 112 | - return $ret; |
|
| 113 | - } else { |
|
| 114 | - $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 115 | - |
|
| 116 | - return $ret; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * @return string |
|
| 122 | - */ |
|
| 123 | - public function getViewItemLink() |
|
| 124 | - { |
|
| 125 | - $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 126 | - |
|
| 127 | - return $ret; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getFromInfo() |
|
| 134 | - { |
|
| 135 | - // check if from_uid represent a user |
|
| 136 | - |
|
| 137 | - if ($this->getVar('from_uid')) { |
|
| 138 | - $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 139 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 140 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 141 | - } |
|
| 142 | - } else { |
|
| 143 | - $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $user; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - public function toArray() |
|
| 153 | - { |
|
| 154 | - $ret = parent::toArray(); |
|
| 155 | - $ret['fromInfo'] = $this->getFromInfo(); |
|
| 156 | - $ret['toInfo'] = $this->getToInfo(); |
|
| 157 | - $ret['fullLink'] = $this->link(true); |
|
| 158 | - |
|
| 159 | - return $ret; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function getToInfo() |
|
| 166 | - { |
|
| 167 | - // check if from_uid represent a user |
|
| 168 | - |
|
| 169 | - if ($this->getVar('to_uid')) { |
|
| 170 | - $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 171 | - if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 172 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 173 | - } |
|
| 174 | - } else { |
|
| 175 | - $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $user; |
|
| 179 | - } |
|
| 32 | + /** |
|
| 33 | + * Link constructor. |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->initVar('linkid', XOBJ_DTYPE_INT, '', true); |
|
| 38 | + $this->initVar('date', XOBJ_DTYPE_INT, 0, false, null, '', false, _CO_SOBJECT_LINK_DATE, '', true, true, false); |
|
| 39 | + $this->initVar('from_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_FROM_UID, _CO_SOBJECT_LINK_FROM_UID_DSC); |
|
| 40 | + $this->initVar('from_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_EMAIL, _CO_SOBJECT_LINK_FROM_EMAIL_DSC, true); |
|
| 41 | + $this->initVar('from_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_FROM_NAME, _CO_SOBJECT_LINK_FROM_NAME_DSC, true); |
|
| 42 | + $this->initVar('to_uid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_TO_UID, _CO_SOBJECT_LINK_TO_UID_DSC); |
|
| 43 | + $this->initVar('to_email', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_EMAIL, _CO_SOBJECT_LINK_TO_EMAIL_DSC, true); |
|
| 44 | + $this->initVar('to_name', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_TO_NAME, _CO_SOBJECT_LINK_TO_NAME_DSC, true); |
|
| 45 | + $this->initVar('link', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_LINK, _CO_SOBJECT_LINK_LINK_DSC, true); |
|
| 46 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true, 255, '', false, _CO_SOBJECT_LINK_SUBJECT, _CO_SOBJECT_LINK_SUBJECT_DSC, true); |
|
| 47 | + $this->initVar('body', XOBJ_DTYPE_TXTAREA, '', true, null, '', false, _CO_SOBJECT_LINK_BODY, _CO_SOBJECT_LINK_BODY_DSC); |
|
| 48 | + $this->initVar('mid', XOBJ_DTYPE_INT, '', false, null, '', false, _CO_SOBJECT_LINK_MID, _CO_SOBJECT_LINK_MID_DSC); |
|
| 49 | + $this->initVar('mid_name', XOBJ_DTYPE_TXTBOX, '', false, 255, '', false, _CO_SOBJECT_LINK_MID_NAME, _CO_SOBJECT_LINK_MID_NAME_DSC, true); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * returns a specific variable for the object in a proper format |
|
| 54 | + * |
|
| 55 | + * @access public |
|
| 56 | + * @param string $key key of the object's variable to be returned |
|
| 57 | + * @param string $format format to use for the output |
|
| 58 | + * @return mixed formatted value of the variable |
|
| 59 | + */ |
|
| 60 | + public function getVar($key, $format = 's') |
|
| 61 | + { |
|
| 62 | + if ('s' === $format && in_array($key, ['from_uid', 'to_uid', 'date', 'link'])) { |
|
| 63 | + // return call_user_func(array($this, $key)); |
|
| 64 | + return $this->{$key}(); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return parent::getVar($key, $format); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + public function from_uid() |
|
| 74 | + { |
|
| 75 | + $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid', 'e'), 1, null, true); |
|
| 76 | + |
|
| 77 | + return $ret; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @param bool $withContact |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function to_uid($withContact = false) |
|
| 85 | + { |
|
| 86 | + $ret = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid', 'e'), 1, null, true); |
|
| 87 | + |
|
| 88 | + return $ret; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @return string |
|
| 93 | + */ |
|
| 94 | + public function date() |
|
| 95 | + { |
|
| 96 | + $ret = formatTimestamp($this->getVar('date', 'e')); |
|
| 97 | + |
|
| 98 | + return $ret; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param bool $full |
|
| 103 | + * @return mixed|string |
|
| 104 | + */ |
|
| 105 | + public function link($full = false) |
|
| 106 | + { |
|
| 107 | + $ret = $this->getVar('link', 'e'); |
|
| 108 | + if ($full) { |
|
| 109 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 110 | + $ret = $myts->displayTarea($ret); |
|
| 111 | + |
|
| 112 | + return $ret; |
|
| 113 | + } else { |
|
| 114 | + $ret = '<a href="' . $ret . '" alt="' . $this->getVar('link', 'e') . '" title="' . $this->getVar('link', 'e') . '">' . _AM_SOBJECT_SENT_LINKS_GOTO . '</a>'; |
|
| 115 | + |
|
| 116 | + return $ret; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * @return string |
|
| 122 | + */ |
|
| 123 | + public function getViewItemLink() |
|
| 124 | + { |
|
| 125 | + $ret = '<a href="' . SMARTOBJECT_URL . 'admin/link.php?op=view&linkid=' . $this->getVar('linkid') . '"><img src="' . SMARTOBJECT_IMAGES_ACTIONS_URL . 'mail_find.png" alt="' . _AM_SOBJECT_SENT_LINK_VIEW . '" title="' . _AM_SOBJECT_SENT_LINK_VIEW . '"></a>'; |
|
| 126 | + |
|
| 127 | + return $ret; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getFromInfo() |
|
| 134 | + { |
|
| 135 | + // check if from_uid represent a user |
|
| 136 | + |
|
| 137 | + if ($this->getVar('from_uid')) { |
|
| 138 | + $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('from_uid')); |
|
| 139 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 140 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 141 | + } |
|
| 142 | + } else { |
|
| 143 | + $user = '<a href="mailto:' . $this->getVar('from_email') . '">' . $this->getVar('from_email') . '</a>'; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $user; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + public function toArray() |
|
| 153 | + { |
|
| 154 | + $ret = parent::toArray(); |
|
| 155 | + $ret['fromInfo'] = $this->getFromInfo(); |
|
| 156 | + $ret['toInfo'] = $this->getToInfo(); |
|
| 157 | + $ret['fullLink'] = $this->link(true); |
|
| 158 | + |
|
| 159 | + return $ret; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function getToInfo() |
|
| 166 | + { |
|
| 167 | + // check if from_uid represent a user |
|
| 168 | + |
|
| 169 | + if ($this->getVar('to_uid')) { |
|
| 170 | + $user = Smartobject\Utility::getLinkedUnameFromId($this->getVar('to_uid')); |
|
| 171 | + if ($user == $GLOBALS['xoopsConfig']['anonymous']) { |
|
| 172 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 173 | + } |
|
| 174 | + } else { |
|
| 175 | + $user = '<a href="mailto:' . $this->getVar('to_email') . '">' . $this->getVar('to_email') . '</a>'; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $user; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -22,163 +22,163 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class About |
| 24 | 24 | { |
| 25 | - public $_lang_aboutTitle; |
|
| 26 | - public $_lang_author_info; |
|
| 27 | - public $_lang_developer_lead; |
|
| 28 | - public $_lang_developer_contributor; |
|
| 29 | - public $_lang_developer_website; |
|
| 30 | - public $_lang_developer_email; |
|
| 31 | - public $_lang_developer_credits; |
|
| 32 | - public $_lang_module_info; |
|
| 33 | - public $_lang_module_status; |
|
| 34 | - public $_lang_module_release_date; |
|
| 35 | - public $_lang_module_demo; |
|
| 36 | - public $_lang_module_support; |
|
| 37 | - public $_lang_module_bug; |
|
| 38 | - public $_lang_module_submit_bug; |
|
| 39 | - public $_lang_module_feature; |
|
| 40 | - public $_lang_module_submit_feature; |
|
| 41 | - public $_lang_module_disclaimer; |
|
| 42 | - public $_lang_author_word; |
|
| 43 | - public $_lang_version_history; |
|
| 44 | - public $_lang_by; |
|
| 45 | - public $_tpl; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * SmartobjectAbout constructor. |
|
| 49 | - * @param string $aboutTitle |
|
| 50 | - */ |
|
| 51 | - public function __construct($aboutTitle = 'About') |
|
| 52 | - { |
|
| 53 | - global $xoopsModule, $xoopsConfig; |
|
| 54 | - |
|
| 55 | - /** @var Smartobject\Helper $helper */ |
|
| 56 | - $helper = Smartobject\Helper::getInstance(); |
|
| 57 | - $helper->loadLanguage('modinfo'); |
|
| 25 | + public $_lang_aboutTitle; |
|
| 26 | + public $_lang_author_info; |
|
| 27 | + public $_lang_developer_lead; |
|
| 28 | + public $_lang_developer_contributor; |
|
| 29 | + public $_lang_developer_website; |
|
| 30 | + public $_lang_developer_email; |
|
| 31 | + public $_lang_developer_credits; |
|
| 32 | + public $_lang_module_info; |
|
| 33 | + public $_lang_module_status; |
|
| 34 | + public $_lang_module_release_date; |
|
| 35 | + public $_lang_module_demo; |
|
| 36 | + public $_lang_module_support; |
|
| 37 | + public $_lang_module_bug; |
|
| 38 | + public $_lang_module_submit_bug; |
|
| 39 | + public $_lang_module_feature; |
|
| 40 | + public $_lang_module_submit_feature; |
|
| 41 | + public $_lang_module_disclaimer; |
|
| 42 | + public $_lang_author_word; |
|
| 43 | + public $_lang_version_history; |
|
| 44 | + public $_lang_by; |
|
| 45 | + public $_tpl; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * SmartobjectAbout constructor. |
|
| 49 | + * @param string $aboutTitle |
|
| 50 | + */ |
|
| 51 | + public function __construct($aboutTitle = 'About') |
|
| 52 | + { |
|
| 53 | + global $xoopsModule, $xoopsConfig; |
|
| 54 | + |
|
| 55 | + /** @var Smartobject\Helper $helper */ |
|
| 56 | + $helper = Smartobject\Helper::getInstance(); |
|
| 57 | + $helper->loadLanguage('modinfo'); |
|
| 58 | 58 | |
| 59 | - $this->_aboutTitle = $aboutTitle; |
|
| 60 | - |
|
| 61 | - $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
| 62 | - $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
| 63 | - $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
| 64 | - $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
| 65 | - $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
| 66 | - $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
| 67 | - $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
| 68 | - $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
| 69 | - $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
| 70 | - $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
| 71 | - $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
| 72 | - $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
| 73 | - $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
| 74 | - $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
| 75 | - $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
| 76 | - $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param $value |
|
| 81 | - * @return mixed |
|
| 82 | - */ |
|
| 83 | - public function sanitize($value) |
|
| 84 | - { |
|
| 85 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 86 | - |
|
| 87 | - return $myts->displayTarea($value, 1); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function render() |
|
| 91 | - { |
|
| 92 | - /** |
|
| 93 | - * @todo move the output to a template |
|
| 94 | - * @todo make the output XHTML compliant |
|
| 95 | - */ |
|
| 96 | - |
|
| 97 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 98 | - |
|
| 99 | - global $xoopsModule; |
|
| 100 | - |
|
| 101 | - Smartobject\Utility::getXoopsCpHeader(); |
|
| 102 | - |
|
| 103 | - /** @var XoopsModuleHandler $moduleHandler */ |
|
| 104 | - $moduleHandler = xoops_getHandler('module'); |
|
| 105 | - $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
| 106 | - |
|
| 107 | - //Smartobject\Utility::getAdminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
| 108 | - |
|
| 109 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 110 | - |
|
| 111 | - // --- |
|
| 112 | - // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 113 | - // $this->_tpl = new \XoopsTpl(); |
|
| 114 | - $this->_tpl = new \XoopsTpl(); |
|
| 115 | - // --- |
|
| 116 | - |
|
| 117 | - $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
| 118 | - $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
| 119 | - $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
| 120 | - $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
| 121 | - $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
| 122 | - |
|
| 123 | - // Left headings... |
|
| 124 | - if ('' !== $versioninfo->getInfo('author_realname')) { |
|
| 125 | - $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
| 126 | - } else { |
|
| 127 | - $author_name = $versioninfo->getInfo('author'); |
|
| 128 | - } |
|
| 129 | - $this->_tpl->assign('module_author_name', $author_name); |
|
| 130 | - |
|
| 131 | - $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
| 132 | - |
|
| 133 | - $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
| 134 | - |
|
| 135 | - // Developers Information |
|
| 136 | - $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
| 137 | - $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
| 138 | - $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
| 139 | - $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
| 140 | - $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
| 141 | - |
|
| 142 | - $people = $versioninfo->getInfo('people'); |
|
| 143 | - if ($people) { |
|
| 144 | - $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map([$this, 'sanitize'], $people['developers']) : false); |
|
| 145 | - $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map([$this, 'sanitize'], $people['testers']) : false); |
|
| 146 | - $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map([$this, 'sanitize'], $people['translators']) : false); |
|
| 147 | - $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map([$this, 'sanitize'], $people['documenters']) : false); |
|
| 148 | - $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map([$this, 'sanitize'], $people['other']) : false); |
|
| 149 | - } |
|
| 150 | - //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
| 151 | - |
|
| 152 | - // Module Development information |
|
| 153 | - $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
| 154 | - $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
| 155 | - $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
| 156 | - $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
| 157 | - $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
| 158 | - $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
| 159 | - $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
| 160 | - $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
| 161 | - |
|
| 162 | - // Warning |
|
| 163 | - $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
| 164 | - |
|
| 165 | - // Author's note |
|
| 166 | - $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
| 167 | - |
|
| 168 | - // For changelog thanks to 3Dev |
|
| 169 | - global $xoopsModule; |
|
| 170 | - $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
| 171 | - if (is_file($filename)) { |
|
| 172 | - $filesize = filesize($filename); |
|
| 173 | - $handle = fopen($filename, 'r'); |
|
| 174 | - $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
| 175 | - fclose($handle); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $this->_tpl->display('db:smartobject_about.tpl'); |
|
| 179 | - |
|
| 180 | - Smartobject\Utility::getModFooter(); |
|
| 181 | - |
|
| 182 | - xoops_cp_footer(); |
|
| 183 | - } |
|
| 59 | + $this->_aboutTitle = $aboutTitle; |
|
| 60 | + |
|
| 61 | + $this->_lang_developer_contributor = _CO_SOBJECT_DEVELOPER_CONTRIBUTOR; |
|
| 62 | + $this->_lang_developer_website = _CO_SOBJECT_DEVELOPER_WEBSITE; |
|
| 63 | + $this->_lang_developer_email = _CO_SOBJECT_DEVELOPER_EMAIL; |
|
| 64 | + $this->_lang_developer_credits = _CO_SOBJECT_DEVELOPER_CREDITS; |
|
| 65 | + $this->_lang_module_info = _CO_SOBJECT_MODULE_INFO; |
|
| 66 | + $this->_lang_module_status = _CO_SOBJECT_MODULE_STATUS; |
|
| 67 | + $this->_lang_module_release_date = _CO_SOBJECT_MODULE_RELEASE_DATE; |
|
| 68 | + $this->_lang_module_demo = _CO_SOBJECT_MODULE_DEMO; |
|
| 69 | + $this->_lang_module_support = _CO_SOBJECT_MODULE_SUPPORT; |
|
| 70 | + $this->_lang_module_bug = _CO_SOBJECT_MODULE_BUG; |
|
| 71 | + $this->_lang_module_submit_bug = _CO_SOBJECT_MODULE_SUBMIT_BUG; |
|
| 72 | + $this->_lang_module_feature = _CO_SOBJECT_MODULE_FEATURE; |
|
| 73 | + $this->_lang_module_submit_feature = _CO_SOBJECT_MODULE_SUBMIT_FEATURE; |
|
| 74 | + $this->_lang_module_disclaimer = _CO_SOBJECT_MODULE_DISCLAIMER; |
|
| 75 | + $this->_lang_author_word = _CO_SOBJECT_AUTHOR_WORD; |
|
| 76 | + $this->_lang_version_history = _CO_SOBJECT_VERSION_HISTORY; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param $value |
|
| 81 | + * @return mixed |
|
| 82 | + */ |
|
| 83 | + public function sanitize($value) |
|
| 84 | + { |
|
| 85 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 86 | + |
|
| 87 | + return $myts->displayTarea($value, 1); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function render() |
|
| 91 | + { |
|
| 92 | + /** |
|
| 93 | + * @todo move the output to a template |
|
| 94 | + * @todo make the output XHTML compliant |
|
| 95 | + */ |
|
| 96 | + |
|
| 97 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 98 | + |
|
| 99 | + global $xoopsModule; |
|
| 100 | + |
|
| 101 | + Smartobject\Utility::getXoopsCpHeader(); |
|
| 102 | + |
|
| 103 | + /** @var XoopsModuleHandler $moduleHandler */ |
|
| 104 | + $moduleHandler = xoops_getHandler('module'); |
|
| 105 | + $versioninfo = $moduleHandler->get($xoopsModule->getVar('mid')); |
|
| 106 | + |
|
| 107 | + //Smartobject\Utility::getAdminMenu(-1, $this->_aboutTitle . " " . $versioninfo->getInfo('name')); |
|
| 108 | + |
|
| 109 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 110 | + |
|
| 111 | + // --- |
|
| 112 | + // 2012-01-01 PHP 5.3: Assigning the return value of new by reference is now deprecated. |
|
| 113 | + // $this->_tpl = new \XoopsTpl(); |
|
| 114 | + $this->_tpl = new \XoopsTpl(); |
|
| 115 | + // --- |
|
| 116 | + |
|
| 117 | + $this->_tpl->assign('module_url', XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/'); |
|
| 118 | + $this->_tpl->assign('module_image', $versioninfo->getInfo('image')); |
|
| 119 | + $this->_tpl->assign('module_name', $versioninfo->getInfo('name')); |
|
| 120 | + $this->_tpl->assign('module_version', $versioninfo->getInfo('version')); |
|
| 121 | + $this->_tpl->assign('module_status_version', $versioninfo->getInfo('status_version')); |
|
| 122 | + |
|
| 123 | + // Left headings... |
|
| 124 | + if ('' !== $versioninfo->getInfo('author_realname')) { |
|
| 125 | + $author_name = $versioninfo->getInfo('author') . ' (' . $versioninfo->getInfo('author_realname') . ')'; |
|
| 126 | + } else { |
|
| 127 | + $author_name = $versioninfo->getInfo('author'); |
|
| 128 | + } |
|
| 129 | + $this->_tpl->assign('module_author_name', $author_name); |
|
| 130 | + |
|
| 131 | + $this->_tpl->assign('module_license', $versioninfo->getInfo('license')); |
|
| 132 | + |
|
| 133 | + $this->_tpl->assign('module_credits', $versioninfo->getInfo('credits')); |
|
| 134 | + |
|
| 135 | + // Developers Information |
|
| 136 | + $this->_tpl->assign('module_developer_lead', $versioninfo->getInfo('developer_lead')); |
|
| 137 | + $this->_tpl->assign('module_developer_contributor', $versioninfo->getInfo('developer_contributor')); |
|
| 138 | + $this->_tpl->assign('module_developer_website_url', $versioninfo->getInfo('developer_website_url')); |
|
| 139 | + $this->_tpl->assign('module_developer_website_name', $versioninfo->getInfo('developer_website_name')); |
|
| 140 | + $this->_tpl->assign('module_developer_email', $versioninfo->getInfo('developer_email')); |
|
| 141 | + |
|
| 142 | + $people = $versioninfo->getInfo('people'); |
|
| 143 | + if ($people) { |
|
| 144 | + $this->_tpl->assign('module_people_developers', isset($people['developers']) ? array_map([$this, 'sanitize'], $people['developers']) : false); |
|
| 145 | + $this->_tpl->assign('module_people_testers', isset($people['testers']) ? array_map([$this, 'sanitize'], $people['testers']) : false); |
|
| 146 | + $this->_tpl->assign('module_people_translators', isset($people['translators']) ? array_map([$this, 'sanitize'], $people['translators']) : false); |
|
| 147 | + $this->_tpl->assign('module_people_documenters', isset($people['documenters']) ? array_map([$this, 'sanitize'], $people['documenters']) : false); |
|
| 148 | + $this->_tpl->assign('module_people_other', isset($people['other']) ? array_map([$this, 'sanitize'], $people['other']) : false); |
|
| 149 | + } |
|
| 150 | + //$this->_tpl->assign('module_developers', $versioninfo->getInfo('developer_email')); |
|
| 151 | + |
|
| 152 | + // Module Development information |
|
| 153 | + $this->_tpl->assign('module_date', $versioninfo->getInfo('date')); |
|
| 154 | + $this->_tpl->assign('module_status', $versioninfo->getInfo('status')); |
|
| 155 | + $this->_tpl->assign('module_demo_site_url', $versioninfo->getInfo('demo_site_url')); |
|
| 156 | + $this->_tpl->assign('module_demo_site_name', $versioninfo->getInfo('demo_site_name')); |
|
| 157 | + $this->_tpl->assign('module_support_site_url', $versioninfo->getInfo('support_site_url')); |
|
| 158 | + $this->_tpl->assign('module_support_site_name', $versioninfo->getInfo('support_site_name')); |
|
| 159 | + $this->_tpl->assign('module_submit_bug', $versioninfo->getInfo('submit_bug')); |
|
| 160 | + $this->_tpl->assign('module_submit_feature', $versioninfo->getInfo('submit_feature')); |
|
| 161 | + |
|
| 162 | + // Warning |
|
| 163 | + $this->_tpl->assign('module_warning', $this->sanitize($versioninfo->getInfo('warning'))); |
|
| 164 | + |
|
| 165 | + // Author's note |
|
| 166 | + $this->_tpl->assign('module_author_word', $versioninfo->getInfo('author_word')); |
|
| 167 | + |
|
| 168 | + // For changelog thanks to 3Dev |
|
| 169 | + global $xoopsModule; |
|
| 170 | + $filename = XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/changelog.txt'; |
|
| 171 | + if (is_file($filename)) { |
|
| 172 | + $filesize = filesize($filename); |
|
| 173 | + $handle = fopen($filename, 'r'); |
|
| 174 | + $this->_tpl->assign('module_version_history', $myts->displayTarea(fread($handle, $filesize), true)); |
|
| 175 | + fclose($handle); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $this->_tpl->display('db:smartobject_about.tpl'); |
|
| 179 | + |
|
| 180 | + Smartobject\Utility::getModFooter(); |
|
| 181 | + |
|
| 182 | + xoops_cp_footer(); |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -40,548 +40,548 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | class SmartObjectForm extends \XoopsThemeForm |
| 42 | 42 | { |
| 43 | - public $targetObject = null; |
|
| 44 | - public $form_fields = null; |
|
| 45 | - public $_cancel_js_action = false; |
|
| 46 | - public $_custom_button = false; |
|
| 47 | - public $_captcha = false; |
|
| 48 | - public $_form_name = false; |
|
| 49 | - public $_form_caption = false; |
|
| 50 | - public $_submit_button_caption = false; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * SmartobjectForm constructor. |
|
| 54 | - * @param string $target |
|
| 55 | - * @param string $form_name |
|
| 56 | - * @param string $form_caption |
|
| 57 | - * @param string $form_action |
|
| 58 | - * @param null $form_fields |
|
| 59 | - * @param bool $submit_button_caption |
|
| 60 | - * @param bool $cancel_js_action |
|
| 61 | - * @param bool $captcha |
|
| 62 | - */ |
|
| 63 | - public function __construct( |
|
| 64 | - &$target, |
|
| 65 | - $form_name, |
|
| 66 | - $form_caption, |
|
| 67 | - $form_action, |
|
| 68 | - $form_fields = null, |
|
| 69 | - $submit_button_caption = false, |
|
| 70 | - $cancel_js_action = false, |
|
| 71 | - $captcha = false |
|
| 72 | - ) { |
|
| 73 | - $this->targetObject =& $target; |
|
| 74 | - $this->form_fields = $form_fields; |
|
| 75 | - $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | - $this->_captcha = $captcha; |
|
| 77 | - $this->_form_name = $form_name; |
|
| 78 | - $this->_form_caption = $form_caption; |
|
| 79 | - $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | - |
|
| 81 | - if (!isset($form_action)) { |
|
| 82 | - $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | - $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | - |
|
| 88 | - $this->createElements(); |
|
| 89 | - |
|
| 90 | - if ($captcha) { |
|
| 91 | - $this->addCaptcha(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $this->createPermissionControls(); |
|
| 95 | - |
|
| 96 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - public function addCaptcha() |
|
| 100 | - { |
|
| 101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | - $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param $name |
|
| 107 | - * @param $caption |
|
| 108 | - * @param bool $onclick |
|
| 109 | - */ |
|
| 110 | - public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | - { |
|
| 112 | - $custom_button_array = [ |
|
| 113 | - 'name' => $name, |
|
| 114 | - 'caption' => $caption, |
|
| 115 | - 'onclick' => $onclick |
|
| 116 | - ]; |
|
| 117 | - $this->_custom_button[] = $custom_button_array; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Add an element to the form |
|
| 122 | - * |
|
| 123 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | - * @param bool $key |
|
| 125 | - * @param bool $var |
|
| 126 | - * @param bool|string $required is this a "required" element? |
|
| 127 | - */ |
|
| 128 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | - { |
|
| 130 | - if ($key) { |
|
| 131 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | - $formElement->setExtra('disabled="disabled"'); |
|
| 133 | - $formElement->setName($key . '-readonly'); |
|
| 134 | - // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | - $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | - $this->addElement($hidden); |
|
| 137 | - } |
|
| 138 | - $formElement->setDescription($var['form_dsc']); |
|
| 139 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | - $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | - $this->addElement($hidden); |
|
| 142 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | - } else { |
|
| 146 | - if (isset($var['form_extra'])) { |
|
| 147 | - $formElement->setExtra($var['form_extra']); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - $controls = $this->targetObject->controls; |
|
| 151 | - if (isset($controls[$key]['js'])) { |
|
| 152 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | - } |
|
| 154 | - parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | - } else { |
|
| 156 | - parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | - } |
|
| 158 | - unset($formElement); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function createElements() |
|
| 162 | - { |
|
| 163 | - $controls = $this->targetObject->controls; |
|
| 164 | - $vars = $this->targetObject->vars; |
|
| 165 | - foreach ($vars as $key => $var) { |
|
| 166 | - |
|
| 167 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | - // need to be displayed, then we only create an hidden field |
|
| 169 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | - $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | - $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | - unset($elementToAdd); |
|
| 173 | - // If not, the we need to create the proper form control for this fields |
|
| 174 | - } else { |
|
| 175 | - // If this field has a specific control, we will use it |
|
| 176 | - |
|
| 177 | - if ('parentid' === $key) { |
|
| 178 | - /** |
|
| 179 | - * Why this ? |
|
| 180 | - */ |
|
| 181 | - } |
|
| 182 | - if (isset($controls[$key])) { |
|
| 183 | - /* If the control has name, it's because it's an object already present in the script |
|
| 43 | + public $targetObject = null; |
|
| 44 | + public $form_fields = null; |
|
| 45 | + public $_cancel_js_action = false; |
|
| 46 | + public $_custom_button = false; |
|
| 47 | + public $_captcha = false; |
|
| 48 | + public $_form_name = false; |
|
| 49 | + public $_form_caption = false; |
|
| 50 | + public $_submit_button_caption = false; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * SmartobjectForm constructor. |
|
| 54 | + * @param string $target |
|
| 55 | + * @param string $form_name |
|
| 56 | + * @param string $form_caption |
|
| 57 | + * @param string $form_action |
|
| 58 | + * @param null $form_fields |
|
| 59 | + * @param bool $submit_button_caption |
|
| 60 | + * @param bool $cancel_js_action |
|
| 61 | + * @param bool $captcha |
|
| 62 | + */ |
|
| 63 | + public function __construct( |
|
| 64 | + &$target, |
|
| 65 | + $form_name, |
|
| 66 | + $form_caption, |
|
| 67 | + $form_action, |
|
| 68 | + $form_fields = null, |
|
| 69 | + $submit_button_caption = false, |
|
| 70 | + $cancel_js_action = false, |
|
| 71 | + $captcha = false |
|
| 72 | + ) { |
|
| 73 | + $this->targetObject =& $target; |
|
| 74 | + $this->form_fields = $form_fields; |
|
| 75 | + $this->_cancel_js_action = $cancel_js_action; |
|
| 76 | + $this->_captcha = $captcha; |
|
| 77 | + $this->_form_name = $form_name; |
|
| 78 | + $this->_form_caption = $form_caption; |
|
| 79 | + $this->_submit_button_caption = $submit_button_caption; |
|
| 80 | + |
|
| 81 | + if (!isset($form_action)) { |
|
| 82 | + $form_action = xoops_getenv('PHP_SELF'); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
| 86 | + $this->setExtra('enctype="multipart/form-data"'); |
|
| 87 | + |
|
| 88 | + $this->createElements(); |
|
| 89 | + |
|
| 90 | + if ($captcha) { |
|
| 91 | + $this->addCaptcha(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $this->createPermissionControls(); |
|
| 95 | + |
|
| 96 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + public function addCaptcha() |
|
| 100 | + { |
|
| 101 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
| 102 | + $this->addElement(new \XoopsFormCaptcha(), true); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param $name |
|
| 107 | + * @param $caption |
|
| 108 | + * @param bool $onclick |
|
| 109 | + */ |
|
| 110 | + public function addCustomButton($name, $caption, $onclick = false) |
|
| 111 | + { |
|
| 112 | + $custom_button_array = [ |
|
| 113 | + 'name' => $name, |
|
| 114 | + 'caption' => $caption, |
|
| 115 | + 'onclick' => $onclick |
|
| 116 | + ]; |
|
| 117 | + $this->_custom_button[] = $custom_button_array; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Add an element to the form |
|
| 122 | + * |
|
| 123 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
| 124 | + * @param bool $key |
|
| 125 | + * @param bool $var |
|
| 126 | + * @param bool|string $required is this a "required" element? |
|
| 127 | + */ |
|
| 128 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
| 129 | + { |
|
| 130 | + if ($key) { |
|
| 131 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
| 132 | + $formElement->setExtra('disabled="disabled"'); |
|
| 133 | + $formElement->setName($key . '-readonly'); |
|
| 134 | + // Since this element is disable, we still want to pass it's value in the form |
|
| 135 | + $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
| 136 | + $this->addElement($hidden); |
|
| 137 | + } |
|
| 138 | + $formElement->setDescription($var['form_dsc']); |
|
| 139 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
| 140 | + $hidden = new \XoopsFormHidden('changedField', false); |
|
| 141 | + $this->addElement($hidden); |
|
| 142 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
| 143 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
| 144 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
| 145 | + } else { |
|
| 146 | + if (isset($var['form_extra'])) { |
|
| 147 | + $formElement->setExtra($var['form_extra']); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + $controls = $this->targetObject->controls; |
|
| 151 | + if (isset($controls[$key]['js'])) { |
|
| 152 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
| 153 | + } |
|
| 154 | + parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
| 155 | + } else { |
|
| 156 | + parent::addElement($formElement, 'notset' === $required ? false : true); |
|
| 157 | + } |
|
| 158 | + unset($formElement); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function createElements() |
|
| 162 | + { |
|
| 163 | + $controls = $this->targetObject->controls; |
|
| 164 | + $vars = $this->targetObject->vars; |
|
| 165 | + foreach ($vars as $key => $var) { |
|
| 166 | + |
|
| 167 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
| 168 | + // need to be displayed, then we only create an hidden field |
|
| 169 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
| 170 | + $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
| 171 | + $this->addElement($elementToAdd, $key, $var, false); |
|
| 172 | + unset($elementToAdd); |
|
| 173 | + // If not, the we need to create the proper form control for this fields |
|
| 174 | + } else { |
|
| 175 | + // If this field has a specific control, we will use it |
|
| 176 | + |
|
| 177 | + if ('parentid' === $key) { |
|
| 178 | + /** |
|
| 179 | + * Why this ? |
|
| 180 | + */ |
|
| 181 | + } |
|
| 182 | + if (isset($controls[$key])) { |
|
| 183 | + /* If the control has name, it's because it's an object already present in the script |
|
| 184 | 184 | * for example, "user" |
| 185 | 185 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
| 186 | 186 | */ |
| 187 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | - $controls[$key]['name'] = 'select'; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | - |
|
| 193 | - // Adding on the form, the control for this field |
|
| 194 | - $this->addElement($form_select, $key, $var); |
|
| 195 | - unset($form_select); |
|
| 196 | - |
|
| 197 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | - } else { |
|
| 199 | - switch ($var['data_type']) { |
|
| 200 | - |
|
| 201 | - case XOBJ_DTYPE_TXTBOX: |
|
| 202 | - |
|
| 203 | - $form_text = $this->getControl('text', $key); |
|
| 204 | - $this->addElement($form_text, $key, $var); |
|
| 205 | - unset($form_text); |
|
| 206 | - break; |
|
| 207 | - |
|
| 208 | - case XOBJ_DTYPE_INT: |
|
| 209 | - $this->targetObject->setControl($key, [ |
|
| 210 | - 'name' => 'text', |
|
| 211 | - 'size' => '5' |
|
| 212 | - ]); |
|
| 213 | - $form_text = $this->getControl('text', $key); |
|
| 214 | - $this->addElement($form_text, $key, $var); |
|
| 215 | - unset($form_text); |
|
| 216 | - break; |
|
| 217 | - |
|
| 218 | - case XOBJ_DTYPE_FLOAT: |
|
| 219 | - $this->targetObject->setControl($key, [ |
|
| 220 | - 'name' => 'text', |
|
| 221 | - 'size' => '5' |
|
| 222 | - ]); |
|
| 223 | - $form_text = $this->getControl('text', $key); |
|
| 224 | - $this->addElement($form_text, $key, $var); |
|
| 225 | - unset($form_text); |
|
| 226 | - break; |
|
| 227 | - |
|
| 228 | - case XOBJ_DTYPE_LTIME: |
|
| 229 | - $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | - $this->addElement($form_date_time, $key, $var); |
|
| 231 | - unset($form_date_time); |
|
| 232 | - break; |
|
| 233 | - |
|
| 234 | - case XOBJ_DTYPE_STIME: |
|
| 235 | - $form_date_time = $this->getControl('date', $key); |
|
| 236 | - $this->addElement($form_date_time, $key, $var); |
|
| 237 | - unset($form_date_time); |
|
| 238 | - break; |
|
| 239 | - |
|
| 240 | - case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | - $form_time = $this->getControl('time', $key); |
|
| 242 | - $this->addElement($form_time, $key, $var); |
|
| 243 | - unset($form_time); |
|
| 244 | - break; |
|
| 245 | - |
|
| 246 | - case XOBJ_DTYPE_CURRENCY: |
|
| 247 | - $this->targetObject->setControl($key, [ |
|
| 248 | - 'name' => 'text', |
|
| 249 | - 'size' => '15' |
|
| 250 | - ]); |
|
| 251 | - $form_currency = $this->getControl('text', $key); |
|
| 252 | - $this->addElement($form_currency, $key, $var); |
|
| 253 | - unset($form_currency); |
|
| 254 | - break; |
|
| 255 | - |
|
| 256 | - case XOBJ_DTYPE_URLLINK: |
|
| 257 | - $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | - $this->addElement($form_urllink, $key, $var); |
|
| 259 | - unset($form_urllink); |
|
| 260 | - break; |
|
| 261 | - |
|
| 262 | - case XOBJ_DTYPE_FILE: |
|
| 263 | - $form_file = $this->getControl('richfile', $key); |
|
| 264 | - $this->addElement($form_file, $key, $var); |
|
| 265 | - unset($form_file); |
|
| 266 | - break; |
|
| 267 | - |
|
| 268 | - case XOBJ_DTYPE_TXTAREA: |
|
| 269 | - |
|
| 270 | - $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | - $this->addElement($form_text_area, $key, $var); |
|
| 272 | - unset($form_text_area); |
|
| 273 | - break; |
|
| 274 | - |
|
| 275 | - case XOBJ_DTYPE_ARRAY: |
|
| 276 | - // TODO: To come... |
|
| 277 | - break; |
|
| 278 | - case XOBJ_DTYPE_SOURCE: |
|
| 279 | - // TODO: To come... |
|
| 280 | - break; |
|
| 281 | - case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | - $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | - $this->addElement($section_control, $key, $var); |
|
| 284 | - unset($section_control); |
|
| 285 | - break; |
|
| 286 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | - $this->addElement($section_control, $key, $var); |
|
| 289 | - unset($section_control); |
|
| 290 | - break; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - // Add an hidden field to store the URL of the page before this form |
|
| 296 | - $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm())); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - public function createPermissionControls() |
|
| 300 | - { |
|
| 301 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | - |
|
| 303 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | - |
|
| 305 | - if ($permissions) { |
|
| 306 | - $memberHandler = xoops_getHandler('member'); |
|
| 307 | - $group_list = $memberHandler->getGroupList(); |
|
| 308 | - asort($group_list); |
|
| 309 | - foreach ($permissions as $permission) { |
|
| 310 | - if ($this->targetObject->isNew()) { |
|
| 311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | - } |
|
| 317 | - $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | - $groups_select->setDescription($permission['description']); |
|
| 319 | - $groups_select->addOptionArray($group_list); |
|
| 320 | - $this->addElement($groups_select); |
|
| 321 | - unset($groups_select); |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @param $form_name |
|
| 328 | - * @param $form_caption |
|
| 329 | - * @param bool $submit_button_caption |
|
| 330 | - */ |
|
| 331 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | - { |
|
| 333 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | - $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | - if (!$submit_button_caption) { |
|
| 336 | - if ($this->targetObject->isNew()) { |
|
| 337 | - $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | - } else { |
|
| 339 | - $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | - } |
|
| 341 | - } else { |
|
| 342 | - $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | - } |
|
| 344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | - $button_tray->addElement($butt_create); |
|
| 346 | - |
|
| 347 | - //creating custom buttons |
|
| 348 | - if ($this->_custom_button) { |
|
| 349 | - foreach ($this->_custom_button as $custom_button) { |
|
| 350 | - $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | - if ($custom_button['onclick']) { |
|
| 352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | - } |
|
| 354 | - $button_tray->addElement($butt_custom); |
|
| 355 | - unset($butt_custom); |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // creating the "cancel" button |
|
| 360 | - $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | - if ($this->_cancel_js_action) { |
|
| 362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | - } else { |
|
| 364 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | - } |
|
| 366 | - $button_tray->addElement($butt_cancel); |
|
| 367 | - |
|
| 368 | - $this->addElement($button_tray); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * @param $controlName |
|
| 373 | - * @param $key |
|
| 374 | - * @return \XoopsFormLabel |
|
| 375 | - */ |
|
| 376 | - public function getControl($controlName, $key) |
|
| 377 | - { |
|
| 378 | - switch ($controlName) { |
|
| 379 | - case 'check': |
|
| 187 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
| 188 | + $controls[$key]['name'] = 'select'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
| 192 | + |
|
| 193 | + // Adding on the form, the control for this field |
|
| 194 | + $this->addElement($form_select, $key, $var); |
|
| 195 | + unset($form_select); |
|
| 196 | + |
|
| 197 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
| 198 | + } else { |
|
| 199 | + switch ($var['data_type']) { |
|
| 200 | + |
|
| 201 | + case XOBJ_DTYPE_TXTBOX: |
|
| 202 | + |
|
| 203 | + $form_text = $this->getControl('text', $key); |
|
| 204 | + $this->addElement($form_text, $key, $var); |
|
| 205 | + unset($form_text); |
|
| 206 | + break; |
|
| 207 | + |
|
| 208 | + case XOBJ_DTYPE_INT: |
|
| 209 | + $this->targetObject->setControl($key, [ |
|
| 210 | + 'name' => 'text', |
|
| 211 | + 'size' => '5' |
|
| 212 | + ]); |
|
| 213 | + $form_text = $this->getControl('text', $key); |
|
| 214 | + $this->addElement($form_text, $key, $var); |
|
| 215 | + unset($form_text); |
|
| 216 | + break; |
|
| 217 | + |
|
| 218 | + case XOBJ_DTYPE_FLOAT: |
|
| 219 | + $this->targetObject->setControl($key, [ |
|
| 220 | + 'name' => 'text', |
|
| 221 | + 'size' => '5' |
|
| 222 | + ]); |
|
| 223 | + $form_text = $this->getControl('text', $key); |
|
| 224 | + $this->addElement($form_text, $key, $var); |
|
| 225 | + unset($form_text); |
|
| 226 | + break; |
|
| 227 | + |
|
| 228 | + case XOBJ_DTYPE_LTIME: |
|
| 229 | + $form_date_time = $this->getControl('date_time', $key); |
|
| 230 | + $this->addElement($form_date_time, $key, $var); |
|
| 231 | + unset($form_date_time); |
|
| 232 | + break; |
|
| 233 | + |
|
| 234 | + case XOBJ_DTYPE_STIME: |
|
| 235 | + $form_date_time = $this->getControl('date', $key); |
|
| 236 | + $this->addElement($form_date_time, $key, $var); |
|
| 237 | + unset($form_date_time); |
|
| 238 | + break; |
|
| 239 | + |
|
| 240 | + case XOBJ_DTYPE_TIME_ONLY: |
|
| 241 | + $form_time = $this->getControl('time', $key); |
|
| 242 | + $this->addElement($form_time, $key, $var); |
|
| 243 | + unset($form_time); |
|
| 244 | + break; |
|
| 245 | + |
|
| 246 | + case XOBJ_DTYPE_CURRENCY: |
|
| 247 | + $this->targetObject->setControl($key, [ |
|
| 248 | + 'name' => 'text', |
|
| 249 | + 'size' => '15' |
|
| 250 | + ]); |
|
| 251 | + $form_currency = $this->getControl('text', $key); |
|
| 252 | + $this->addElement($form_currency, $key, $var); |
|
| 253 | + unset($form_currency); |
|
| 254 | + break; |
|
| 255 | + |
|
| 256 | + case XOBJ_DTYPE_URLLINK: |
|
| 257 | + $form_urllink = $this->getControl('urllink', $key); |
|
| 258 | + $this->addElement($form_urllink, $key, $var); |
|
| 259 | + unset($form_urllink); |
|
| 260 | + break; |
|
| 261 | + |
|
| 262 | + case XOBJ_DTYPE_FILE: |
|
| 263 | + $form_file = $this->getControl('richfile', $key); |
|
| 264 | + $this->addElement($form_file, $key, $var); |
|
| 265 | + unset($form_file); |
|
| 266 | + break; |
|
| 267 | + |
|
| 268 | + case XOBJ_DTYPE_TXTAREA: |
|
| 269 | + |
|
| 270 | + $form_text_area = $this->getTextArea($key, $var); |
|
| 271 | + $this->addElement($form_text_area, $key, $var); |
|
| 272 | + unset($form_text_area); |
|
| 273 | + break; |
|
| 274 | + |
|
| 275 | + case XOBJ_DTYPE_ARRAY: |
|
| 276 | + // TODO: To come... |
|
| 277 | + break; |
|
| 278 | + case XOBJ_DTYPE_SOURCE: |
|
| 279 | + // TODO: To come... |
|
| 280 | + break; |
|
| 281 | + case XOBJ_DTYPE_FORM_SECTION: |
|
| 282 | + $section_control = new SmartFormSection($key, $var['value']); |
|
| 283 | + $this->addElement($section_control, $key, $var); |
|
| 284 | + unset($section_control); |
|
| 285 | + break; |
|
| 286 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
| 287 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
| 288 | + $this->addElement($section_control, $key, $var); |
|
| 289 | + unset($section_control); |
|
| 290 | + break; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + // Add an hidden field to store the URL of the page before this form |
|
| 296 | + $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm())); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + public function createPermissionControls() |
|
| 300 | + { |
|
| 301 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
| 302 | + |
|
| 303 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
| 304 | + |
|
| 305 | + if ($permissions) { |
|
| 306 | + $memberHandler = xoops_getHandler('member'); |
|
| 307 | + $group_list = $memberHandler->getGroupList(); |
|
| 308 | + asort($group_list); |
|
| 309 | + foreach ($permissions as $permission) { |
|
| 310 | + if ($this->targetObject->isNew()) { |
|
| 311 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
| 312 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
| 316 | + } |
|
| 317 | + $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
| 318 | + $groups_select->setDescription($permission['description']); |
|
| 319 | + $groups_select->addOptionArray($group_list); |
|
| 320 | + $this->addElement($groups_select); |
|
| 321 | + unset($groups_select); |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @param $form_name |
|
| 328 | + * @param $form_caption |
|
| 329 | + * @param bool $submit_button_caption |
|
| 330 | + */ |
|
| 331 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
| 332 | + { |
|
| 333 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
| 334 | + $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
| 335 | + if (!$submit_button_caption) { |
|
| 336 | + if ($this->targetObject->isNew()) { |
|
| 337 | + $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
| 338 | + } else { |
|
| 339 | + $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
| 340 | + } |
|
| 341 | + } else { |
|
| 342 | + $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
| 343 | + } |
|
| 344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
| 345 | + $button_tray->addElement($butt_create); |
|
| 346 | + |
|
| 347 | + //creating custom buttons |
|
| 348 | + if ($this->_custom_button) { |
|
| 349 | + foreach ($this->_custom_button as $custom_button) { |
|
| 350 | + $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
| 351 | + if ($custom_button['onclick']) { |
|
| 352 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
| 353 | + } |
|
| 354 | + $button_tray->addElement($butt_custom); |
|
| 355 | + unset($butt_custom); |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + // creating the "cancel" button |
|
| 360 | + $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
| 361 | + if ($this->_cancel_js_action) { |
|
| 362 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
| 363 | + } else { |
|
| 364 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
| 365 | + } |
|
| 366 | + $button_tray->addElement($butt_cancel); |
|
| 367 | + |
|
| 368 | + $this->addElement($button_tray); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * @param $controlName |
|
| 373 | + * @param $key |
|
| 374 | + * @return \XoopsFormLabel |
|
| 375 | + */ |
|
| 376 | + public function getControl($controlName, $key) |
|
| 377 | + { |
|
| 378 | + switch ($controlName) { |
|
| 379 | + case 'check': |
|
| 380 | 380 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
| 381 | - $control = $this->targetObject->getControl($key); |
|
| 382 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | - $controlObj->addOptionArray($control['options']); |
|
| 381 | + $control = $this->targetObject->getControl($key); |
|
| 382 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 383 | + $controlObj->addOptionArray($control['options']); |
|
| 384 | 384 | |
| 385 | - return $controlObj; |
|
| 386 | - break; |
|
| 385 | + return $controlObj; |
|
| 386 | + break; |
|
| 387 | 387 | |
| 388 | - case 'color': |
|
| 389 | - $control = $this->targetObject->getControl($key); |
|
| 390 | - $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 388 | + case 'color': |
|
| 389 | + $control = $this->targetObject->getControl($key); |
|
| 390 | + $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 391 | 391 | |
| 392 | - return $controlObj; |
|
| 393 | - break; |
|
| 392 | + return $controlObj; |
|
| 393 | + break; |
|
| 394 | 394 | |
| 395 | - case 'radio': |
|
| 396 | - $control = $this->targetObject->getControl($key); |
|
| 395 | + case 'radio': |
|
| 396 | + $control = $this->targetObject->getControl($key); |
|
| 397 | 397 | |
| 398 | - $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | - $controlObj->addOptionArray($control['options']); |
|
| 398 | + $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 399 | + $controlObj->addOptionArray($control['options']); |
|
| 400 | 400 | |
| 401 | - return $controlObj; |
|
| 402 | - break; |
|
| 401 | + return $controlObj; |
|
| 402 | + break; |
|
| 403 | 403 | |
| 404 | - case 'label': |
|
| 405 | - return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | - break; |
|
| 404 | + case 'label': |
|
| 405 | + return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
| 406 | + break; |
|
| 407 | 407 | |
| 408 | - case 'textarea': |
|
| 409 | - return $this->getTextArea($key); |
|
| 408 | + case 'textarea': |
|
| 409 | + return $this->getTextArea($key); |
|
| 410 | 410 | |
| 411 | - case 'theme': |
|
| 412 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 411 | + case 'theme': |
|
| 412 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
| 413 | 413 | |
| 414 | - case 'theme_multi': |
|
| 415 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | - break; |
|
| 414 | + case 'theme_multi': |
|
| 415 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
| 416 | + break; |
|
| 417 | 417 | |
| 418 | - case 'timezone': |
|
| 419 | - return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | - break; |
|
| 418 | + case 'timezone': |
|
| 419 | + return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
| 420 | + break; |
|
| 421 | 421 | |
| 422 | - case 'group': |
|
| 423 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | - break; |
|
| 422 | + case 'group': |
|
| 423 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
| 424 | + break; |
|
| 425 | 425 | |
| 426 | - case 'group_multi': |
|
| 427 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | - break; |
|
| 426 | + case 'group_multi': |
|
| 427 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 428 | + break; |
|
| 429 | 429 | |
| 430 | - /*case 'user': |
|
| 430 | + /*case 'user': |
|
| 431 | 431 | return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
| 432 | 432 | break;*/ |
| 433 | 433 | |
| 434 | - case 'user_multi': |
|
| 435 | - return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | - break; |
|
| 434 | + case 'user_multi': |
|
| 435 | + return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
| 436 | + break; |
|
| 437 | 437 | |
| 438 | - case 'password': |
|
| 439 | - return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | - break; |
|
| 438 | + case 'password': |
|
| 439 | + return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
| 440 | + break; |
|
| 441 | 441 | |
| 442 | - case 'country': |
|
| 443 | - return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | - break; |
|
| 442 | + case 'country': |
|
| 443 | + return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
| 444 | + break; |
|
| 445 | 445 | |
| 446 | - case 'urllink': |
|
| 446 | + case 'urllink': |
|
| 447 | 447 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
| 448 | 448 | |
| 449 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | - break; |
|
| 449 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
| 450 | + break; |
|
| 451 | 451 | |
| 452 | - case 'richfile': |
|
| 452 | + case 'richfile': |
|
| 453 | 453 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
| 454 | 454 | |
| 455 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | - break; |
|
| 457 | - case 'section': |
|
| 455 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
| 456 | + break; |
|
| 457 | + case 'section': |
|
| 458 | 458 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
| 459 | 459 | |
| 460 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | - break; |
|
| 460 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
| 461 | + break; |
|
| 462 | 462 | |
| 463 | - default: |
|
| 464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | - if (!class_exists($classname)) { |
|
| 466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 463 | + default: |
|
| 464 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
| 465 | + if (!class_exists($classname)) { |
|
| 466 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
| 467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
| 468 | - } else { |
|
| 469 | - // perhaps this is a control created by the module |
|
| 470 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | - $classFileName = strtolower($classname) . '.php'; |
|
| 474 | - |
|
| 475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 468 | + } else { |
|
| 469 | + // perhaps this is a control created by the module |
|
| 470 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
| 471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
| 472 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
| 473 | + $classFileName = strtolower($classname) . '.php'; |
|
| 474 | + |
|
| 475 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
| 476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
| 477 | - } else { |
|
| 478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | - |
|
| 480 | - return new \XoopsFormLabel(); //Empty object |
|
| 481 | - } |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - return new $classname($this->targetObject, $key); |
|
| 486 | - break; |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @param $key |
|
| 492 | - * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | - */ |
|
| 494 | - public function getTextArea($key) |
|
| 495 | - { |
|
| 496 | - $var = $this->targetObject->vars[$key]; |
|
| 497 | - |
|
| 498 | - // if no control has been created, let's create a default one |
|
| 499 | - if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | - $control = [ |
|
| 501 | - 'name' => 'textarea', |
|
| 502 | - 'itemHandler' => false, |
|
| 503 | - 'method' => false, |
|
| 504 | - 'module' => false, |
|
| 505 | - 'form_editor' => 'default' |
|
| 506 | - ]; |
|
| 507 | - } else { |
|
| 508 | - $control = $this->targetObject->controls[$key]; |
|
| 509 | - } |
|
| 510 | - $xoops22 = Smartobject\Utility::isXoops22(); |
|
| 511 | - |
|
| 512 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | - /** |
|
| 514 | - * If the editor is 'default', retreive the default editor of this module |
|
| 515 | - */ |
|
| 516 | - if ('default' === $form_editor) { |
|
| 517 | - global $xoopsModuleConfig; |
|
| 518 | - $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - $caption = $var['form_caption']; |
|
| 522 | - $name = $key; |
|
| 523 | - |
|
| 524 | - $value = $this->targetObject->getVar($key); |
|
| 525 | - |
|
| 526 | - $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | - |
|
| 528 | - $editor_configs = []; |
|
| 529 | - $editor_configs['name'] = $name; |
|
| 530 | - $editor_configs['value'] = $value; |
|
| 531 | - if ('textarea' !== $form_editor) { |
|
| 532 | - $editor_configs['rows'] = 35; |
|
| 533 | - $editor_configs['cols'] = 60; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - if (isset($control['rows'])) { |
|
| 537 | - $editor_configs['rows'] = $control['rows']; |
|
| 538 | - } |
|
| 539 | - if (isset($control['cols'])) { |
|
| 540 | - $editor_configs['cols'] = $control['cols']; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - $editor_configs['width'] = '100%'; |
|
| 544 | - $editor_configs['height'] = '400px'; |
|
| 545 | - |
|
| 546 | - $dhtml = true; |
|
| 547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | - |
|
| 549 | - if (file_exists($xoopseditorclass)) { |
|
| 550 | - require_once $xoopseditorclass; |
|
| 551 | - $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | - } else { |
|
| 553 | - switch ($form_editor) { |
|
| 554 | - |
|
| 555 | - case 'tiny': |
|
| 556 | - if (!$xoops22) { |
|
| 557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | - $editor = new \XoopsFormTinymce([ |
|
| 560 | - 'caption' => $caption, |
|
| 561 | - 'name' => $name, |
|
| 562 | - 'value' => $value, |
|
| 563 | - 'width' => '100%', |
|
| 564 | - 'height' => '300px' |
|
| 565 | - ], true); |
|
| 566 | - } else { |
|
| 567 | - if ($dhtml) { |
|
| 568 | - $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | - } else { |
|
| 570 | - $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - } else { |
|
| 574 | - $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | - } |
|
| 576 | - break; |
|
| 577 | - |
|
| 578 | - case 'dhtmltextarea': |
|
| 579 | - case 'dhtmltext': |
|
| 580 | - $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | - if ($var['form_dsc']) { |
|
| 582 | - $editor->setDescription($var['form_dsc']); |
|
| 583 | - } |
|
| 584 | - break; |
|
| 477 | + } else { |
|
| 478 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
| 479 | + |
|
| 480 | + return new \XoopsFormLabel(); //Empty object |
|
| 481 | + } |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + return new $classname($this->targetObject, $key); |
|
| 486 | + break; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @param $key |
|
| 492 | + * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
| 493 | + */ |
|
| 494 | + public function getTextArea($key) |
|
| 495 | + { |
|
| 496 | + $var = $this->targetObject->vars[$key]; |
|
| 497 | + |
|
| 498 | + // if no control has been created, let's create a default one |
|
| 499 | + if (!isset($this->targetObject->controls[$key])) { |
|
| 500 | + $control = [ |
|
| 501 | + 'name' => 'textarea', |
|
| 502 | + 'itemHandler' => false, |
|
| 503 | + 'method' => false, |
|
| 504 | + 'module' => false, |
|
| 505 | + 'form_editor' => 'default' |
|
| 506 | + ]; |
|
| 507 | + } else { |
|
| 508 | + $control = $this->targetObject->controls[$key]; |
|
| 509 | + } |
|
| 510 | + $xoops22 = Smartobject\Utility::isXoops22(); |
|
| 511 | + |
|
| 512 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
| 513 | + /** |
|
| 514 | + * If the editor is 'default', retreive the default editor of this module |
|
| 515 | + */ |
|
| 516 | + if ('default' === $form_editor) { |
|
| 517 | + global $xoopsModuleConfig; |
|
| 518 | + $form_editor = isset($xoopsModuleConfig['default_editor']) ? $xoopsModuleConfig['default_editor'] : 'textarea'; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + $caption = $var['form_caption']; |
|
| 522 | + $name = $key; |
|
| 523 | + |
|
| 524 | + $value = $this->targetObject->getVar($key); |
|
| 525 | + |
|
| 526 | + $value = $this->targetObject->getValueFor($key, true); |
|
| 527 | + |
|
| 528 | + $editor_configs = []; |
|
| 529 | + $editor_configs['name'] = $name; |
|
| 530 | + $editor_configs['value'] = $value; |
|
| 531 | + if ('textarea' !== $form_editor) { |
|
| 532 | + $editor_configs['rows'] = 35; |
|
| 533 | + $editor_configs['cols'] = 60; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + if (isset($control['rows'])) { |
|
| 537 | + $editor_configs['rows'] = $control['rows']; |
|
| 538 | + } |
|
| 539 | + if (isset($control['cols'])) { |
|
| 540 | + $editor_configs['cols'] = $control['cols']; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + $editor_configs['width'] = '100%'; |
|
| 544 | + $editor_configs['height'] = '400px'; |
|
| 545 | + |
|
| 546 | + $dhtml = true; |
|
| 547 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
| 548 | + |
|
| 549 | + if (file_exists($xoopseditorclass)) { |
|
| 550 | + require_once $xoopseditorclass; |
|
| 551 | + $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
| 552 | + } else { |
|
| 553 | + switch ($form_editor) { |
|
| 554 | + |
|
| 555 | + case 'tiny': |
|
| 556 | + if (!$xoops22) { |
|
| 557 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
| 558 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
| 559 | + $editor = new \XoopsFormTinymce([ |
|
| 560 | + 'caption' => $caption, |
|
| 561 | + 'name' => $name, |
|
| 562 | + 'value' => $value, |
|
| 563 | + 'width' => '100%', |
|
| 564 | + 'height' => '300px' |
|
| 565 | + ], true); |
|
| 566 | + } else { |
|
| 567 | + if ($dhtml) { |
|
| 568 | + $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
| 569 | + } else { |
|
| 570 | + $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + } else { |
|
| 574 | + $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
| 575 | + } |
|
| 576 | + break; |
|
| 577 | + |
|
| 578 | + case 'dhtmltextarea': |
|
| 579 | + case 'dhtmltext': |
|
| 580 | + $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
| 581 | + if ($var['form_dsc']) { |
|
| 582 | + $editor->setDescription($var['form_dsc']); |
|
| 583 | + } |
|
| 584 | + break; |
|
| 585 | 585 | |
| 586 | 586 | // case 'inbetween': |
| 587 | 587 | // if (!$xoops22) { |
@@ -634,177 +634,177 @@ discard block |
||
| 634 | 634 | // } |
| 635 | 635 | // break; |
| 636 | 636 | |
| 637 | - default: |
|
| 638 | - case 'textarea': |
|
| 639 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | - |
|
| 642 | - $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | - if ($var['form_dsc']) { |
|
| 644 | - $editor->setDescription($var['form_dsc']); |
|
| 645 | - } |
|
| 646 | - break; |
|
| 647 | - |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $editor; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * @param $key |
|
| 656 | - * @param $var |
|
| 657 | - * @param bool $multiple |
|
| 658 | - * @return \XoopsFormSelect |
|
| 659 | - */ |
|
| 660 | - public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | - { |
|
| 662 | - $size = $multiple ? 5 : 1; |
|
| 663 | - $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | - |
|
| 665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | - $dirlist = []; |
|
| 667 | - while (false !== ($file = readdir($handle))) { |
|
| 668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | - && 'cvs' !== strtolower($file)) { |
|
| 670 | - $dirlist[$file] = $file; |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - closedir($handle); |
|
| 674 | - if (!empty($dirlist)) { |
|
| 675 | - asort($dirlist); |
|
| 676 | - $theme_select->addOptionArray($dirlist); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return $theme_select; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - /** |
|
| 683 | - * @param $keyname |
|
| 684 | - * @return bool |
|
| 685 | - */ |
|
| 686 | - public function &getElementById($keyname) |
|
| 687 | - { |
|
| 688 | - foreach ($this->_elements as $eleObj) { |
|
| 689 | - if ($eleObj->getName() == $keyname) { |
|
| 690 | - $ret =& $eleObj; |
|
| 691 | - break; |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - return isset($ret) ? $ret : false; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | - * |
|
| 701 | - * @return string |
|
| 702 | - */ |
|
| 703 | - public function render() |
|
| 704 | - { |
|
| 705 | - $required = $this->getRequired(); |
|
| 706 | - $ret = " |
|
| 637 | + default: |
|
| 638 | + case 'textarea': |
|
| 639 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
| 640 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
| 641 | + |
|
| 642 | + $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
| 643 | + if ($var['form_dsc']) { |
|
| 644 | + $editor->setDescription($var['form_dsc']); |
|
| 645 | + } |
|
| 646 | + break; |
|
| 647 | + |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $editor; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * @param $key |
|
| 656 | + * @param $var |
|
| 657 | + * @param bool $multiple |
|
| 658 | + * @return \XoopsFormSelect |
|
| 659 | + */ |
|
| 660 | + public function getThemeSelect($key, $var, $multiple = false) |
|
| 661 | + { |
|
| 662 | + $size = $multiple ? 5 : 1; |
|
| 663 | + $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
| 664 | + |
|
| 665 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
| 666 | + $dirlist = []; |
|
| 667 | + while (false !== ($file = readdir($handle))) { |
|
| 668 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
| 669 | + && 'cvs' !== strtolower($file)) { |
|
| 670 | + $dirlist[$file] = $file; |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + closedir($handle); |
|
| 674 | + if (!empty($dirlist)) { |
|
| 675 | + asort($dirlist); |
|
| 676 | + $theme_select->addOptionArray($dirlist); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return $theme_select; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + /** |
|
| 683 | + * @param $keyname |
|
| 684 | + * @return bool |
|
| 685 | + */ |
|
| 686 | + public function &getElementById($keyname) |
|
| 687 | + { |
|
| 688 | + foreach ($this->_elements as $eleObj) { |
|
| 689 | + if ($eleObj->getName() == $keyname) { |
|
| 690 | + $ret =& $eleObj; |
|
| 691 | + break; |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + return isset($ret) ? $ret : false; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * create HTML to output the form as a theme-enabled table with validation. |
|
| 700 | + * |
|
| 701 | + * @return string |
|
| 702 | + */ |
|
| 703 | + public function render() |
|
| 704 | + { |
|
| 705 | + $required = $this->getRequired(); |
|
| 706 | + $ret = " |
|
| 707 | 707 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
| 708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
| 709 | 709 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
| 710 | 710 | '; |
| 711 | - $hidden = ''; |
|
| 712 | - $class = 'even'; |
|
| 713 | - foreach ($this->getElements() as $ele) { |
|
| 714 | - if (!is_object($ele)) { |
|
| 715 | - $ret .= $ele; |
|
| 716 | - } elseif (!$ele->isHidden()) { |
|
| 717 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | - if ('' !== $ele->getDescription()) { |
|
| 720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | - } |
|
| 722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | - } else { |
|
| 724 | - $hidden .= $ele->render(); |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | - $ret .= $this->renderValidationJS(true); |
|
| 729 | - |
|
| 730 | - return $ret; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - /** |
|
| 734 | - * assign to smarty form template instead of displaying directly |
|
| 735 | - * |
|
| 736 | - * @param \XoopsTpl $tpl |
|
| 737 | - * |
|
| 738 | - * object |
|
| 739 | - * @param bool $smartyName |
|
| 740 | - * @see Smarty |
|
| 741 | - */ |
|
| 742 | - public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | - { |
|
| 744 | - $i = 0; |
|
| 745 | - $elements = []; |
|
| 746 | - foreach ($this->getElements() as $ele) { |
|
| 747 | - $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | - $elements[$n]['name'] = $ele->getName(); |
|
| 749 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | - $elements[$n]['body'] = $ele->render(); |
|
| 751 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | - $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | - if ('' !== $ele->getDescription()) { |
|
| 756 | - $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | - } |
|
| 758 | - ++$i; |
|
| 759 | - } |
|
| 760 | - $js = $this->renderValidationJS(); |
|
| 761 | - if (!$smartyName) { |
|
| 762 | - $smartyName = $this->getName(); |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - $tpl->assign($smartyName, [ |
|
| 766 | - 'title' => $this->getTitle(), |
|
| 767 | - 'name' => $this->getName(), |
|
| 768 | - 'action' => $this->getAction(), |
|
| 769 | - 'method' => $this->getMethod(), |
|
| 770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | - 'javascript' => $js, |
|
| 772 | - 'elements' => $elements |
|
| 773 | - ]); |
|
| 774 | - } |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * @param bool $withtags |
|
| 778 | - * @return string |
|
| 779 | - */ |
|
| 780 | - public function renderValidationJS($withtags = true) |
|
| 781 | - { |
|
| 782 | - $js = ''; |
|
| 783 | - if ($withtags) { |
|
| 784 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | - } |
|
| 786 | - $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | - $formname = $this->getName(); |
|
| 788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | - // First, output code to check required elements |
|
| 790 | - $elements = $this->getRequired(); |
|
| 791 | - foreach ($elements as $elt) { |
|
| 792 | - $eltname = $elt->getName(); |
|
| 793 | - $eltcaption = trim($elt->getCaption()); |
|
| 794 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | - if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | - $js .= 'var myOption = -1;'; |
|
| 798 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 711 | + $hidden = ''; |
|
| 712 | + $class = 'even'; |
|
| 713 | + foreach ($this->getElements() as $ele) { |
|
| 714 | + if (!is_object($ele)) { |
|
| 715 | + $ret .= $ele; |
|
| 716 | + } elseif (!$ele->isHidden()) { |
|
| 717 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
| 718 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
| 719 | + if ('' !== $ele->getDescription()) { |
|
| 720 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
| 721 | + } |
|
| 722 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
| 723 | + } else { |
|
| 724 | + $hidden .= $ele->render(); |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
| 728 | + $ret .= $this->renderValidationJS(true); |
|
| 729 | + |
|
| 730 | + return $ret; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + /** |
|
| 734 | + * assign to smarty form template instead of displaying directly |
|
| 735 | + * |
|
| 736 | + * @param \XoopsTpl $tpl |
|
| 737 | + * |
|
| 738 | + * object |
|
| 739 | + * @param bool $smartyName |
|
| 740 | + * @see Smarty |
|
| 741 | + */ |
|
| 742 | + public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
| 743 | + { |
|
| 744 | + $i = 0; |
|
| 745 | + $elements = []; |
|
| 746 | + foreach ($this->getElements() as $ele) { |
|
| 747 | + $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
| 748 | + $elements[$n]['name'] = $ele->getName(); |
|
| 749 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
| 750 | + $elements[$n]['body'] = $ele->render(); |
|
| 751 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
| 752 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
| 753 | + $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
| 754 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
| 755 | + if ('' !== $ele->getDescription()) { |
|
| 756 | + $elements[$n]['description'] = $ele->getDescription(); |
|
| 757 | + } |
|
| 758 | + ++$i; |
|
| 759 | + } |
|
| 760 | + $js = $this->renderValidationJS(); |
|
| 761 | + if (!$smartyName) { |
|
| 762 | + $smartyName = $this->getName(); |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + $tpl->assign($smartyName, [ |
|
| 766 | + 'title' => $this->getTitle(), |
|
| 767 | + 'name' => $this->getName(), |
|
| 768 | + 'action' => $this->getAction(), |
|
| 769 | + 'method' => $this->getMethod(), |
|
| 770 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
| 771 | + 'javascript' => $js, |
|
| 772 | + 'elements' => $elements |
|
| 773 | + ]); |
|
| 774 | + } |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * @param bool $withtags |
|
| 778 | + * @return string |
|
| 779 | + */ |
|
| 780 | + public function renderValidationJS($withtags = true) |
|
| 781 | + { |
|
| 782 | + $js = ''; |
|
| 783 | + if ($withtags) { |
|
| 784 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
| 785 | + } |
|
| 786 | + $myts = \MyTextSanitizer::getInstance(); |
|
| 787 | + $formname = $this->getName(); |
|
| 788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
| 789 | + // First, output code to check required elements |
|
| 790 | + $elements = $this->getRequired(); |
|
| 791 | + foreach ($elements as $elt) { |
|
| 792 | + $eltname = $elt->getName(); |
|
| 793 | + $eltcaption = trim($elt->getCaption()); |
|
| 794 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
| 795 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
| 796 | + if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
| 797 | + $js .= 'var myOption = -1;'; |
|
| 798 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
| 799 | 799 | if (myform.{$eltname}[i].checked) { |
| 800 | 800 | myOption = i; i = -1; |
| 801 | 801 | } |
| 802 | 802 | } |
| 803 | 803 | if (myOption == -1) { |
| 804 | 804 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
| 805 | - } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | - $js .= 'var hasSelections = false;'; |
|
| 807 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 805 | + } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
| 806 | + $js .= 'var hasSelections = false;'; |
|
| 807 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 808 | 808 | if (myform['{$eltname}[]'].options[i].selected) { |
| 809 | 809 | hasSelections = true; |
| 810 | 810 | } |
@@ -812,12 +812,12 @@ discard block |
||
| 812 | 812 | } |
| 813 | 813 | if (hasSelections === false) { |
| 814 | 814 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
| 815 | - } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | - || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | - $js .= 'var hasSelections = false;'; |
|
| 818 | - //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | - if (false === strpos($eltname, '[')) { |
|
| 820 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 815 | + } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
| 816 | + || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
| 817 | + $js .= 'var hasSelections = false;'; |
|
| 818 | + //sometimes, there is an implicit '[]', sometimes not |
|
| 819 | + if (false === strpos($eltname, '[')) { |
|
| 820 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
| 821 | 821 | if (myform['{$eltname}[]'][i].checked) { |
| 822 | 822 | hasSelections = true; |
| 823 | 823 | } |
@@ -825,8 +825,8 @@ discard block |
||
| 825 | 825 | } |
| 826 | 826 | if (hasSelections === false) { |
| 827 | 827 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
| 828 | - } else { |
|
| 829 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 828 | + } else { |
|
| 829 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
| 830 | 830 | if (myform['{$eltname}'][i].checked) { |
| 831 | 831 | hasSelections = true; |
| 832 | 832 | } |
@@ -834,25 +834,25 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | if (hasSelections === false) { |
| 836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
| 837 | - } |
|
| 838 | - } else { |
|
| 839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - // Now, handle custom validation code |
|
| 843 | - $elements =& $this->getElements(true); |
|
| 844 | - foreach ($elements as $elt) { |
|
| 845 | - if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | - if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | - $js .= $eltjs . "\n"; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - } |
|
| 851 | - $js .= "return true;\n}\n"; |
|
| 852 | - if ($withtags) { |
|
| 853 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return $js; |
|
| 857 | - } |
|
| 837 | + } |
|
| 838 | + } else { |
|
| 839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + // Now, handle custom validation code |
|
| 843 | + $elements =& $this->getElements(true); |
|
| 844 | + foreach ($elements as $elt) { |
|
| 845 | + if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
| 846 | + if ($eltjs = $elt->renderValidationJS()) { |
|
| 847 | + $js .= $eltjs . "\n"; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + } |
|
| 851 | + $js .= "return true;\n}\n"; |
|
| 852 | + if ($withtags) { |
|
| 853 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return $js; |
|
| 857 | + } |
|
| 858 | 858 | } |
@@ -25,800 +25,800 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class Table |
| 27 | 27 | { |
| 28 | - public $_id; |
|
| 29 | - public $_objectHandler; |
|
| 30 | - public $_columns; |
|
| 31 | - public $_criteria; |
|
| 32 | - public $_actions; |
|
| 33 | - public $_objects = false; |
|
| 34 | - public $_aObjects; |
|
| 35 | - public $_custom_actions; |
|
| 36 | - public $_sortsel; |
|
| 37 | - public $_ordersel; |
|
| 38 | - public $_limitsel; |
|
| 39 | - public $_filtersel; |
|
| 40 | - public $_filterseloptions; |
|
| 41 | - public $_filtersel2; |
|
| 42 | - public $_filtersel2options; |
|
| 43 | - public $_filtersel2optionsDefault; |
|
| 44 | - |
|
| 45 | - public $_tempObject; |
|
| 46 | - public $_tpl; |
|
| 47 | - public $_introButtons; |
|
| 48 | - public $_quickSearch = false; |
|
| 49 | - public $_actionButtons = false; |
|
| 50 | - public $_head_css_class = 'bg3'; |
|
| 51 | - public $_hasActions = false; |
|
| 52 | - public $_userSide = false; |
|
| 53 | - public $_printerFriendlyPage = false; |
|
| 54 | - public $_tableHeader = false; |
|
| 55 | - public $_tableFooter = false; |
|
| 56 | - public $_showActionsColumnTitle = true; |
|
| 57 | - public $_isTree = false; |
|
| 58 | - public $_showFilterAndLimit = true; |
|
| 59 | - public $_enableColumnsSorting = true; |
|
| 60 | - public $_customTemplate = false; |
|
| 61 | - public $_withSelectedActions = []; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Constructor |
|
| 65 | - * |
|
| 66 | - * @param Smartobject\PersistableObjectHandler $objectHandler {@link Smartobject\SmartPersistableObjectHandler} |
|
| 67 | - * @param \CriteriaElement $criteria |
|
| 68 | - * @param array $actions array representing the actions to offer |
|
| 69 | - * |
|
| 70 | - * @param bool $userSide |
|
| 71 | - */ |
|
| 72 | - public function __construct(Smartobject\PersistableObjectHandler $objectHandler, \CriteriaElement $criteria = null, $actions = ['edit', 'delete'], $userSide = false) { |
|
| 73 | - $this->_id = $objectHandler->className; |
|
| 74 | - $this->_objectHandler = $objectHandler; |
|
| 75 | - |
|
| 76 | - if (!$criteria) { |
|
| 77 | - $criteria = new \CriteriaCompo(); |
|
| 78 | - } |
|
| 79 | - $this->_criteria = $criteria; |
|
| 80 | - $this->_actions = $actions; |
|
| 81 | - $this->_custom_actions = []; |
|
| 82 | - $this->_userSide = $userSide; |
|
| 83 | - if ($userSide) { |
|
| 84 | - $this->_head_css_class = 'head'; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param $op |
|
| 90 | - * @param bool $caption |
|
| 91 | - * @param bool $text |
|
| 92 | - */ |
|
| 93 | - public function addActionButton($op, $caption = false, $text = false) |
|
| 94 | - { |
|
| 95 | - $action = [ |
|
| 96 | - 'op' => $op, |
|
| 97 | - 'caption' => $caption, |
|
| 98 | - 'text' => $text |
|
| 99 | - ]; |
|
| 100 | - $this->_actionButtons[] = $action; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param $columnObj |
|
| 105 | - */ |
|
| 106 | - public function addColumn($columnObj) |
|
| 107 | - { |
|
| 108 | - $this->_columns[] = $columnObj; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param $name |
|
| 113 | - * @param $location |
|
| 114 | - * @param $value |
|
| 115 | - */ |
|
| 116 | - public function addIntroButton($name, $location, $value) |
|
| 117 | - { |
|
| 118 | - $introButton = []; |
|
| 119 | - $introButton['name'] = $name; |
|
| 120 | - $introButton['location'] = $location; |
|
| 121 | - $introButton['value'] = $value; |
|
| 122 | - $this->_introButtons[] = $introButton; |
|
| 123 | - unset($introButton); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function addPrinterFriendlyLink() |
|
| 127 | - { |
|
| 128 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 129 | - $current_url = $current_urls['full']; |
|
| 130 | - $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @param $fields |
|
| 135 | - * @param string $caption |
|
| 136 | - */ |
|
| 137 | - public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 138 | - { |
|
| 139 | - $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param $content |
|
| 144 | - */ |
|
| 145 | - public function addHeader($content) |
|
| 146 | - { |
|
| 147 | - $this->_tableHeader = $content; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @param $content |
|
| 152 | - */ |
|
| 153 | - public function addFooter($content) |
|
| 154 | - { |
|
| 155 | - $this->_tableFooter = $content; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @param $caption |
|
| 160 | - */ |
|
| 161 | - public function addDefaultIntroButton($caption) |
|
| 162 | - { |
|
| 163 | - $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @param $method |
|
| 168 | - */ |
|
| 169 | - public function addCustomAction($method) |
|
| 170 | - { |
|
| 171 | - $this->_custom_actions[] = $method; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param $default_sort |
|
| 176 | - */ |
|
| 177 | - public function setDefaultSort($default_sort) |
|
| 178 | - { |
|
| 179 | - $this->_sortsel = $default_sort; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @return string |
|
| 184 | - */ |
|
| 185 | - public function getDefaultSort() |
|
| 186 | - { |
|
| 187 | - if ($this->_sortsel) { |
|
| 188 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 189 | - } else { |
|
| 190 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param $default_order |
|
| 196 | - */ |
|
| 197 | - public function setDefaultOrder($default_order) |
|
| 198 | - { |
|
| 199 | - $this->_ordersel = $default_order; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @return string |
|
| 204 | - */ |
|
| 205 | - public function getDefaultOrder() |
|
| 206 | - { |
|
| 207 | - if ($this->_ordersel) { |
|
| 208 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 209 | - } else { |
|
| 210 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param array $actions |
|
| 216 | - */ |
|
| 217 | - public function addWithSelectedActions($actions = []) |
|
| 218 | - { |
|
| 219 | - $this->addColumn(new ObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 220 | - $this->_withSelectedActions = $actions; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Adding a filter in the table |
|
| 225 | - * |
|
| 226 | - * @param string $key key to the field that will be used for sorting |
|
| 227 | - * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 228 | - * @param bool $default |
|
| 229 | - */ |
|
| 230 | - public function addFilter($key, $method, $default = false) |
|
| 231 | - { |
|
| 232 | - $this->_filterseloptions[$key] = $method; |
|
| 233 | - $this->_filtersel2optionsDefault = $default; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param $default_filter |
|
| 238 | - */ |
|
| 239 | - public function setDefaultFilter($default_filter) |
|
| 240 | - { |
|
| 241 | - $this->_filtersel = $default_filter; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - public function isForUserSide() |
|
| 245 | - { |
|
| 246 | - $this->_userSide = true; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * @param $template |
|
| 251 | - */ |
|
| 252 | - public function setCustomTemplate($template) |
|
| 253 | - { |
|
| 254 | - $this->_customTemplate = $template; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - public function setSortOrder() |
|
| 258 | - { |
|
| 259 | - $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 260 | - //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 261 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 262 | - $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 263 | - |
|
| 264 | - if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 265 | - && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 266 | - $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 267 | - } else { |
|
| 268 | - $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 272 | - //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 273 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 274 | - $ordersArray = $this->getOrdersArray(); |
|
| 275 | - $this->_criteria->setOrder($this->_ordersel); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @param $id |
|
| 280 | - */ |
|
| 281 | - public function setTableId($id) |
|
| 282 | - { |
|
| 283 | - $this->_id = $id; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @param $objects |
|
| 288 | - */ |
|
| 289 | - public function setObjects($objects) |
|
| 290 | - { |
|
| 291 | - $this->_objects = $objects; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - public function createTableRows() |
|
| 295 | - { |
|
| 296 | - $this->_aObjects = []; |
|
| 297 | - |
|
| 298 | - $doWeHaveActions = false; |
|
| 299 | - |
|
| 300 | - $objectclass = 'odd'; |
|
| 301 | - if (count($this->_objects) > 0) { |
|
| 302 | - foreach ($this->_objects as $object) { |
|
| 303 | - $aObject = []; |
|
| 304 | - |
|
| 305 | - $i = 0; |
|
| 306 | - |
|
| 307 | - $aColumns = []; |
|
| 308 | - |
|
| 309 | - foreach ($this->_columns as $column) { |
|
| 310 | - $aColumn = []; |
|
| 311 | - |
|
| 312 | - if (0 == $i) { |
|
| 313 | - $class = 'head'; |
|
| 314 | - } elseif (0 == $i % 2) { |
|
| 315 | - $class = 'even'; |
|
| 316 | - } else { |
|
| 317 | - $class = 'odd'; |
|
| 318 | - } |
|
| 319 | - if (method_exists($object, 'initiateCustomFields')) { |
|
| 320 | - //$object->initiateCustomFields(); |
|
| 321 | - } |
|
| 322 | - if ('checked' === $column->_keyname) { |
|
| 323 | - $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 324 | - } elseif ($column->_customMethodForValue |
|
| 325 | - && method_exists($object, $column->_customMethodForValue)) { |
|
| 326 | - $method = $column->_customMethodForValue; |
|
| 327 | - if ($column->_param) { |
|
| 328 | - $value = $object->$method($column->_param); |
|
| 329 | - } else { |
|
| 330 | - $value = $object->$method(); |
|
| 331 | - } |
|
| 332 | - } else { |
|
| 333 | - /** |
|
| 334 | - * If the column is the identifier, then put a link on it |
|
| 335 | - */ |
|
| 336 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 337 | - $value = $object->getItemLink(); |
|
| 338 | - } else { |
|
| 339 | - $value = $object->getVar($column->getKeyName()); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - $aColumn['value'] = $value; |
|
| 344 | - $aColumn['class'] = $class; |
|
| 345 | - $aColumn['width'] = $column->getWidth(); |
|
| 346 | - $aColumn['align'] = $column->getAlign(); |
|
| 347 | - |
|
| 348 | - $aColumns[] = $aColumn; |
|
| 349 | - ++$i; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - $aObject['columns'] = $aColumns; |
|
| 353 | - $aObject['id'] = $object->id(); |
|
| 354 | - |
|
| 355 | - $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 356 | - |
|
| 357 | - $aObject['class'] = $objectclass; |
|
| 358 | - |
|
| 359 | - $actions = []; |
|
| 360 | - |
|
| 361 | - // Adding the custom actions if any |
|
| 362 | - foreach ($this->_custom_actions as $action) { |
|
| 363 | - if (method_exists($object, $action)) { |
|
| 364 | - $actions[] = $object->$action(); |
|
| 365 | - } |
|
| 366 | - } |
|
| 28 | + public $_id; |
|
| 29 | + public $_objectHandler; |
|
| 30 | + public $_columns; |
|
| 31 | + public $_criteria; |
|
| 32 | + public $_actions; |
|
| 33 | + public $_objects = false; |
|
| 34 | + public $_aObjects; |
|
| 35 | + public $_custom_actions; |
|
| 36 | + public $_sortsel; |
|
| 37 | + public $_ordersel; |
|
| 38 | + public $_limitsel; |
|
| 39 | + public $_filtersel; |
|
| 40 | + public $_filterseloptions; |
|
| 41 | + public $_filtersel2; |
|
| 42 | + public $_filtersel2options; |
|
| 43 | + public $_filtersel2optionsDefault; |
|
| 44 | + |
|
| 45 | + public $_tempObject; |
|
| 46 | + public $_tpl; |
|
| 47 | + public $_introButtons; |
|
| 48 | + public $_quickSearch = false; |
|
| 49 | + public $_actionButtons = false; |
|
| 50 | + public $_head_css_class = 'bg3'; |
|
| 51 | + public $_hasActions = false; |
|
| 52 | + public $_userSide = false; |
|
| 53 | + public $_printerFriendlyPage = false; |
|
| 54 | + public $_tableHeader = false; |
|
| 55 | + public $_tableFooter = false; |
|
| 56 | + public $_showActionsColumnTitle = true; |
|
| 57 | + public $_isTree = false; |
|
| 58 | + public $_showFilterAndLimit = true; |
|
| 59 | + public $_enableColumnsSorting = true; |
|
| 60 | + public $_customTemplate = false; |
|
| 61 | + public $_withSelectedActions = []; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Constructor |
|
| 65 | + * |
|
| 66 | + * @param Smartobject\PersistableObjectHandler $objectHandler {@link Smartobject\SmartPersistableObjectHandler} |
|
| 67 | + * @param \CriteriaElement $criteria |
|
| 68 | + * @param array $actions array representing the actions to offer |
|
| 69 | + * |
|
| 70 | + * @param bool $userSide |
|
| 71 | + */ |
|
| 72 | + public function __construct(Smartobject\PersistableObjectHandler $objectHandler, \CriteriaElement $criteria = null, $actions = ['edit', 'delete'], $userSide = false) { |
|
| 73 | + $this->_id = $objectHandler->className; |
|
| 74 | + $this->_objectHandler = $objectHandler; |
|
| 75 | + |
|
| 76 | + if (!$criteria) { |
|
| 77 | + $criteria = new \CriteriaCompo(); |
|
| 78 | + } |
|
| 79 | + $this->_criteria = $criteria; |
|
| 80 | + $this->_actions = $actions; |
|
| 81 | + $this->_custom_actions = []; |
|
| 82 | + $this->_userSide = $userSide; |
|
| 83 | + if ($userSide) { |
|
| 84 | + $this->_head_css_class = 'head'; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param $op |
|
| 90 | + * @param bool $caption |
|
| 91 | + * @param bool $text |
|
| 92 | + */ |
|
| 93 | + public function addActionButton($op, $caption = false, $text = false) |
|
| 94 | + { |
|
| 95 | + $action = [ |
|
| 96 | + 'op' => $op, |
|
| 97 | + 'caption' => $caption, |
|
| 98 | + 'text' => $text |
|
| 99 | + ]; |
|
| 100 | + $this->_actionButtons[] = $action; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param $columnObj |
|
| 105 | + */ |
|
| 106 | + public function addColumn($columnObj) |
|
| 107 | + { |
|
| 108 | + $this->_columns[] = $columnObj; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param $name |
|
| 113 | + * @param $location |
|
| 114 | + * @param $value |
|
| 115 | + */ |
|
| 116 | + public function addIntroButton($name, $location, $value) |
|
| 117 | + { |
|
| 118 | + $introButton = []; |
|
| 119 | + $introButton['name'] = $name; |
|
| 120 | + $introButton['location'] = $location; |
|
| 121 | + $introButton['value'] = $value; |
|
| 122 | + $this->_introButtons[] = $introButton; |
|
| 123 | + unset($introButton); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function addPrinterFriendlyLink() |
|
| 127 | + { |
|
| 128 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 129 | + $current_url = $current_urls['full']; |
|
| 130 | + $this->_printerFriendlyPage = $current_url . '&print'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @param $fields |
|
| 135 | + * @param string $caption |
|
| 136 | + */ |
|
| 137 | + public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH) |
|
| 138 | + { |
|
| 139 | + $this->_quickSearch = ['fields' => $fields, 'caption' => $caption]; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param $content |
|
| 144 | + */ |
|
| 145 | + public function addHeader($content) |
|
| 146 | + { |
|
| 147 | + $this->_tableHeader = $content; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @param $content |
|
| 152 | + */ |
|
| 153 | + public function addFooter($content) |
|
| 154 | + { |
|
| 155 | + $this->_tableFooter = $content; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @param $caption |
|
| 160 | + */ |
|
| 161 | + public function addDefaultIntroButton($caption) |
|
| 162 | + { |
|
| 163 | + $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @param $method |
|
| 168 | + */ |
|
| 169 | + public function addCustomAction($method) |
|
| 170 | + { |
|
| 171 | + $this->_custom_actions[] = $method; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param $default_sort |
|
| 176 | + */ |
|
| 177 | + public function setDefaultSort($default_sort) |
|
| 178 | + { |
|
| 179 | + $this->_sortsel = $default_sort; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @return string |
|
| 184 | + */ |
|
| 185 | + public function getDefaultSort() |
|
| 186 | + { |
|
| 187 | + if ($this->_sortsel) { |
|
| 188 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 189 | + } else { |
|
| 190 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param $default_order |
|
| 196 | + */ |
|
| 197 | + public function setDefaultOrder($default_order) |
|
| 198 | + { |
|
| 199 | + $this->_ordersel = $default_order; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 205 | + public function getDefaultOrder() |
|
| 206 | + { |
|
| 207 | + if ($this->_ordersel) { |
|
| 208 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 209 | + } else { |
|
| 210 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC'); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param array $actions |
|
| 216 | + */ |
|
| 217 | + public function addWithSelectedActions($actions = []) |
|
| 218 | + { |
|
| 219 | + $this->addColumn(new ObjectColumn('checked', 'center', 20, false, false, ' ')); |
|
| 220 | + $this->_withSelectedActions = $actions; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Adding a filter in the table |
|
| 225 | + * |
|
| 226 | + * @param string $key key to the field that will be used for sorting |
|
| 227 | + * @param string $method method of the handler that will be called to populate the options when this filter is selected |
|
| 228 | + * @param bool $default |
|
| 229 | + */ |
|
| 230 | + public function addFilter($key, $method, $default = false) |
|
| 231 | + { |
|
| 232 | + $this->_filterseloptions[$key] = $method; |
|
| 233 | + $this->_filtersel2optionsDefault = $default; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param $default_filter |
|
| 238 | + */ |
|
| 239 | + public function setDefaultFilter($default_filter) |
|
| 240 | + { |
|
| 241 | + $this->_filtersel = $default_filter; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + public function isForUserSide() |
|
| 245 | + { |
|
| 246 | + $this->_userSide = true; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * @param $template |
|
| 251 | + */ |
|
| 252 | + public function setCustomTemplate($template) |
|
| 253 | + { |
|
| 254 | + $this->_customTemplate = $template; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + public function setSortOrder() |
|
| 258 | + { |
|
| 259 | + $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort(); |
|
| 260 | + //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel; |
|
| 261 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel); |
|
| 262 | + $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel); |
|
| 263 | + |
|
| 264 | + if (isset($this->_tempObject->vars[$this->_sortsel]['itemName']) |
|
| 265 | + && $this->_tempObject->vars[$this->_sortsel]['itemName']) { |
|
| 266 | + $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel); |
|
| 267 | + } else { |
|
| 268 | + $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder(); |
|
| 272 | + //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel; |
|
| 273 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel); |
|
| 274 | + $ordersArray = $this->getOrdersArray(); |
|
| 275 | + $this->_criteria->setOrder($this->_ordersel); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @param $id |
|
| 280 | + */ |
|
| 281 | + public function setTableId($id) |
|
| 282 | + { |
|
| 283 | + $this->_id = $id; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @param $objects |
|
| 288 | + */ |
|
| 289 | + public function setObjects($objects) |
|
| 290 | + { |
|
| 291 | + $this->_objects = $objects; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + public function createTableRows() |
|
| 295 | + { |
|
| 296 | + $this->_aObjects = []; |
|
| 297 | + |
|
| 298 | + $doWeHaveActions = false; |
|
| 299 | + |
|
| 300 | + $objectclass = 'odd'; |
|
| 301 | + if (count($this->_objects) > 0) { |
|
| 302 | + foreach ($this->_objects as $object) { |
|
| 303 | + $aObject = []; |
|
| 304 | + |
|
| 305 | + $i = 0; |
|
| 306 | + |
|
| 307 | + $aColumns = []; |
|
| 308 | + |
|
| 309 | + foreach ($this->_columns as $column) { |
|
| 310 | + $aColumn = []; |
|
| 311 | + |
|
| 312 | + if (0 == $i) { |
|
| 313 | + $class = 'head'; |
|
| 314 | + } elseif (0 == $i % 2) { |
|
| 315 | + $class = 'even'; |
|
| 316 | + } else { |
|
| 317 | + $class = 'odd'; |
|
| 318 | + } |
|
| 319 | + if (method_exists($object, 'initiateCustomFields')) { |
|
| 320 | + //$object->initiateCustomFields(); |
|
| 321 | + } |
|
| 322 | + if ('checked' === $column->_keyname) { |
|
| 323 | + $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">'; |
|
| 324 | + } elseif ($column->_customMethodForValue |
|
| 325 | + && method_exists($object, $column->_customMethodForValue)) { |
|
| 326 | + $method = $column->_customMethodForValue; |
|
| 327 | + if ($column->_param) { |
|
| 328 | + $value = $object->$method($column->_param); |
|
| 329 | + } else { |
|
| 330 | + $value = $object->$method(); |
|
| 331 | + } |
|
| 332 | + } else { |
|
| 333 | + /** |
|
| 334 | + * If the column is the identifier, then put a link on it |
|
| 335 | + */ |
|
| 336 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 337 | + $value = $object->getItemLink(); |
|
| 338 | + } else { |
|
| 339 | + $value = $object->getVar($column->getKeyName()); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + $aColumn['value'] = $value; |
|
| 344 | + $aColumn['class'] = $class; |
|
| 345 | + $aColumn['width'] = $column->getWidth(); |
|
| 346 | + $aColumn['align'] = $column->getAlign(); |
|
| 347 | + |
|
| 348 | + $aColumns[] = $aColumn; |
|
| 349 | + ++$i; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + $aObject['columns'] = $aColumns; |
|
| 353 | + $aObject['id'] = $object->id(); |
|
| 354 | + |
|
| 355 | + $objectclass = ('even' === $objectclass) ? 'odd' : 'even'; |
|
| 356 | + |
|
| 357 | + $aObject['class'] = $objectclass; |
|
| 358 | + |
|
| 359 | + $actions = []; |
|
| 360 | + |
|
| 361 | + // Adding the custom actions if any |
|
| 362 | + foreach ($this->_custom_actions as $action) { |
|
| 363 | + if (method_exists($object, $action)) { |
|
| 364 | + $actions[] = $object->$action(); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | 368 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
| 369 | - $controller = new ObjectController($this->_objectHandler); |
|
| 370 | - |
|
| 371 | - if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 372 | - $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 373 | - } |
|
| 374 | - if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 375 | - $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 376 | - } |
|
| 377 | - $aObject['actions'] = $actions; |
|
| 378 | - |
|
| 379 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 380 | - |
|
| 381 | - $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 382 | - |
|
| 383 | - $this->_aObjects[] = $aObject; |
|
| 384 | - } |
|
| 385 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 386 | - } else { |
|
| 387 | - $colspan = count($this->_columns) + 1; |
|
| 388 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 389 | - } |
|
| 390 | - $this->_hasActions = $doWeHaveActions; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * @param bool $debug |
|
| 395 | - * @return mixed |
|
| 396 | - */ |
|
| 397 | - public function fetchObjects($debug = false) |
|
| 398 | - { |
|
| 399 | - return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @return string |
|
| 404 | - */ |
|
| 405 | - public function getDefaultFilter() |
|
| 406 | - { |
|
| 407 | - if ($this->_filtersel) { |
|
| 408 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 409 | - } else { |
|
| 410 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @return array|bool |
|
| 416 | - */ |
|
| 417 | - public function getFiltersArray() |
|
| 418 | - { |
|
| 419 | - $ret = []; |
|
| 420 | - $field = []; |
|
| 421 | - $field['caption'] = _CO_OBJ_NONE; |
|
| 422 | - $field['selected'] = ''; |
|
| 423 | - $ret['default'] = $field; |
|
| 424 | - unset($field); |
|
| 425 | - |
|
| 426 | - if ($this->_filterseloptions) { |
|
| 427 | - foreach ($this->_filterseloptions as $key => $value) { |
|
| 428 | - $field = []; |
|
| 429 | - if (is_array($value)) { |
|
| 430 | - $field['caption'] = $key; |
|
| 431 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 432 | - } else { |
|
| 433 | - $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 434 | - $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 435 | - } |
|
| 436 | - $ret[$key] = $field; |
|
| 437 | - unset($field); |
|
| 438 | - } |
|
| 439 | - } else { |
|
| 440 | - $ret = false; |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return $ret; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * @param $default_filter2 |
|
| 448 | - */ |
|
| 449 | - public function setDefaultFilter2($default_filter2) |
|
| 450 | - { |
|
| 451 | - $this->_filtersel2 = $default_filter2; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function getDefaultFilter2() |
|
| 458 | - { |
|
| 459 | - if ($this->_filtersel2) { |
|
| 460 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 461 | - } else { |
|
| 462 | - return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 463 | - } |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * @return array |
|
| 468 | - */ |
|
| 469 | - public function getFilters2Array() |
|
| 470 | - { |
|
| 471 | - $ret = []; |
|
| 472 | - |
|
| 473 | - foreach ($this->_filtersel2options as $key => $value) { |
|
| 474 | - $field = []; |
|
| 475 | - $field['caption'] = $value; |
|
| 476 | - $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 477 | - $ret[$key] = $field; |
|
| 478 | - unset($field); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return $ret; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * @param $limitsArray |
|
| 486 | - * @param $params_of_the_options_sel |
|
| 487 | - */ |
|
| 488 | - public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 489 | - { |
|
| 490 | - // Rendering the form to select options on the table |
|
| 491 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 492 | - $current_url = $current_urls['full']; |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * What was $params_of_the_options_sel doing again ? |
|
| 496 | - */ |
|
| 497 | - //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 498 | - $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 499 | - $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * @return array |
|
| 504 | - */ |
|
| 505 | - public function getLimitsArray() |
|
| 506 | - { |
|
| 507 | - $ret = []; |
|
| 508 | - $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 509 | - $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 510 | - |
|
| 511 | - $ret['5']['caption'] = '5'; |
|
| 512 | - $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 513 | - |
|
| 514 | - $ret['10']['caption'] = '10'; |
|
| 515 | - $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 516 | - |
|
| 517 | - $ret['15']['caption'] = '15'; |
|
| 518 | - $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 519 | - |
|
| 520 | - $ret['20']['caption'] = '20'; |
|
| 521 | - $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 522 | - |
|
| 523 | - $ret['25']['caption'] = '25'; |
|
| 524 | - $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 525 | - |
|
| 526 | - $ret['30']['caption'] = '30'; |
|
| 527 | - $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 528 | - |
|
| 529 | - $ret['35']['caption'] = '35'; |
|
| 530 | - $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 531 | - |
|
| 532 | - $ret['40']['caption'] = '40'; |
|
| 533 | - $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 534 | - |
|
| 535 | - return $ret; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @return bool |
|
| 540 | - */ |
|
| 541 | - public function getObjects() |
|
| 542 | - { |
|
| 543 | - return $this->_objects; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - public function hideActionColumnTitle() |
|
| 547 | - { |
|
| 548 | - $this->_showActionsColumnTitle = false; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - public function hideFilterAndLimit() |
|
| 552 | - { |
|
| 553 | - $this->_showFilterAndLimit = false; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @return array |
|
| 558 | - */ |
|
| 559 | - public function getOrdersArray() |
|
| 560 | - { |
|
| 561 | - $ret = []; |
|
| 562 | - $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 563 | - $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 564 | - |
|
| 565 | - $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 566 | - $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 567 | - |
|
| 568 | - return $ret; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @return mixed|string|void |
|
| 573 | - */ |
|
| 574 | - public function renderD() |
|
| 575 | - { |
|
| 576 | - return $this->render(false, true); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - public function renderForPrint() |
|
| 580 | - { |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * @param bool $fetchOnly |
|
| 585 | - * @param bool $debug |
|
| 586 | - * @return mixed|string|void |
|
| 587 | - */ |
|
| 588 | - public function render($fetchOnly = false, $debug = false) |
|
| 589 | - { |
|
| 590 | - require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 591 | - |
|
| 592 | - $this->_tpl = new \XoopsTpl(); |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 596 | - * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 597 | - * and we will free it after |
|
| 598 | - */ |
|
| 599 | - $this->_tempObject = $this->_objectHandler->create(); |
|
| 600 | - |
|
| 601 | - $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 602 | - |
|
| 603 | - $this->setSortOrder(); |
|
| 604 | - |
|
| 605 | - if (!$this->_isTree) { |
|
| 606 | - $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 607 | - } else { |
|
| 608 | - $this->_limitsel = 'all'; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 612 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 613 | - $limitsArray = $this->getLimitsArray(); |
|
| 614 | - $this->_criteria->setLimit($this->_limitsel); |
|
| 615 | - |
|
| 616 | - $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 617 | - $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 618 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 619 | - $filtersArray = $this->getFiltersArray(); |
|
| 620 | - |
|
| 621 | - if ($filtersArray) { |
|
| 622 | - $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 626 | - if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 627 | - // check if method associate with this filter exists in the handler |
|
| 628 | - if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 629 | - $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 630 | - $this->_criteria->add($filter['criteria']); |
|
| 631 | - } else { |
|
| 632 | - if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 633 | - |
|
| 634 | - // then we will create the selfilter2 options by calling this method |
|
| 635 | - $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 636 | - $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 637 | - |
|
| 638 | - $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 639 | - $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 640 | - |
|
| 641 | - $filters2Array = $this->getFilters2Array(); |
|
| 642 | - $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 643 | - |
|
| 644 | - Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 645 | - if ('default' !== $this->_filtersel2) { |
|
| 646 | - $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - // Check if we have a quicksearch |
|
| 652 | - |
|
| 653 | - if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 654 | - $quicksearch_criteria = new \CriteriaCompo(); |
|
| 655 | - if (is_array($this->_quickSearch['fields'])) { |
|
| 656 | - foreach ($this->_quickSearch['fields'] as $v) { |
|
| 657 | - $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 658 | - } |
|
| 659 | - } else { |
|
| 660 | - $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 661 | - } |
|
| 662 | - $this->_criteria->add($quicksearch_criteria); |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - $this->_objects = $this->fetchObjects($debug); |
|
| 666 | - |
|
| 667 | - require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 668 | - if ($this->_criteria->getLimit() > 0) { |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Geeting rid of the old params |
|
| 672 | - * $new_get_array is an array containing the new GET parameters |
|
| 673 | - */ |
|
| 674 | - $new_get_array = []; |
|
| 675 | - |
|
| 676 | - /** |
|
| 677 | - * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 678 | - * but without the pagenave parameters. This array will be used in the |
|
| 679 | - * OptionsSelection |
|
| 680 | - */ |
|
| 681 | - $params_of_the_options_sel = []; |
|
| 682 | - |
|
| 683 | - $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 684 | - foreach ($_GET as $k => $v) { |
|
| 685 | - if (!in_array($k, $not_needed_params)) { |
|
| 686 | - $new_get_array[] = "$k=$v"; |
|
| 687 | - $params_of_the_options_sel[] = "$k=$v"; |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Adding the new params of the pagenav |
|
| 693 | - */ |
|
| 694 | - $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 695 | - $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 696 | - $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 697 | - $otherParams = implode('&', $new_get_array); |
|
| 698 | - |
|
| 699 | - $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 700 | - $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 701 | - } |
|
| 702 | - $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 703 | - |
|
| 704 | - // retreive the current url and the query string |
|
| 705 | - $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 706 | - $current_url = $current_urls['full_phpself']; |
|
| 707 | - $query_string = $current_urls['querystring']; |
|
| 708 | - if ($query_string) { |
|
| 709 | - $query_string = str_replace('?', '', $query_string); |
|
| 710 | - } |
|
| 711 | - $query_stringArray = explode('&', $query_string); |
|
| 712 | - $new_query_stringArray = []; |
|
| 713 | - foreach ($query_stringArray as $query_string) { |
|
| 714 | - if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 715 | - $new_query_stringArray[] = $query_string; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - $new_query_string = implode('&', $new_query_stringArray); |
|
| 719 | - |
|
| 720 | - $orderArray = []; |
|
| 721 | - $orderArray['ASC']['image'] = 'desc.png'; |
|
| 722 | - $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 723 | - $orderArray['DESC']['image'] = 'asc.png'; |
|
| 724 | - $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 725 | - |
|
| 726 | - $aColumns = []; |
|
| 727 | - |
|
| 728 | - foreach ($this->_columns as $column) { |
|
| 729 | - $qs_param = ''; |
|
| 730 | - $aColumn = []; |
|
| 731 | - $aColumn['width'] = $column->getWidth(); |
|
| 732 | - $aColumn['align'] = $column->getAlign(); |
|
| 733 | - $aColumn['key'] = $column->getKeyName(); |
|
| 734 | - if ('checked' === $column->_keyname) { |
|
| 735 | - $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 736 | - } elseif ($column->getCustomCaption()) { |
|
| 737 | - $aColumn['caption'] = $column->getCustomCaption(); |
|
| 738 | - } else { |
|
| 739 | - $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 740 | - } |
|
| 741 | - // Are we doing a GET sort on this column ? |
|
| 742 | - $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 743 | - && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 744 | - || ($this->_sortsel == $column->getKeyName()); |
|
| 745 | - $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 746 | - |
|
| 747 | - if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 748 | - $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 749 | - } |
|
| 750 | - if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 751 | - $aColumn['caption'] = $aColumn['caption']; |
|
| 752 | - } elseif ($getSort) { |
|
| 753 | - $aColumn['caption'] = '<a href="' |
|
| 754 | - . $current_url |
|
| 755 | - . '?' |
|
| 756 | - . $this->_objectHandler->_itemname |
|
| 757 | - . '_' |
|
| 758 | - . 'sortsel=' |
|
| 759 | - . $column->getKeyName() |
|
| 760 | - . '&' |
|
| 761 | - . $this->_objectHandler->_itemname |
|
| 762 | - . '_' |
|
| 763 | - . 'ordersel=' |
|
| 764 | - . $orderArray[$order]['neworder'] |
|
| 765 | - . $qs_param |
|
| 766 | - . '&' |
|
| 767 | - . $new_query_string |
|
| 768 | - . '">' |
|
| 769 | - . $aColumn['caption'] |
|
| 770 | - . ' <img src="' |
|
| 771 | - . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 772 | - . $orderArray[$order]['image'] |
|
| 773 | - . '" alt="ASC"></a>'; |
|
| 774 | - } else { |
|
| 775 | - $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 776 | - } |
|
| 777 | - $aColumns[] = $aColumn; |
|
| 778 | - } |
|
| 779 | - $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 780 | - |
|
| 781 | - if ($this->_quickSearch) { |
|
| 782 | - $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $this->createTableRows(); |
|
| 786 | - |
|
| 787 | - $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 788 | - $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 789 | - $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 790 | - $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 791 | - $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 792 | - $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 793 | - $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 794 | - $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 795 | - $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 796 | - $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 797 | - $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 798 | - $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 799 | - if (!empty($this->_withSelectedActions)) { |
|
| 800 | - $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 804 | - if ($fetchOnly) { |
|
| 805 | - return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 806 | - } else { |
|
| 807 | - $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 808 | - } |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - public function disableColumnsSorting() |
|
| 812 | - { |
|
| 813 | - $this->_enableColumnsSorting = false; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * @param bool $debug |
|
| 818 | - * @return mixed|string|void |
|
| 819 | - */ |
|
| 820 | - public function fetch($debug = false) |
|
| 821 | - { |
|
| 822 | - return $this->render(true, $debug); |
|
| 823 | - } |
|
| 369 | + $controller = new ObjectController($this->_objectHandler); |
|
| 370 | + |
|
| 371 | + if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) { |
|
| 372 | + $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide); |
|
| 373 | + } |
|
| 374 | + if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) { |
|
| 375 | + $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide); |
|
| 376 | + } |
|
| 377 | + $aObject['actions'] = $actions; |
|
| 378 | + |
|
| 379 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 380 | + |
|
| 381 | + $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0; |
|
| 382 | + |
|
| 383 | + $this->_aObjects[] = $aObject; |
|
| 384 | + } |
|
| 385 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 386 | + } else { |
|
| 387 | + $colspan = count($this->_columns) + 1; |
|
| 388 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 389 | + } |
|
| 390 | + $this->_hasActions = $doWeHaveActions; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @param bool $debug |
|
| 395 | + * @return mixed |
|
| 396 | + */ |
|
| 397 | + public function fetchObjects($debug = false) |
|
| 398 | + { |
|
| 399 | + return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug); |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @return string |
|
| 404 | + */ |
|
| 405 | + public function getDefaultFilter() |
|
| 406 | + { |
|
| 407 | + if ($this->_filtersel) { |
|
| 408 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 409 | + } else { |
|
| 410 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default'); |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @return array|bool |
|
| 416 | + */ |
|
| 417 | + public function getFiltersArray() |
|
| 418 | + { |
|
| 419 | + $ret = []; |
|
| 420 | + $field = []; |
|
| 421 | + $field['caption'] = _CO_OBJ_NONE; |
|
| 422 | + $field['selected'] = ''; |
|
| 423 | + $ret['default'] = $field; |
|
| 424 | + unset($field); |
|
| 425 | + |
|
| 426 | + if ($this->_filterseloptions) { |
|
| 427 | + foreach ($this->_filterseloptions as $key => $value) { |
|
| 428 | + $field = []; |
|
| 429 | + if (is_array($value)) { |
|
| 430 | + $field['caption'] = $key; |
|
| 431 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 432 | + } else { |
|
| 433 | + $field['caption'] = $this->_tempObject->vars[$key]['form_caption']; |
|
| 434 | + $field['selected'] = $this->_filtersel == $key ? 'selected' : ''; |
|
| 435 | + } |
|
| 436 | + $ret[$key] = $field; |
|
| 437 | + unset($field); |
|
| 438 | + } |
|
| 439 | + } else { |
|
| 440 | + $ret = false; |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return $ret; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * @param $default_filter2 |
|
| 448 | + */ |
|
| 449 | + public function setDefaultFilter2($default_filter2) |
|
| 450 | + { |
|
| 451 | + $this->_filtersel2 = $default_filter2; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function getDefaultFilter2() |
|
| 458 | + { |
|
| 459 | + if ($this->_filtersel2) { |
|
| 460 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 461 | + } else { |
|
| 462 | + return Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default'); |
|
| 463 | + } |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * @return array |
|
| 468 | + */ |
|
| 469 | + public function getFilters2Array() |
|
| 470 | + { |
|
| 471 | + $ret = []; |
|
| 472 | + |
|
| 473 | + foreach ($this->_filtersel2options as $key => $value) { |
|
| 474 | + $field = []; |
|
| 475 | + $field['caption'] = $value; |
|
| 476 | + $field['selected'] = $this->_filtersel2 == $key ? 'selected' : ''; |
|
| 477 | + $ret[$key] = $field; |
|
| 478 | + unset($field); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return $ret; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * @param $limitsArray |
|
| 486 | + * @param $params_of_the_options_sel |
|
| 487 | + */ |
|
| 488 | + public function renderOptionSelection($limitsArray, $params_of_the_options_sel) |
|
| 489 | + { |
|
| 490 | + // Rendering the form to select options on the table |
|
| 491 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 492 | + $current_url = $current_urls['full']; |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * What was $params_of_the_options_sel doing again ? |
|
| 496 | + */ |
|
| 497 | + //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel)); |
|
| 498 | + $this->_tpl->assign('smartobject_optionssel_action', $current_url); |
|
| 499 | + $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * @return array |
|
| 504 | + */ |
|
| 505 | + public function getLimitsArray() |
|
| 506 | + { |
|
| 507 | + $ret = []; |
|
| 508 | + $ret['all']['caption'] = _CO_SOBJECT_LIMIT_ALL; |
|
| 509 | + $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : ''; |
|
| 510 | + |
|
| 511 | + $ret['5']['caption'] = '5'; |
|
| 512 | + $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : ''; |
|
| 513 | + |
|
| 514 | + $ret['10']['caption'] = '10'; |
|
| 515 | + $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : ''; |
|
| 516 | + |
|
| 517 | + $ret['15']['caption'] = '15'; |
|
| 518 | + $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : ''; |
|
| 519 | + |
|
| 520 | + $ret['20']['caption'] = '20'; |
|
| 521 | + $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : ''; |
|
| 522 | + |
|
| 523 | + $ret['25']['caption'] = '25'; |
|
| 524 | + $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : ''; |
|
| 525 | + |
|
| 526 | + $ret['30']['caption'] = '30'; |
|
| 527 | + $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : ''; |
|
| 528 | + |
|
| 529 | + $ret['35']['caption'] = '35'; |
|
| 530 | + $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : ''; |
|
| 531 | + |
|
| 532 | + $ret['40']['caption'] = '40'; |
|
| 533 | + $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : ''; |
|
| 534 | + |
|
| 535 | + return $ret; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @return bool |
|
| 540 | + */ |
|
| 541 | + public function getObjects() |
|
| 542 | + { |
|
| 543 | + return $this->_objects; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + public function hideActionColumnTitle() |
|
| 547 | + { |
|
| 548 | + $this->_showActionsColumnTitle = false; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + public function hideFilterAndLimit() |
|
| 552 | + { |
|
| 553 | + $this->_showFilterAndLimit = false; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @return array |
|
| 558 | + */ |
|
| 559 | + public function getOrdersArray() |
|
| 560 | + { |
|
| 561 | + $ret = []; |
|
| 562 | + $ret['ASC']['caption'] = _CO_SOBJECT_SORT_ASC; |
|
| 563 | + $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : ''; |
|
| 564 | + |
|
| 565 | + $ret['DESC']['caption'] = _CO_SOBJECT_SORT_DESC; |
|
| 566 | + $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : ''; |
|
| 567 | + |
|
| 568 | + return $ret; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @return mixed|string|void |
|
| 573 | + */ |
|
| 574 | + public function renderD() |
|
| 575 | + { |
|
| 576 | + return $this->render(false, true); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + public function renderForPrint() |
|
| 580 | + { |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * @param bool $fetchOnly |
|
| 585 | + * @param bool $debug |
|
| 586 | + * @return mixed|string|void |
|
| 587 | + */ |
|
| 588 | + public function render($fetchOnly = false, $debug = false) |
|
| 589 | + { |
|
| 590 | + require_once XOOPS_ROOT_PATH . '/class/template.php'; |
|
| 591 | + |
|
| 592 | + $this->_tpl = new \XoopsTpl(); |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * We need access to the vars of the SmartObject for a few things in the table creation. |
|
| 596 | + * Since we may not have a SmartObject to look into now, let's create one for this purpose |
|
| 597 | + * and we will free it after |
|
| 598 | + */ |
|
| 599 | + $this->_tempObject = $this->_objectHandler->create(); |
|
| 600 | + |
|
| 601 | + $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0); |
|
| 602 | + |
|
| 603 | + $this->setSortOrder(); |
|
| 604 | + |
|
| 605 | + if (!$this->_isTree) { |
|
| 606 | + $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : Smartobject\Utility::getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15'); |
|
| 607 | + } else { |
|
| 608 | + $this->_limitsel = 'all'; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel; |
|
| 612 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel); |
|
| 613 | + $limitsArray = $this->getLimitsArray(); |
|
| 614 | + $this->_criteria->setLimit($this->_limitsel); |
|
| 615 | + |
|
| 616 | + $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter(); |
|
| 617 | + $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel; |
|
| 618 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel); |
|
| 619 | + $filtersArray = $this->getFiltersArray(); |
|
| 620 | + |
|
| 621 | + if ($filtersArray) { |
|
| 622 | + $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + // Check if the selected filter is defined and if so, create the selfilter2 |
|
| 626 | + if (isset($this->_filterseloptions[$this->_filtersel])) { |
|
| 627 | + // check if method associate with this filter exists in the handler |
|
| 628 | + if (is_array($this->_filterseloptions[$this->_filtersel])) { |
|
| 629 | + $filter = $this->_filterseloptions[$this->_filtersel]; |
|
| 630 | + $this->_criteria->add($filter['criteria']); |
|
| 631 | + } else { |
|
| 632 | + if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) { |
|
| 633 | + |
|
| 634 | + // then we will create the selfilter2 options by calling this method |
|
| 635 | + $method = $this->_filterseloptions[$this->_filtersel]; |
|
| 636 | + $this->_filtersel2options = $this->_objectHandler->$method(); |
|
| 637 | + |
|
| 638 | + $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2(); |
|
| 639 | + $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2; |
|
| 640 | + |
|
| 641 | + $filters2Array = $this->getFilters2Array(); |
|
| 642 | + $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array); |
|
| 643 | + |
|
| 644 | + Smartobject\Utility::setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2); |
|
| 645 | + if ('default' !== $this->_filtersel2) { |
|
| 646 | + $this->_criteria->add(new \Criteria($this->_filtersel, $this->_filtersel2)); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + // Check if we have a quicksearch |
|
| 652 | + |
|
| 653 | + if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) { |
|
| 654 | + $quicksearch_criteria = new \CriteriaCompo(); |
|
| 655 | + if (is_array($this->_quickSearch['fields'])) { |
|
| 656 | + foreach ($this->_quickSearch['fields'] as $v) { |
|
| 657 | + $quicksearch_criteria->add(new \Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR'); |
|
| 658 | + } |
|
| 659 | + } else { |
|
| 660 | + $quicksearch_criteria->add(new \Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE')); |
|
| 661 | + } |
|
| 662 | + $this->_criteria->add($quicksearch_criteria); |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + $this->_objects = $this->fetchObjects($debug); |
|
| 666 | + |
|
| 667 | + require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
|
| 668 | + if ($this->_criteria->getLimit() > 0) { |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Geeting rid of the old params |
|
| 672 | + * $new_get_array is an array containing the new GET parameters |
|
| 673 | + */ |
|
| 674 | + $new_get_array = []; |
|
| 675 | + |
|
| 676 | + /** |
|
| 677 | + * $params_of_the_options_sel is an array with all the parameters of the page |
|
| 678 | + * but without the pagenave parameters. This array will be used in the |
|
| 679 | + * OptionsSelection |
|
| 680 | + */ |
|
| 681 | + $params_of_the_options_sel = []; |
|
| 682 | + |
|
| 683 | + $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName]; |
|
| 684 | + foreach ($_GET as $k => $v) { |
|
| 685 | + if (!in_array($k, $not_needed_params)) { |
|
| 686 | + $new_get_array[] = "$k=$v"; |
|
| 687 | + $params_of_the_options_sel[] = "$k=$v"; |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Adding the new params of the pagenav |
|
| 693 | + */ |
|
| 694 | + $new_get_array[] = 'sortsel=' . $this->_sortsel; |
|
| 695 | + $new_get_array[] = 'ordersel=' . $this->_ordersel; |
|
| 696 | + $new_get_array[] = 'limitsel=' . $this->_limitsel; |
|
| 697 | + $otherParams = implode('&', $new_get_array); |
|
| 698 | + |
|
| 699 | + $pagenav = new \XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams); |
|
| 700 | + $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav()); |
|
| 701 | + } |
|
| 702 | + $this->renderOptionSelection($limitsArray, $params_of_the_options_sel); |
|
| 703 | + |
|
| 704 | + // retreive the current url and the query string |
|
| 705 | + $current_urls = Smartobject\Utility::getCurrentUrls(); |
|
| 706 | + $current_url = $current_urls['full_phpself']; |
|
| 707 | + $query_string = $current_urls['querystring']; |
|
| 708 | + if ($query_string) { |
|
| 709 | + $query_string = str_replace('?', '', $query_string); |
|
| 710 | + } |
|
| 711 | + $query_stringArray = explode('&', $query_string); |
|
| 712 | + $new_query_stringArray = []; |
|
| 713 | + foreach ($query_stringArray as $query_string) { |
|
| 714 | + if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) { |
|
| 715 | + $new_query_stringArray[] = $query_string; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + $new_query_string = implode('&', $new_query_stringArray); |
|
| 719 | + |
|
| 720 | + $orderArray = []; |
|
| 721 | + $orderArray['ASC']['image'] = 'desc.png'; |
|
| 722 | + $orderArray['ASC']['neworder'] = 'DESC'; |
|
| 723 | + $orderArray['DESC']['image'] = 'asc.png'; |
|
| 724 | + $orderArray['DESC']['neworder'] = 'ASC'; |
|
| 725 | + |
|
| 726 | + $aColumns = []; |
|
| 727 | + |
|
| 728 | + foreach ($this->_columns as $column) { |
|
| 729 | + $qs_param = ''; |
|
| 730 | + $aColumn = []; |
|
| 731 | + $aColumn['width'] = $column->getWidth(); |
|
| 732 | + $aColumn['align'] = $column->getAlign(); |
|
| 733 | + $aColumn['key'] = $column->getKeyName(); |
|
| 734 | + if ('checked' === $column->_keyname) { |
|
| 735 | + $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">'; |
|
| 736 | + } elseif ($column->getCustomCaption()) { |
|
| 737 | + $aColumn['caption'] = $column->getCustomCaption(); |
|
| 738 | + } else { |
|
| 739 | + $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName(); |
|
| 740 | + } |
|
| 741 | + // Are we doing a GET sort on this column ? |
|
| 742 | + $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) |
|
| 743 | + && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName()) |
|
| 744 | + || ($this->_sortsel == $column->getKeyName()); |
|
| 745 | + $order = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC'; |
|
| 746 | + |
|
| 747 | + if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) { |
|
| 748 | + $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id]; |
|
| 749 | + } |
|
| 750 | + if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) { |
|
| 751 | + $aColumn['caption'] = $aColumn['caption']; |
|
| 752 | + } elseif ($getSort) { |
|
| 753 | + $aColumn['caption'] = '<a href="' |
|
| 754 | + . $current_url |
|
| 755 | + . '?' |
|
| 756 | + . $this->_objectHandler->_itemname |
|
| 757 | + . '_' |
|
| 758 | + . 'sortsel=' |
|
| 759 | + . $column->getKeyName() |
|
| 760 | + . '&' |
|
| 761 | + . $this->_objectHandler->_itemname |
|
| 762 | + . '_' |
|
| 763 | + . 'ordersel=' |
|
| 764 | + . $orderArray[$order]['neworder'] |
|
| 765 | + . $qs_param |
|
| 766 | + . '&' |
|
| 767 | + . $new_query_string |
|
| 768 | + . '">' |
|
| 769 | + . $aColumn['caption'] |
|
| 770 | + . ' <img src="' |
|
| 771 | + . SMARTOBJECT_IMAGES_ACTIONS_URL |
|
| 772 | + . $orderArray[$order]['image'] |
|
| 773 | + . '" alt="ASC"></a>'; |
|
| 774 | + } else { |
|
| 775 | + $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>'; |
|
| 776 | + } |
|
| 777 | + $aColumns[] = $aColumn; |
|
| 778 | + } |
|
| 779 | + $this->_tpl->assign('smartobject_columns', $aColumns); |
|
| 780 | + |
|
| 781 | + if ($this->_quickSearch) { |
|
| 782 | + $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']); |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $this->createTableRows(); |
|
| 786 | + |
|
| 787 | + $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit); |
|
| 788 | + $this->_tpl->assign('smartobject_isTree', $this->_isTree); |
|
| 789 | + $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle); |
|
| 790 | + $this->_tpl->assign('smartobject_table_header', $this->_tableHeader); |
|
| 791 | + $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter); |
|
| 792 | + $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage); |
|
| 793 | + $this->_tpl->assign('smartobject_user_side', $this->_userSide); |
|
| 794 | + $this->_tpl->assign('smartobject_has_actions', $this->_hasActions); |
|
| 795 | + $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class); |
|
| 796 | + $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons); |
|
| 797 | + $this->_tpl->assign('smartobject_introButtons', $this->_introButtons); |
|
| 798 | + $this->_tpl->assign('smartobject_id', $this->_id); |
|
| 799 | + if (!empty($this->_withSelectedActions)) { |
|
| 800 | + $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl'; |
|
| 804 | + if ($fetchOnly) { |
|
| 805 | + return $this->_tpl->fetch('db:' . $smartobjectTable_template); |
|
| 806 | + } else { |
|
| 807 | + $this->_tpl->display('db:' . $smartobjectTable_template); |
|
| 808 | + } |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + public function disableColumnsSorting() |
|
| 812 | + { |
|
| 813 | + $this->_enableColumnsSorting = false; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * @param bool $debug |
|
| 818 | + * @return mixed|string|void |
|
| 819 | + */ |
|
| 820 | + public function fetch($debug = false) |
|
| 821 | + { |
|
| 822 | + return $this->render(true, $debug); |
|
| 823 | + } |
|
| 824 | 824 | } |
@@ -30,22 +30,22 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class ObjectCurrencyHandler extends Smartobject\PersistableObjectHandler |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * SmartObjectCurrencyHandler constructor. |
|
| 35 | - * @param \XoopsDatabase $db |
|
| 36 | - */ |
|
| 37 | - public function __construct(\XoopsDatabase $db) |
|
| 38 | - { |
|
| 39 | - parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function getCurrencies() |
|
| 46 | - { |
|
| 47 | - $currenciesObj =& $this->getObjects(null, true); |
|
| 48 | - |
|
| 49 | - return $currenciesObj; |
|
| 50 | - } |
|
| 33 | + /** |
|
| 34 | + * SmartObjectCurrencyHandler constructor. |
|
| 35 | + * @param \XoopsDatabase $db |
|
| 36 | + */ |
|
| 37 | + public function __construct(\XoopsDatabase $db) |
|
| 38 | + { |
|
| 39 | + parent::__construct($db, 'currency', 'currencyid', 'name', '', 'smartobject'); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function getCurrencies() |
|
| 46 | + { |
|
| 47 | + $currenciesObj =& $this->getObjects(null, true); |
|
| 48 | + |
|
| 49 | + return $currenciesObj; |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -29,27 +29,27 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class TagHandler extends Smartobject\PersistableMlObjectHandler |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * SmartobjectTagHandler constructor. |
|
| 34 | - * @param \XoopsDatabase $db |
|
| 35 | - */ |
|
| 36 | - public function __construct(\XoopsDatabase $db) |
|
| 37 | - { |
|
| 38 | - parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * SmartobjectTagHandler constructor. |
|
| 34 | + * @param \XoopsDatabase $db |
|
| 35 | + */ |
|
| 36 | + public function __construct(\XoopsDatabase $db) |
|
| 37 | + { |
|
| 38 | + parent::__construct($db, 'tag', 'tagid', 'name', 'description', 'smartobject'); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return mixed |
|
| 43 | - */ |
|
| 44 | - public function getLanguages() |
|
| 45 | - { |
|
| 46 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 47 | - $aLanguages = XoopsLists::getLangList(); |
|
| 48 | - $ret['default'] = _CO_SOBJECT_ALL; |
|
| 49 | - foreach ($aLanguages as $lang) { |
|
| 50 | - $ret[$lang] = $lang; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * @return mixed |
|
| 43 | + */ |
|
| 44 | + public function getLanguages() |
|
| 45 | + { |
|
| 46 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
| 47 | + $aLanguages = XoopsLists::getLangList(); |
|
| 48 | + $ret['default'] = _CO_SOBJECT_ALL; |
|
| 49 | + foreach ($aLanguages as $lang) { |
|
| 50 | + $ret[$lang] = $lang; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return $ret; |
|
| 54 | - } |
|
| 53 | + return $ret; |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -23,82 +23,82 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class ObjectColumn |
| 25 | 25 | { |
| 26 | - public $_keyname; |
|
| 27 | - public $_align; |
|
| 28 | - public $_width; |
|
| 29 | - public $_customMethodForValue; |
|
| 30 | - public $_extraParams; |
|
| 31 | - public $_sortable; |
|
| 32 | - public $_customCaption; |
|
| 26 | + public $_keyname; |
|
| 27 | + public $_align; |
|
| 28 | + public $_width; |
|
| 29 | + public $_customMethodForValue; |
|
| 30 | + public $_extraParams; |
|
| 31 | + public $_sortable; |
|
| 32 | + public $_customCaption; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * SmartObjectColumn constructor. |
|
| 36 | - * @param $keyname |
|
| 37 | - * @param string $align |
|
| 38 | - * @param bool $width |
|
| 39 | - * @param bool $customMethodForValue |
|
| 40 | - * @param bool $param |
|
| 41 | - * @param bool $customCaption |
|
| 42 | - * @param bool $sortable |
|
| 43 | - */ |
|
| 44 | - public function __construct( |
|
| 45 | - $keyname, |
|
| 46 | - $align = 'left', |
|
| 47 | - $width = false, |
|
| 48 | - $customMethodForValue = false, |
|
| 49 | - $param = false, |
|
| 50 | - $customCaption = false, |
|
| 51 | - $sortable = true |
|
| 52 | - ) { |
|
| 53 | - $this->_keyname = $keyname; |
|
| 54 | - $this->_align = $align; |
|
| 55 | - $this->_width = $width; |
|
| 56 | - $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | - $this->_sortable = $sortable; |
|
| 58 | - $this->_param = $param; |
|
| 59 | - $this->_customCaption = $customCaption; |
|
| 60 | - } |
|
| 34 | + /** |
|
| 35 | + * SmartObjectColumn constructor. |
|
| 36 | + * @param $keyname |
|
| 37 | + * @param string $align |
|
| 38 | + * @param bool $width |
|
| 39 | + * @param bool $customMethodForValue |
|
| 40 | + * @param bool $param |
|
| 41 | + * @param bool $customCaption |
|
| 42 | + * @param bool $sortable |
|
| 43 | + */ |
|
| 44 | + public function __construct( |
|
| 45 | + $keyname, |
|
| 46 | + $align = 'left', |
|
| 47 | + $width = false, |
|
| 48 | + $customMethodForValue = false, |
|
| 49 | + $param = false, |
|
| 50 | + $customCaption = false, |
|
| 51 | + $sortable = true |
|
| 52 | + ) { |
|
| 53 | + $this->_keyname = $keyname; |
|
| 54 | + $this->_align = $align; |
|
| 55 | + $this->_width = $width; |
|
| 56 | + $this->_customMethodForValue = $customMethodForValue; |
|
| 57 | + $this->_sortable = $sortable; |
|
| 58 | + $this->_param = $param; |
|
| 59 | + $this->_customCaption = $customCaption; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function getKeyName() |
|
| 63 | - { |
|
| 64 | - return $this->_keyname; |
|
| 65 | - } |
|
| 62 | + public function getKeyName() |
|
| 63 | + { |
|
| 64 | + return $this->_keyname; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function getAlign() |
|
| 71 | - { |
|
| 72 | - return $this->_align; |
|
| 73 | - } |
|
| 67 | + /** |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function getAlign() |
|
| 71 | + { |
|
| 72 | + return $this->_align; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 78 | - public function isSortable() |
|
| 79 | - { |
|
| 80 | - return $this->_sortable; |
|
| 81 | - } |
|
| 75 | + /** |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | + public function isSortable() |
|
| 79 | + { |
|
| 80 | + return $this->_sortable; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * @return bool|string |
|
| 85 | - */ |
|
| 86 | - public function getWidth() |
|
| 87 | - { |
|
| 88 | - if ($this->_width) { |
|
| 89 | - $ret = $this->_width; |
|
| 90 | - } else { |
|
| 91 | - $ret = ''; |
|
| 92 | - } |
|
| 83 | + /** |
|
| 84 | + * @return bool|string |
|
| 85 | + */ |
|
| 86 | + public function getWidth() |
|
| 87 | + { |
|
| 88 | + if ($this->_width) { |
|
| 89 | + $ret = $this->_width; |
|
| 90 | + } else { |
|
| 91 | + $ret = ''; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return $ret; |
|
| 95 | - } |
|
| 94 | + return $ret; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 100 | - public function getCustomCaption() |
|
| 101 | - { |
|
| 102 | - return $this->_customCaption; |
|
| 103 | - } |
|
| 97 | + /** |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | + public function getCustomCaption() |
|
| 101 | + { |
|
| 102 | + return $this->_customCaption; |
|
| 103 | + } |
|
| 104 | 104 | } |
@@ -25,157 +25,157 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class TreeTable extends Smartobject\BaseSmartObjectTable |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * SmartObjectTreeTable constructor. |
|
| 30 | - * @param PersistableObjectHandler $objectHandler |
|
| 31 | - * @param bool $criteria |
|
| 32 | - * @param array $actions |
|
| 33 | - * @param bool $userSide |
|
| 34 | - */ |
|
| 35 | - public function __construct( |
|
| 36 | - PersistableObjectHandler $objectHandler, |
|
| 37 | - $criteria = false, |
|
| 38 | - $actions = ['edit', 'delete'], |
|
| 39 | - $userSide = false |
|
| 40 | - ) { |
|
| 41 | - $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
| 42 | - $this->_isTree = true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Get children objects given a specific parentid |
|
| 47 | - * |
|
| 48 | - * @var int $parentid id of the parent which children we want to retreive |
|
| 49 | - * @return array of SmartObject |
|
| 50 | - */ |
|
| 51 | - public function getChildrenOf($parentid = 0) |
|
| 52 | - { |
|
| 53 | - return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param $object |
|
| 58 | - * @param int $level |
|
| 59 | - */ |
|
| 60 | - public function createTableRow($object, $level = 0) |
|
| 61 | - { |
|
| 62 | - $aObject = []; |
|
| 63 | - |
|
| 64 | - $i = 0; |
|
| 65 | - |
|
| 66 | - $aColumns = []; |
|
| 67 | - $doWeHaveActions = false; |
|
| 68 | - |
|
| 69 | - foreach ($this->_columns as $column) { |
|
| 70 | - $aColumn = []; |
|
| 71 | - |
|
| 72 | - if (0 == $i) { |
|
| 73 | - $class = 'head'; |
|
| 74 | - } elseif (0 == $i % 2) { |
|
| 75 | - $class = 'even'; |
|
| 76 | - } else { |
|
| 77 | - $class = 'odd'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 81 | - $method = $column->_customMethodForValue; |
|
| 82 | - $value = $object->$method(); |
|
| 83 | - } else { |
|
| 84 | - /** |
|
| 85 | - * If the column is the identifier, then put a link on it |
|
| 86 | - */ |
|
| 87 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 88 | - $value = $object->getItemLink(); |
|
| 89 | - } else { |
|
| 90 | - $value = $object->getVar($column->getKeyName()); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $space = ''; |
|
| 95 | - if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 96 | - for ($i = 0; $i < $level; ++$i) { |
|
| 97 | - $space .= '--'; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ('' !== $space) { |
|
| 102 | - $space .= ' '; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $aColumn['value'] = $space . $value; |
|
| 106 | - $aColumn['class'] = $class; |
|
| 107 | - $aColumn['width'] = $column->getWidth(); |
|
| 108 | - $aColumn['align'] = $column->getAlign(); |
|
| 109 | - $aColumn['key'] = $column->getKeyName(); |
|
| 110 | - |
|
| 111 | - $aColumns[] = $aColumn; |
|
| 112 | - ++$i; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $aObject['columns'] = $aColumns; |
|
| 116 | - |
|
| 117 | - $class = 'even' === $class ? 'odd' : 'even'; |
|
| 118 | - $aObject['class'] = $class; |
|
| 119 | - |
|
| 120 | - $actions = []; |
|
| 121 | - |
|
| 122 | - // Adding the custom actions if any |
|
| 123 | - foreach ($this->_custom_actions as $action) { |
|
| 124 | - if (method_exists($object, $action)) { |
|
| 125 | - $actions[] = $object->$action(); |
|
| 126 | - } |
|
| 127 | - } |
|
| 28 | + /** |
|
| 29 | + * SmartObjectTreeTable constructor. |
|
| 30 | + * @param PersistableObjectHandler $objectHandler |
|
| 31 | + * @param bool $criteria |
|
| 32 | + * @param array $actions |
|
| 33 | + * @param bool $userSide |
|
| 34 | + */ |
|
| 35 | + public function __construct( |
|
| 36 | + PersistableObjectHandler $objectHandler, |
|
| 37 | + $criteria = false, |
|
| 38 | + $actions = ['edit', 'delete'], |
|
| 39 | + $userSide = false |
|
| 40 | + ) { |
|
| 41 | + $this->SmartObjectTable($objectHandler, $criteria, $actions, $userSide); |
|
| 42 | + $this->_isTree = true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Get children objects given a specific parentid |
|
| 47 | + * |
|
| 48 | + * @var int $parentid id of the parent which children we want to retreive |
|
| 49 | + * @return array of SmartObject |
|
| 50 | + */ |
|
| 51 | + public function getChildrenOf($parentid = 0) |
|
| 52 | + { |
|
| 53 | + return isset($this->_objects[$parentid]) ? $this->_objects[$parentid] : false; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param $object |
|
| 58 | + * @param int $level |
|
| 59 | + */ |
|
| 60 | + public function createTableRow($object, $level = 0) |
|
| 61 | + { |
|
| 62 | + $aObject = []; |
|
| 63 | + |
|
| 64 | + $i = 0; |
|
| 65 | + |
|
| 66 | + $aColumns = []; |
|
| 67 | + $doWeHaveActions = false; |
|
| 68 | + |
|
| 69 | + foreach ($this->_columns as $column) { |
|
| 70 | + $aColumn = []; |
|
| 71 | + |
|
| 72 | + if (0 == $i) { |
|
| 73 | + $class = 'head'; |
|
| 74 | + } elseif (0 == $i % 2) { |
|
| 75 | + $class = 'even'; |
|
| 76 | + } else { |
|
| 77 | + $class = 'odd'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ($column->_customMethodForValue && method_exists($object, $column->_customMethodForValue)) { |
|
| 81 | + $method = $column->_customMethodForValue; |
|
| 82 | + $value = $object->$method(); |
|
| 83 | + } else { |
|
| 84 | + /** |
|
| 85 | + * If the column is the identifier, then put a link on it |
|
| 86 | + */ |
|
| 87 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 88 | + $value = $object->getItemLink(); |
|
| 89 | + } else { |
|
| 90 | + $value = $object->getVar($column->getKeyName()); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $space = ''; |
|
| 95 | + if ($column->getKeyName() == $this->_objectHandler->identifierName) { |
|
| 96 | + for ($i = 0; $i < $level; ++$i) { |
|
| 97 | + $space .= '--'; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ('' !== $space) { |
|
| 102 | + $space .= ' '; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $aColumn['value'] = $space . $value; |
|
| 106 | + $aColumn['class'] = $class; |
|
| 107 | + $aColumn['width'] = $column->getWidth(); |
|
| 108 | + $aColumn['align'] = $column->getAlign(); |
|
| 109 | + $aColumn['key'] = $column->getKeyName(); |
|
| 110 | + |
|
| 111 | + $aColumns[] = $aColumn; |
|
| 112 | + ++$i; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $aObject['columns'] = $aColumns; |
|
| 116 | + |
|
| 117 | + $class = 'even' === $class ? 'odd' : 'even'; |
|
| 118 | + $aObject['class'] = $class; |
|
| 119 | + |
|
| 120 | + $actions = []; |
|
| 121 | + |
|
| 122 | + // Adding the custom actions if any |
|
| 123 | + foreach ($this->_custom_actions as $action) { |
|
| 124 | + if (method_exists($object, $action)) { |
|
| 125 | + $actions[] = $object->$action(); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | 129 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php'; |
| 130 | - $controller = new ObjectController($this->_objectHandler); |
|
| 131 | - |
|
| 132 | - if (in_array('edit', $this->_actions)) { |
|
| 133 | - $actions[] = $controller->getEditItemLink($object, false, true); |
|
| 134 | - } |
|
| 135 | - if (in_array('delete', $this->_actions)) { |
|
| 136 | - $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
| 137 | - } |
|
| 138 | - $aObject['actions'] = $actions; |
|
| 139 | - |
|
| 140 | - $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 141 | - $aObject['id'] = $object->id(); |
|
| 142 | - $this->_aObjects[] = $aObject; |
|
| 143 | - |
|
| 144 | - $childrenObjects = $this->getChildrenOf($object->id()); |
|
| 145 | - |
|
| 146 | - $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
| 147 | - |
|
| 148 | - if ($childrenObjects) { |
|
| 149 | - ++$level; |
|
| 150 | - foreach ($childrenObjects as $subObject) { |
|
| 151 | - $this->createTableRow($subObject, $level); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function createTableRows() |
|
| 157 | - { |
|
| 158 | - $this->_aObjects = []; |
|
| 159 | - |
|
| 160 | - if (count($this->_objects) > 0) { |
|
| 161 | - foreach ($this->getChildrenOf() as $object) { |
|
| 162 | - $this->createTableRow($object); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 166 | - } else { |
|
| 167 | - $colspan = count($this->_columns) + 1; |
|
| 168 | - $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @return mixed |
|
| 174 | - */ |
|
| 175 | - public function fetchObjects() |
|
| 176 | - { |
|
| 177 | - $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
| 178 | - |
|
| 179 | - return $ret; |
|
| 180 | - } |
|
| 130 | + $controller = new ObjectController($this->_objectHandler); |
|
| 131 | + |
|
| 132 | + if (in_array('edit', $this->_actions)) { |
|
| 133 | + $actions[] = $controller->getEditItemLink($object, false, true); |
|
| 134 | + } |
|
| 135 | + if (in_array('delete', $this->_actions)) { |
|
| 136 | + $actions[] = $controller->getDeleteItemLink($object, false, true); |
|
| 137 | + } |
|
| 138 | + $aObject['actions'] = $actions; |
|
| 139 | + |
|
| 140 | + $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30); |
|
| 141 | + $aObject['id'] = $object->id(); |
|
| 142 | + $this->_aObjects[] = $aObject; |
|
| 143 | + |
|
| 144 | + $childrenObjects = $this->getChildrenOf($object->id()); |
|
| 145 | + |
|
| 146 | + $this->_hasActions = $this->_hasActions ? true : count($actions) > 0; |
|
| 147 | + |
|
| 148 | + if ($childrenObjects) { |
|
| 149 | + ++$level; |
|
| 150 | + foreach ($childrenObjects as $subObject) { |
|
| 151 | + $this->createTableRow($subObject, $level); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function createTableRows() |
|
| 157 | + { |
|
| 158 | + $this->_aObjects = []; |
|
| 159 | + |
|
| 160 | + if (count($this->_objects) > 0) { |
|
| 161 | + foreach ($this->getChildrenOf() as $object) { |
|
| 162 | + $this->createTableRow($object); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + $this->_tpl->assign('smartobject_objects', $this->_aObjects); |
|
| 166 | + } else { |
|
| 167 | + $colspan = count($this->_columns) + 1; |
|
| 168 | + $this->_tpl->assign('smartobject_colspan', $colspan); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @return mixed |
|
| 174 | + */ |
|
| 175 | + public function fetchObjects() |
|
| 176 | + { |
|
| 177 | + $ret = $this->_objectHandler->getObjects($this->_criteria, 'parentid'); |
|
| 178 | + |
|
| 179 | + return $ret; |
|
| 180 | + } |
|
| 181 | 181 | } |