mambax7 /
extcal
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | namespace XoopsModules\Extcal; |
||
| 4 | |||
| 5 | /** |
||
| 6 | * classGenerator |
||
| 7 | * walls_watermarks. |
||
| 8 | * |
||
| 9 | * You may not change or alter any portion of this comment or credits |
||
| 10 | * of supporting developers from this source code or any supporting source code |
||
| 11 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 12 | * This program is distributed in the hope that it will be useful, |
||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 15 | * |
||
| 16 | * |
||
| 17 | * |
||
| 18 | * L'utilisation de ce formulaire d'adminitration suppose |
||
| 19 | * que la classe correspondante de la table a été générées avec classGenerator |
||
| 20 | **/ |
||
| 21 | require_once XOOPS_ROOT_PATH . '/class/uploader.php'; |
||
| 22 | |||
| 23 | use XoopsModules\Extcal\{Helper, |
||
| 24 | EventHandler, |
||
| 25 | CategoryHandler, |
||
| 26 | Common, |
||
| 27 | Constants |
||
| 28 | }; |
||
| 29 | |||
| 30 | /** @var CategoryHandler $categoryHandler */ |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Class Utility |
||
| 34 | */ |
||
| 35 | class Utility extends Common\SysUtility |
||
| 36 | { |
||
| 37 | //--------------- Custom module methods ----------------------------- |
||
| 38 | /** |
||
| 39 | * @param $eventId |
||
| 40 | * |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | public static function getEvent($eventId) |
||
| 44 | { |
||
| 45 | $eventHandler = Helper::getInstance()->getHandler(\_EXTCAL_CLN_EVENT); |
||
| 46 | $event = $eventHandler->getEvent($eventId); |
||
| 47 | $t = $event->getVars(); |
||
| 48 | $data = []; |
||
| 49 | // while (list($key, $val) = each($t)) { |
||
| 50 | foreach ($t as $key => $val) { |
||
| 51 | $data[$key] = $val['value']; |
||
| 52 | } |
||
| 53 | |||
| 54 | return $data; |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @param $REQUEST |
||
| 59 | * @param $event_picture1 |
||
| 60 | * @param $event_picture2 |
||
| 61 | */ |
||
| 62 | public static function loadImg($REQUEST, &$event_picture1, &$event_picture2) |
||
| 63 | { |
||
| 64 | /////////////////////////////////////////////////////////////////////////////// |
||
| 65 | $uploaddir_event = XOOPS_ROOT_PATH . '/uploads/extcal/'; |
||
| 66 | $uploadurl_event = XOOPS_URL . '/uploads/extcal/'; |
||
| 67 | //$picture = ''; |
||
| 68 | for ($j = 1; $j < 3; ++$j) { |
||
| 69 | $delimg = @$REQUEST['delimg_' . $j . '']; |
||
| 70 | $delimg = isset($delimg) ? (int)$delimg : 0; |
||
| 71 | if (0 == $delimg && !empty($REQUEST['xoops_upload_file'][$j])) { |
||
| 72 | $upload = new \XoopsMediaUploader( |
||
| 73 | $uploaddir_event, [ |
||
| 74 | 'image/gif', |
||
| 75 | 'image/jpeg', |
||
| 76 | 'image/pjpeg', |
||
| 77 | 'image/x-png', |
||
| 78 | 'image/png', |
||
| 79 | 'image/jpg', |
||
| 80 | ], 3145728, null, null |
||
| 81 | ); |
||
| 82 | if ($upload->fetchMedia($REQUEST['xoops_upload_file'][$j])) { |
||
| 83 | $upload->setPrefix('event_'); |
||
| 84 | $upload->fetchMedia($REQUEST['xoops_upload_file'][$j]); |
||
| 85 | if (!$upload->upload()) { |
||
| 86 | $errors = $upload->getErrors(); |
||
| 87 | \redirect_header('<script>javascript:history.go(-1)</script>', 3, $errors); |
||
| 88 | } else { |
||
| 89 | if (1 == $j) { |
||
| 90 | $event_picture1 = $upload->getSavedFileName(); |
||
| 91 | } elseif (2 == $j) { |
||
| 92 | $event_picture2 = $upload->getSavedFileName(); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } elseif (!empty($REQUEST['file' . $j])) { |
||
| 96 | if (1 == $j) { |
||
| 97 | $event_picture1 = $REQUEST['file' . $j]; |
||
| 98 | } elseif (2 == $j) { |
||
| 99 | $event_picture2 = $REQUEST['file' . $j]; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } else { |
||
| 103 | $url_event = XOOPS_ROOT_PATH . '/uploads/extcal/' . $REQUEST['file' . $j]; |
||
| 104 | if (1 == $j) { |
||
| 105 | $event_picture1 = ''; |
||
| 106 | } elseif (2 == $j) { |
||
| 107 | $event_picture2 = ''; |
||
| 108 | } |
||
| 109 | if (\is_file($url_event)) { |
||
| 110 | \chmod($url_event, 0777); |
||
| 111 | \unlink($url_event); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | //exit; |
||
| 116 | /////////////////////////////////////////////////////////////////////////////// |
||
| 117 | } |
||
| 118 | |||
| 119 | /******************************************************************* |
||
| 120 | * |
||
| 121 | ****************************************************************** |
||
| 122 | * @param $cat |
||
| 123 | * @param bool $addNone |
||
| 124 | * @param string $name |
||
| 125 | * @return \XoopsFormSelect |
||
| 126 | */ |
||
| 127 | public static function getListCategories($cat, $addNone = true, $name = 'cat') |
||
| 128 | { |
||
| 129 | global $xoopsUser; |
||
| 130 | // Category selectbox |
||
| 131 | $categoryHandler = Helper::getInstance()->getHandler(\_EXTCAL_CLN_CAT); |
||
| 132 | |||
| 133 | $catsList = $categoryHandler->getAllCat($xoopsUser); |
||
| 134 | $catSelect = new \XoopsFormSelect('', $name, $cat); |
||
| 135 | if ($addNone) { |
||
| 136 | $catSelect->addOption(0, ' '); |
||
| 137 | } |
||
| 138 | |||
| 139 | foreach ($catsList as $catList) { |
||
| 140 | $catSelect->addOption($catList->getVar('cat_id'), $catList->getVar('cat_name')); |
||
| 141 | } |
||
| 142 | |||
| 143 | return $catSelect; |
||
| 144 | } |
||
| 145 | |||
| 146 | /******************************************************************* |
||
| 147 | * |
||
| 148 | ****************************************************************** |
||
| 149 | * @param string $name |
||
| 150 | * @param array|int|null $cat |
||
| 151 | * @return array |
||
| 152 | */ |
||
| 153 | public static function getCheckeCategories($name = 'cat', $cat = null) |
||
| 154 | { |
||
| 155 | global $xoopsUser; |
||
| 156 | // Category selectbox |
||
| 157 | //<option style="background-color:#00FFFF;">VARCHAR</option> |
||
| 158 | |||
| 159 | $categoryHandler = Helper::getInstance()->getHandler(\_EXTCAL_CLN_CAT); |
||
| 160 | $catsList = $categoryHandler->getAllCat($xoopsUser); |
||
| 161 | |||
| 162 | $t = []; |
||
| 163 | foreach ($catsList as $catList) { |
||
| 164 | $cat_id = $catList->getVar('cat_id'); |
||
| 165 | $name = $catList->getVar('cat_name'); |
||
| 166 | $cat_color = $catList->getVar('cat_color'); |
||
| 167 | $checked = \in_array($cat_id, $cat) ? 'checked' : ''; |
||
| 168 | $cat = '' |
||
| 169 | . "<div style='float:left; margin-left:5px;'>" |
||
| 170 | . "<input type='checkbox' name='{$name}[{$cat_id}]' value='1' {$checked}>" |
||
| 171 | . "<div style='absolute:left;height:12px; width:6px; background-color:#{$cat_color}; border:1px solid #000000; float:left; margin-right:5px;' ></div>" |
||
| 172 | . " {$name}" |
||
| 173 | . '</div>'; |
||
| 174 | |||
| 175 | $t[] = $cat; |
||
| 176 | } |
||
| 177 | |||
| 178 | return $t; |
||
| 179 | } |
||
| 180 | |||
| 181 | /******************************************************************* |
||
| 182 | * |
||
| 183 | ****************************************************************** |
||
| 184 | * @param string $name |
||
| 185 | * @param string $caption |
||
| 186 | * @param mixed $default |
||
| 187 | * @param bool $addNone |
||
| 188 | * @return \XoopsFormSelect |
||
| 189 | */ |
||
| 190 | public static function getListOrderBy($name = 'orderby', $caption = '', $default = null, $addNone = false) |
||
| 191 | { |
||
| 192 | global $xoopsUser; |
||
| 193 | |||
| 194 | $select = new \XoopsFormSelect($caption, $name, $default); |
||
| 195 | if ($addNone) { |
||
| 196 | $select->addOption('', ''); |
||
| 197 | } |
||
| 198 | |||
| 199 | $select->addOption('year ASC', \_MD_EXTCAL_YEAR . ' ' . \_MD_EXTCAL_ORDER_BY_ASC); |
||
| 200 | $select->addOption('year DESC', \_MD_EXTCAL_YEAR . ' ' . \_MD_EXTCAL_ORDER_BY_DESC); |
||
| 201 | |||
| 202 | $select->addOption('month ASC', \_MD_EXTCAL_MONTH . ' ' . \_MD_EXTCAL_ORDER_BY_ASC); |
||
| 203 | $select->addOption('month DESC', \_MD_EXTCAL_MONTH . ' ' . \_MD_EXTCAL_ORDER_BY_DESC); |
||
| 204 | |||
| 205 | $select->addOption('event_title ASC', \_MD_EXTCAL_ALPHA . ' ' . \_MD_EXTCAL_ORDER_BY_ASC); |
||
| 206 | $select->addOption('event_title DESC', \_MD_EXTCAL_ALPHA . ' ' . \_MD_EXTCAL_ORDER_BY_DESC); |
||
| 207 | |||
| 208 | $select->addOption('cat_name ASC', \_MD_EXTCAL_CATEGORY . ' ' . \_MD_EXTCAL_ORDER_BY_ASC); |
||
| 209 | $select->addOption('cat_name DESC', \_MD_EXTCAL_CATEGORY . ' ' . \_MD_EXTCAL_ORDER_BY_DESC); |
||
| 210 | |||
| 211 | return $select; |
||
| 212 | } |
||
| 213 | |||
| 214 | /******************************************************************* |
||
| 215 | * |
||
| 216 | ****************************************************************** |
||
| 217 | * @param string $name |
||
| 218 | * @param string $caption |
||
| 219 | * @param mixed $default |
||
| 220 | * @return \XoopsFormSelect |
||
| 221 | */ |
||
| 222 | public static function getListAndOr($name = 'andor', $caption = '', $default = null) |
||
| 223 | { |
||
| 224 | global $xoopsUser; |
||
| 225 | |||
| 226 | $select = new \XoopsFormSelect($caption, $name, $default); |
||
| 227 | |||
| 228 | $select->addOption('AND', \_MD_EXTCAL_AND); |
||
| 229 | $select->addOption('OR', \_MD_EXTCAL_OR); |
||
| 230 | |||
| 231 | return $select; |
||
| 232 | } |
||
| 233 | |||
| 234 | /******************************************************************* |
||
| 235 | * |
||
| 236 | ****************************************************************** |
||
| 237 | * @param $name |
||
| 238 | * @param $caption |
||
| 239 | * @param $default |
||
| 240 | * @param $options |
||
| 241 | * @param string $sep |
||
| 242 | * @return \XoopsFormSelect |
||
| 243 | */ |
||
| 244 | public static function getList($name, $caption, $default, $options, $sep = ';') |
||
| 245 | { |
||
| 246 | global $xoopsUser; |
||
| 247 | |||
| 248 | $select = new \XoopsFormSelect($caption, $name, $default); |
||
| 249 | if (!\is_array($options)) { |
||
| 250 | $options = \explode($sep, $options); |
||
| 251 | } |
||
| 252 | |||
| 253 | foreach ($options as $h => $hValue) { |
||
| 254 | $select->addOption($h, $options[$h]); |
||
| 255 | } |
||
| 256 | |||
| 257 | return $select; |
||
| 258 | } |
||
| 259 | |||
| 260 | /******************************************************************* |
||
| 261 | * |
||
| 262 | ****************************************************************** |
||
| 263 | * @param $ts |
||
| 264 | * @param $startMonth |
||
| 265 | * @param $endMonth |
||
| 266 | * @param string $mode |
||
| 267 | * @return \DateTime |
||
| 268 | * @throws \Exception |
||
| 269 | * @throws \Exception |
||
| 270 | */ |
||
| 271 | public static function getDateBetweenDates($ts, $startMonth, $endMonth, $mode = 'w') |
||
| 272 | { |
||
| 273 | $d = new \DateTime($periodStart); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 274 | $d->setTimestamp($ts); |
||
| 275 | |||
| 276 | //echo "<br>affichage des periodes : <br>"; |
||
| 277 | $begin = new \DateTime(); |
||
| 278 | $begin->setTimestamp($startMonth); |
||
| 279 | //echo $begin->format("d/m/Y Ã H\hi:s").'<br>'; // 03/10/2007 Ã 19h39:53 |
||
| 280 | |||
| 281 | $end = new \DateTime(); |
||
| 282 | $end->setTimestamp($endMonth); |
||
| 283 | //echo $end->format("d/m/Y Ã H\hi:s").'<br>'; // 03/10/2007 Ã 19h39:53 |
||
| 284 | //echo "<hr>"; |
||
| 285 | $interval = \DateInterval::createFromDateString('next sunday'); |
||
| 286 | $period = new \DatePeriod($begin, $interval, $end); |
||
| 287 | //echoDateArray($period); |
||
| 288 | |||
| 289 | //echo "<hr>{$interval}"; |
||
| 290 | return $d; |
||
| 291 | //echo mktime($heure, $minute, $seconde, $mois, $jour, $an); |
||
| 292 | |||
| 293 | // |
||
| 294 | // $jour = date('d', $ts); |
||
| 295 | // $mois = date('m', $ts); |
||
| 296 | // $an = date('Y', $ts); |
||
| 297 | // $heure = date('H', $ts); |
||
| 298 | // $minute = date('i', $ts); |
||
| 299 | // $seconde = date('s', $ts); |
||
| 300 | // $d->setDate($heure,$minute,$seconde,$mois,$jour,$an); |
||
| 301 | |||
| 302 | // <?php |
||
| 303 | // $interval = DateInterval::createFromDateString('next sunday'); |
||
| 304 | // $period = new \DatePeriod($begin, $interval, $end); |
||
| 305 | // foreach ($period as $dt) { |
||
| 306 | // echo $dt->format( "l Y-m-d H:i:s\n" ); |
||
| 307 | } |
||
| 308 | |||
| 309 | /* |
||
| 310 | Sunday 2009-11-01 00:00:00 |
||
| 311 | Sunday 2009-11-08 00:00:00 |
||
| 312 | Sunday 2009-11-15 00:00:00 |
||
| 313 | Sunday 2009-11-22 00:00:00 |
||
| 314 | Sunday 2009-11-29 00:00:00 |
||
| 315 | Sunday 2009-12-06 00:00:00 |
||
| 316 | ... |
||
| 317 | */ |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @param $period |
||
| 321 | */ |
||
| 322 | public static function echoDateArray($period) |
||
| 323 | { |
||
| 324 | foreach ($period as $dt) { |
||
| 325 | echo $dt->format("l Y-m-d H:i:s\n") . '<br>'; |
||
| 326 | } |
||
| 327 | } |
||
| 328 | |||
| 329 | /*****************************************************************/ |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param $t |
||
| 333 | * @param string $msg |
||
| 334 | */ |
||
| 335 | public static function echoArray($t, $msg = '') |
||
| 336 | { |
||
| 337 | if ('' != $msg) { |
||
| 338 | echo "<hr>{$msg}<hr>"; |
||
| 339 | } |
||
| 340 | |||
| 341 | $txt = \print_r($t, true); |
||
| 342 | echo '<pre>Number of items: ' . \count($t) . "<br>{$txt}</pre>"; |
||
| 343 | } |
||
| 344 | |||
| 345 | /*****************************************************************/ |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @param $line |
||
| 349 | * @param string $msg |
||
| 350 | */ |
||
| 351 | public static function extEcho($line, $msg = '') |
||
| 352 | { |
||
| 353 | if ('' != $msg) { |
||
| 354 | echo "<hr>{$msg}<hr>"; |
||
| 355 | } |
||
| 356 | echo $line . '<br>'; |
||
| 357 | } |
||
| 358 | |||
| 359 | /*****************************************************************/ |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @param $tsName |
||
| 363 | * @param string $msg |
||
| 364 | */ |
||
| 365 | public static function echoTsn($tsName, $msg = '') |
||
| 366 | { |
||
| 367 | global $$tsName; |
||
| 368 | $ts = $$tsName; |
||
| 369 | static::echoTsu($ts, $tsName, $msg = ''); |
||
| 370 | } |
||
| 371 | |||
| 372 | /*****************************************************************/ |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @param $ts |
||
| 376 | * @param $tsName |
||
| 377 | * @param string $msg |
||
| 378 | */ |
||
| 379 | public static function echoTsu($ts, $tsName, $msg = '') |
||
| 380 | { |
||
| 381 | if ('' != $msg) { |
||
| 382 | echo "<hr>{$msg}<hr>"; |
||
| 383 | } |
||
| 384 | |||
| 385 | echo 'date --->' . $tsName . ' = ' . $ts . ' - ' . \date('d-m-Y H:m:s', $ts) . '<br>'; |
||
| 386 | } |
||
| 387 | |||
| 388 | /*****************************************************************/ |
||
| 389 | /*****************************************************************/ |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @param $date |
||
| 393 | * @param string $sep |
||
| 394 | * |
||
| 395 | * @return int |
||
| 396 | */ |
||
| 397 | public static function convertDate($date, $sep = '-') |
||
| 398 | { |
||
| 399 | $lstSep = '/ .'; |
||
| 400 | |||
| 401 | for ($h = 0, $count = mb_strlen($lstSep); $h < $count; ++$h) { |
||
| 402 | $sep2replace = mb_substr($lstSep, $h, 1); |
||
| 403 | if (mb_strpos($date, $sep2replace)) { |
||
| 404 | $date = \str_replace($sep2replace, $sep, $date); |
||
| 405 | } |
||
| 406 | |||
| 407 | return \strtotime($date); |
||
| 408 | } |
||
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @param $givendate |
||
| 413 | * @param int $day |
||
| 414 | * @param int $mth |
||
| 415 | * @param int $yr |
||
| 416 | * |
||
| 417 | * @return int |
||
| 418 | */ |
||
| 419 | public static function addDate($givendate, $day = 0, $mth = 0, $yr = 0) |
||
| 420 | { |
||
| 421 | //$cd = strtotime($givendate); |
||
| 422 | $cd = $givendate; |
||
| 423 | $newdate = \date('Y-m-d h:i:s', \mktime(\date('h', $cd), \date('i', $cd), \date('s', $cd), \date('m', $cd) + $mth, \date('d', $cd) + $day, \date('Y', $cd) + $yr)); |
||
| 424 | |||
| 425 | return \strtotime($newdate); |
||
| 426 | } |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @param $date |
||
| 430 | * @param $number |
||
| 431 | * @param $interval |
||
| 432 | * |
||
| 433 | * @return int |
||
| 434 | */ |
||
| 435 | public static function addDate2($date, $number, $interval = 'd') |
||
| 436 | { |
||
| 437 | $date_time_array = \getdate($date); |
||
| 438 | $hours = $date_time_array['hours']; |
||
| 439 | $minutes = $date_time_array['minutes']; |
||
| 440 | $seconds = $date_time_array['seconds']; |
||
| 441 | $month = $date_time_array['mon']; |
||
| 442 | $day = $date_time_array['mday']; |
||
| 443 | $year = $date_time_array['year']; |
||
| 444 | |||
| 445 | switch ($interval) { |
||
| 446 | case 'yyyy': |
||
| 447 | $year += $number; |
||
| 448 | break; |
||
| 449 | case 'q': |
||
| 450 | $year += ($number * 3); |
||
| 451 | break; |
||
| 452 | case 'm': |
||
| 453 | $month += $number; |
||
| 454 | break; |
||
| 455 | case 'y': |
||
| 456 | case 'd': |
||
| 457 | case 'w': |
||
| 458 | $day += $number; |
||
| 459 | break; |
||
| 460 | case 'ww': |
||
| 461 | $day += ($number * 7); |
||
| 462 | break; |
||
| 463 | case 'h': |
||
| 464 | $hours += $number; |
||
| 465 | break; |
||
| 466 | case 'n': |
||
| 467 | $minutes += $number; |
||
| 468 | break; |
||
| 469 | case 's': |
||
| 470 | $seconds += $number; |
||
| 471 | break; |
||
| 472 | } |
||
| 473 | $timestamp = \mktime($hours, $minutes, $seconds, $month, $day, $year); |
||
| 474 | |||
| 475 | return $timestamp; |
||
| 476 | } |
||
| 477 | |||
| 478 | // function date_diff($date1, $date2) { |
||
| 479 | // $current = $date1; |
||
| 480 | // $datetime2 = date_create($date2); |
||
| 481 | // $count = 0; |
||
| 482 | // while (date_create($current) < $datetime2) { |
||
| 483 | // $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current))); |
||
| 484 | // ++$count; |
||
| 485 | // } |
||
| 486 | // return $count; |
||
| 487 | // } |
||
| 488 | |||
| 489 | /**************************************************************************/ |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @param $color |
||
| 493 | * @param $plancher |
||
| 494 | * @param $plafond |
||
| 495 | * |
||
| 496 | * @return string |
||
| 497 | */ |
||
| 498 | public static function getLighterColor($color, $plancher, $plafond) |
||
| 499 | { |
||
| 500 | // require_once __DIR__ . '/ColorTools.php'; |
||
| 501 | |||
| 502 | //$ct = new \ColorTools(); |
||
| 503 | //return $ct->eclaircir($color,$plancher,$plafond); |
||
| 504 | return ColorTools::eclaircir($color, $plancher, $plafond); |
||
| 505 | } |
||
| 506 | /**************************************************************************/ |
||
| 507 | } |
||
| 508 |