This repository has been archived by the owner on Sep 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar_menu_setup.php
204 lines (170 loc) · 4.55 KB
/
calendar_menu_setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Installation and update handler for event calendar plugin
*
* $Source: /cvs_backup/e107_0.8/e107_plugins/calendar_menu/languages/English_admin_calendar_menu.php,v $
* $Revision$
* $Date$
* $Author$
*/
/**
* e107 Event calendar plugin
*
* Plugin file - installation and update handling
*
* @package e107_plugins
* @subpackage event_calendar
* @version $Id$;
*/
if (!defined('e107_INIT')) { exit; }
e107::lan('calendar_menu', 'install', true);
class calendar_menu_setup // must match folder name ie. <pluginfolder>_setup
{
function install_post($param)
{
$somethingFailed = FALSE;
$mes = eMessage::getInstance();
if ($this->insertDefaultCategory(FALSE, $mes) == FALSE)
{
$somethingFailed = TRUE;
}
if ($somethingFailed)
{
$mes->add(EC_ADINST_LAN_04, E_MESSAGE_SUCCESS);
}
else
{
}
}
function install_pre($param)
{
// echo "Calendar uninstall routine<br />";
}
/**
* Called to see if plugin upgrade is required
*
* @param $param mixed - no purpose currently
* @return boolean TRUE if upgrade required, FALSE otherwise
*/
function upgrade_required($param = FALSE)
{
$required = FALSE;
$data = e107::pref('calendar_menu');
if (count($data) == 0)
{
$required = TRUE;
}
$pref = e107::pref('core'); // Core Prefs Array.
foreach($pref as $k=>$v)
{
if(substr($k, 0, 10) == 'eventpost_')
{
$required = TRUE; // Need to remove core prefs
break;
}
}
//print_a($data);
return $required;
}
/**
* Upgrade stage 1
*
* @param $param mixed - no purpose currently
* @return - none
*/
function upgrade_pre($param = FALSE)
{
$mes = eMessage::getInstance();
$calPref = e107::pref('calendar_menu');
if (count($calPref) == 0)
{ // Need to move prefs over
unset($calPref);
$calNew = e107::getPlugConfig('calendar_menu'); // Initialize calendar_menu prefs.
$corePrefs = e107::getConfig('core'); // Core Prefs Object.
$pref = e107::pref('core'); // Core Prefs Array.
foreach($pref as $k=>$v)
{
if(substr($k, 0, 10) == 'eventpost_')
{
$calNew->add($k, $v);
$corePrefs->remove($k);
}
}
$calNew->save();
$corePrefs->save();
$calPref = e107::pref('calendar_menu'); // retrieve calendar_menu pref array.
//print_a($calPref);
$mes->add(EC_ADINST_LAN_10, E_MESSAGE_SUCCESS);
}
else
{
$corePrefs = e107::getConfig('core'); // Core Prefs Object.
$pref = e107::pref('core'); // Core Prefs Array.
$removed = FALSE;
foreach ($calPref as $k => $v)
{
if (isset($pref[$k]))
{
$corePrefs->remove($k);
$removed = TRUE;
}
}
if ($removed)
{
$corePrefs->save();
$mes->add(EC_ADINST_LAN_11, E_MESSAGE_INFO); // Old prefs removed from core
}
else
{
$mes->add(EC_ADINST_LAN_09, E_MESSAGE_INFO); // Nothing to do - prefs already moved
}
}
}
/**
* Upgrade final stage - add default category
*
* @param $param mixed - no purpose currently
* @return - none
*/
function upgrade_post($param)
{
$this->insertDefaultCategory(TRUE);
}
/**
* Make sure default category is in calendar database; add it if not.
*
* Adds an appropriate message to the passed message handler.
* Returns TRUE if the call can be deemed a success (category present or added); FALSE on error
*/
function insertDefaultCategory($isUpgrade) // Insert the text for the default category into the DB here
{
$mes = eMessage::getInstance();
$sql = e107::getDb();
require_once(e_PLUGIN.'calendar_menu/ecal_class.php'); // Gets the define for the 'Default' category
if ($isUpgrade && $sql->db_Select('event_cat','event_cat_name',"event_cat_name='".EC_DEFAULT_CATEGORY."' "))
{
$mes->add(EC_ADINST_LAN_08, E_MESSAGE_INFO); // Nothing to do - default category already present
return TRUE;
}
$ec_insert_entries = "INSERT INTO `#event_cat` (event_cat_name, event_cat_description, event_cat_ahead, event_cat_msg1, event_cat_msg2, event_cat_lastupdate)
VALUES ('".EC_DEFAULT_CATEGORY."', '".EC_ADINST_LAN_03."', 5,
'".EC_ADINST_LAN_01."', '".EC_ADINST_LAN_02."',
'".intval(time())."') ";
if ($result = $sql->db_Select_gen($ec_insert_entries))
{
$mes->add(EC_ADINST_LAN_06, E_MESSAGE_SUCCESS);
}
else
{
$mes->add(EC_ADINST_LAN_07, E_MESSAGE_ERROR);
}
return $result;
}
}
?>