1
|
|
|
<?php |
2
|
|
|
// $Id: xdir_migrate.php wtravel |
3
|
|
|
// ------------------------------------------------------------------------ // |
4
|
|
|
// EFQ Directory // |
5
|
|
|
// Copyright (c) 2006 EFQ Consultancy // |
6
|
|
|
// <http://www.efqdirectory.com/> // |
7
|
|
|
// ------------------------------------------------------------------------ // |
8
|
|
|
// This program is free software; you can redistribute it and/or modify // |
9
|
|
|
// it under the terms of the GNU General Public License as published by // |
10
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
11
|
|
|
// (at your option) any later version. // |
12
|
|
|
// // |
13
|
|
|
// You may not change or alter any portion of this comment or credits // |
14
|
|
|
// of supporting developers from this source code or any supporting // |
15
|
|
|
// source code which is considered copyrighted (c) material of the // |
16
|
|
|
// original comment or credit authors. // |
17
|
|
|
// // |
18
|
|
|
// This program is distributed in the hope that it will be useful, // |
19
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
20
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
21
|
|
|
// GNU General Public License for more details. // |
22
|
|
|
// // |
23
|
|
|
// You should have received a copy of the GNU General Public License // |
24
|
|
|
// along with this program; if not, write to the Free Software // |
25
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
26
|
|
|
// ------------------------------------------------------------------------ // |
27
|
|
|
// Part of the efqDirectory module provided by: wtravel // |
28
|
|
|
// e-mail: [email protected] // |
29
|
|
|
// Purpose: Create a business directory for xoops. // |
30
|
|
|
// Based upon the mylinks and the mxDirectory modules // |
31
|
|
|
// ------------------------------------------------------------------------- // |
32
|
|
|
include __DIR__ . '/../../../include/cp_header.php'; |
33
|
|
View Code Duplication |
if (file_exists(__DIR__ . '/../language/' . $xoopsConfig['language'] . '/main.php')) { |
|
|
|
|
34
|
|
|
include __DIR__ . '/../language/' . $xoopsConfig['language'] . '/main.php'; |
35
|
|
|
} else { |
36
|
|
|
include __DIR__ . '/../language/english/main.php'; |
37
|
|
|
} |
38
|
|
|
include __DIR__ . '/../include/functions.php'; |
39
|
|
|
include __DIR__ . '/../class/class.fieldtype.php'; |
40
|
|
|
include __DIR__ . '/../class/class.datatype.php'; |
41
|
|
|
include __DIR__ . '/../class/class.directory.php'; |
42
|
|
|
include __DIR__ . '/../class/class.xdir.php'; |
43
|
|
|
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
|
|
|
44
|
|
|
include_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php'; |
45
|
|
|
$myts = MyTextSanitizer::getInstance(); |
|
|
|
|
46
|
|
|
$eh = new ErrorHandler; |
|
|
|
|
47
|
|
|
|
48
|
|
|
$moddir = $xoopsModule->getVar('dirname'); |
49
|
|
|
|
50
|
|
|
if (isset($_GET['dirid'])) { |
51
|
|
|
$get_dir = (int)$_GET['dirid']; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function xdirConfig() |
55
|
|
|
{ |
56
|
|
|
global $xoopsDB, $xoopsModule, $xoopsUser, $myts, $moddir; |
57
|
|
|
xoops_cp_header(); |
|
|
|
|
58
|
|
|
adminmenu(0, _MD_A_DIRADMIN); |
59
|
|
|
echo '<h4>' . _MD_MIGRATE_FROM_XDIR . '</h4>'; |
|
|
|
|
60
|
|
|
echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>"; |
61
|
|
|
$form = new XoopsThemeForm(_MD_XIDR_MIGRATE_TO_NEWDIR, 'submitform', 'xdir_migrate.php'); |
|
|
|
|
62
|
|
|
$form->addElement(new XoopsFormText(_MD_DIRNAME, 'dirname', 100, 150, ''), true); |
|
|
|
|
63
|
|
|
$form_diropen = new XoopsFormCheckBox(_MD_OPENYN, 'open', 0); |
|
|
|
|
64
|
|
|
$form_diropen->addOption(1, _MD_YESNO); |
65
|
|
|
$form->addElement($form_diropen); |
66
|
|
|
$form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit')); |
|
|
|
|
67
|
|
|
$form->addElement(new XoopsFormHidden('op', 'newdir')); |
|
|
|
|
68
|
|
|
$form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid'))); |
69
|
|
|
$form->display(); |
70
|
|
|
echo '</td></tr></table>'; |
71
|
|
|
xoops_cp_footer(); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
function newDir() |
75
|
|
|
{ |
76
|
|
|
global $xoopsDB, $_POST, $myts, $eh; |
77
|
|
|
if (isset($_POST['dirname']) and $_POST['dirname'] !== '') { |
78
|
|
|
$p_dirname = $_POST['dirname']; |
79
|
|
|
} else { |
80
|
|
|
redirect_header("directories.php?op=moddir&dirid=$db_dirid", 2, _MD_XDIR_CREATE_EMPTY_DIR); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
if (isset($_POST['open'])) { |
83
|
|
|
$p_open = $_POST['open']; |
84
|
|
|
} else { |
85
|
|
|
$p_open = 0; |
86
|
|
|
} |
87
|
|
|
$directory = new efqDirectory; |
88
|
|
|
$directory->setVar('name', $p_dirname); |
|
|
|
|
89
|
|
|
$directory->setVar('open', $p_open); |
90
|
|
|
$directoryHandler = new efqDirectoryHandler; |
91
|
|
|
$directoryHandler->insertDirectory($directory); |
92
|
|
|
$db_dirid = $directory->getVar('dirid'); |
93
|
|
|
|
94
|
|
|
if ($db_dirid > 0) { |
95
|
|
|
$xdirHandler = new efqXdirHandler(); |
96
|
|
|
$xdirHandler->doMigrate($db_dirid); |
97
|
|
|
$migration_errors = $xdirHandler->get_errors(); |
98
|
|
|
if (count($migration_errors) > 0) { |
99
|
|
|
redirect_header('xdir_migrate.php', 2, _MD_XDIR_MIGRATION_FAILED); |
|
|
|
|
100
|
|
|
} else { |
101
|
|
|
redirect_header('directories.php?op=moddir&dirid=' . $db_dirid, 2, _MD_XDIR_MIGRATION_COMPLETED); |
|
|
|
|
102
|
|
|
} |
103
|
|
|
} else { |
104
|
|
|
redirect_header('xdir_migrate.php', 2, _MD_XDIR_MIGRATION_FAILED); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
View Code Duplication |
if (!isset($_POST['op'])) { |
|
|
|
|
109
|
|
|
$op = isset($_GET['op']) ? $_GET['op'] : 'dirConfig'; |
110
|
|
|
} else { |
111
|
|
|
$op = $_POST['op']; |
112
|
|
|
} |
113
|
|
|
switch ($op) { |
114
|
|
|
|
115
|
|
|
case 'newdir': |
116
|
|
|
newDir(); |
117
|
|
|
break; |
118
|
|
|
default: |
119
|
|
|
xdirConfig(); |
120
|
|
|
break; |
121
|
|
|
} |
122
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.