1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits of |
4
|
|
|
supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit |
6
|
|
|
authors. |
7
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, but |
9
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Module: Pedigree |
15
|
|
|
* |
16
|
|
|
* @package \XoopsModules\Pedigree |
17
|
|
|
* @copyright Copyright (c) 2001-2019 {@link https://xoops.org XOOPS Project} |
18
|
|
|
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
19
|
|
|
* @author XOOPS Module Development Team |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
use Xmf\Request; |
|
|
|
|
23
|
|
|
use XoopsModules\Pedigree; |
24
|
|
|
use XoopsModules\Pedigree\Constants; |
25
|
|
|
|
26
|
|
|
require_once __DIR__ . '/header.php'; |
27
|
|
|
/** @var XoopsModules\Pedigree\Helper $helper */ |
28
|
|
|
$helper->loadLanguage('main'); |
29
|
|
|
|
30
|
|
|
// Include any common code for this module. |
31
|
|
|
require_once $helper->path('include/common.php'); |
32
|
|
|
|
33
|
|
|
$GLOBALS['xoopsOption']['template_main'] = 'pedigree_delete.tpl'; |
34
|
|
|
require XOOPS_ROOT_PATH . '/header.php'; |
35
|
|
|
|
36
|
|
|
//check XOOPS security token |
37
|
|
|
if (!$GLOBALS['xoopsSecurity']->check()) { |
38
|
|
|
$helper->redirect('', Constants::REDIRECT_DELAY_MEDIUM, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
//check for authorized user access |
42
|
|
|
if (empty($GLOBALS['xoopsUser']) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser)) { |
43
|
|
|
redirect_header('javascript:history.go(-1)', 3, _NOPERM . '<br>' . _MA_PEDIGREE_REGIST); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$dogid = Request::getInt('dogid', 0, 'post'); |
47
|
|
|
$dogname = Request::getString('curname', '', 'post'); |
48
|
|
|
|
49
|
|
|
if (!empty($dogname)) { |
50
|
|
|
$treeHandler = $helper->getHandler('Tree'); |
51
|
|
|
$treeObj = $treeHandler->get($dogid); |
52
|
|
|
if ($treeObj instanceof Pedigree\Tree && !$treeObj->isNew()) { |
53
|
|
|
$treeValues = $treeObj->getValues(); |
|
|
|
|
54
|
|
|
$trashHandler = $helper->getHandler('Trash'); |
55
|
|
|
$trashObj = $trashHandler->create(); |
56
|
|
|
$trashObj->setVars($treeValues); |
|
|
|
|
57
|
|
|
$trashHandler->insert($trashObj); |
58
|
|
|
$treeHandler->delete($treeObj); |
|
|
|
|
59
|
|
|
if (Constants::MALE == $treeValues['roft']) { |
60
|
|
|
$criteria = new \Criteria('father', $dogid); |
61
|
|
|
$treeHandler->updateAll('father', 0, $criteria); |
|
|
|
|
62
|
|
|
} else { |
63
|
|
|
$criteria = new \Criteria('mother', $dogid); |
64
|
|
|
$treeHandler->updateAll('mother', 0, $criteria); |
65
|
|
|
} |
66
|
|
|
$helper->redirect('index.php', Constants::REDIRECT_DELAY_MEDIUM, _MD_DATACHANGED); |
67
|
|
|
} else { |
68
|
|
|
//@todo display more descriptive error message |
69
|
|
|
$helper->redirect("dog.php?id={$dogid}", Constants::REDIRECT_DELAY_SHORT, 'ERROR!!'); |
70
|
|
|
} |
71
|
|
|
/* |
72
|
|
|
$sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE id=' . $dogid; |
73
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); |
74
|
|
|
while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
75
|
|
|
//check for edit rights |
76
|
|
|
$access = 0; |
77
|
|
|
$xoopsModule = XoopsModule::getByDirname($moduleDirName); |
78
|
|
|
if ($helper->isUserAdmin() || $row['user'] == $GLOBALS['xoopsUser']->getVar('uid')) { |
79
|
|
|
$sql = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_trash') . ' SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ' WHERE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . ".id='" . $dogid . "'"; |
80
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
81
|
|
|
$delsql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " WHERE id ='" . $row['id'] . "'"; |
82
|
|
|
$GLOBALS['xoopsDB']->query($delsql); |
83
|
|
|
if ('0' == $row['roft']) { |
84
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET father = '0' where father = '" . $row['id'] . "'"; |
85
|
|
|
} else { |
86
|
|
|
$sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('pedigree_registry') . " SET mother = '0' where mother = '" . $row['id'] . "'"; |
87
|
|
|
} |
88
|
|
|
$GLOBALS['xoopsDB']->query($sql); |
89
|
|
|
$changed = true; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
*/ |
93
|
|
|
} else { |
94
|
|
|
//@todo dog name was empty so send user back to try again |
95
|
|
|
} |
96
|
|
|
//footer |
97
|
|
|
require XOOPS_ROOT_PATH . '/footer.php'; |
98
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: