PageRenderTime 31ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

/AutoUpdate/Update1_2_9To1_2_10.php

https://github.com/jwigal/emcommdb
PHP | 727 lines | 520 code | 160 blank | 47 comment | 127 complexity | 7ab8e4782bce4239349ed19954e222ea MD5 | raw file
  1<?php
  2/*******************************************************************************
  3*
  4*  filename    : Update1_2_9To1_2_10.php
  5*  description : Update MySQL database from 1.2.9 To 1.2.10
  6*
  7*  http://www.churchdb.org/
  8*
  9*  Contributors:
 10*  2007 Ed Davis
 11*
 12*  Copyright Contributors
 13*
 14*  ChurchInfo is free software; you can redistribute it and/or modify
 15*  it under the terms of the GNU General Public License as published by
 16*  the Free Software Foundation; either version 2 of the License, or
 17*  (at your option) any later version.
 18*
 19*  This file best viewed in a text editor with tabs stops set to 4 characters
 20*
 21******************************************************************************/
 22$sVersion = '1.2.10';
 23
 24for (; ; ) {    // This is not a loop but a section of code to be 
 25                // executed once.  If an error occurs running a query the
 26                // remaining code section is skipped and all table 
 27                // modifications are "un-done" at the end.
 28                // The idea here is that upon failure the users database
 29                // is restored to the previous version.
 30
 31// **************************************************************************
 32// Make a backup copy of config_cfg before making changes to the table.  This
 33// makes it possible to recover from an error.
 34
 35$sSQL = "DROP TABLE IF EXISTS `tempconfig_tcfg`";
 36RunQuery($sSQL, TRUE);
 37
 38$sSQL = "CREATE TABLE `tempconfig_tcfg` (
 39  `cfg_id` int(11) NOT NULL default '0',
 40  `cfg_name` varchar(50) NOT NULL default '',
 41  `cfg_value` text,
 42  `cfg_type` enum('text','number','date','boolean','textarea') NOT NULL default 'text',
 43  `cfg_default` text NOT NULL,
 44  `cfg_tooltip` text NOT NULL,
 45  `cfg_section` varchar(50) NOT NULL default '',
 46  PRIMARY KEY  (`cfg_id`),
 47  UNIQUE KEY `tcfg_name` (`cfg_name`),
 48  KEY `cfg_id` (`cfg_id`)
 49) ENGINE=MyISAM";
 50RunQuery($sSQL, TRUE);
 51
 52$sSQL = "INSERT INTO `tempconfig_tcfg` 
 53SELECT `cfg_id`,`cfg_name`,`cfg_value`,`cfg_type`,`cfg_default`,`cfg_tooltip`,`cfg_section`
 54FROM `config_cfg` ORDER BY `cfg_id`";
 55RunQuery($sSQL, TRUE);
 56
 57// Make a backup copy of list_lst before making changes to the table.  This
 58// makes it possible to recover from an error.
 59
 60$sSQL = "DROP TABLE IF EXISTS `templist_tlst`";
 61RunQuery($sSQL, TRUE);
 62
 63$sSQL = "CREATE TABLE IF NOT EXISTS `templist_tlst` (
 64  `lst_ID` mediumint(8) unsigned NOT NULL default '0',
 65  `lst_OptionID` mediumint(8) unsigned NOT NULL default '0',
 66  `lst_OptionSequence` tinyint(3) unsigned NOT NULL default '0',
 67  `lst_OptionName` varchar(50) NOT NULL default ''
 68) ENGINE=MyISAM";
 69RunQuery($sSQL, TRUE);
 70
 71$sSQL = "INSERT INTO `templist_tlst` 
 72SELECT `lst_ID`,`lst_OptionID`,`lst_OptionSequence`,`lst_OptionName`
 73FROM `list_lst` ORDER BY `lst_id`, `lst_OptionID`";
 74RunQuery($sSQL, TRUE);
 75
 76// Make a backup copy of userconfig_ucfg before making changes to the table.  This
 77// makes it possible to recover from an error.
 78
 79$sSQL = "DROP TABLE IF EXISTS `tempuserconfig_tucfg`";
 80RunQuery($sSQL, TRUE);
 81
 82$sSQL = "CREATE TABLE IF NOT EXISTS `tempuserconfig_tucfg` (
 83  `ucfg_per_id` mediumint(9) unsigned NOT NULL,
 84  `ucfg_id` int(11) NOT NULL default '0',
 85  `ucfg_name` varchar(50) NOT NULL default '',
 86  `ucfg_value` text,
 87  `ucfg_type` enum('text','number','date','boolean','textarea') NOT NULL default 'text',
 88  `ucfg_tooltip` text NOT NULL,
 89  `ucfg_permission` enum('FALSE','TRUE') NOT NULL default 'FALSE',
 90  PRIMARY KEY  (`ucfg_per_ID`,`ucfg_id`)
 91) ENGINE=MyISAM";
 92RunQuery($sSQL, TRUE);
 93
 94$sSQL = "INSERT INTO `tempuserconfig_tucfg` 
 95SELECT `ucfg_per_id`,`ucfg_id`,`ucfg_name`,`ucfg_value`, `ucfg_type`, `ucfg_tooltip`, `ucfg_permission`
 96FROM `userconfig_ucfg` ORDER BY `ucfg_per_ID`, `ucfg_id`";
 97RunQuery($sSQL, TRUE);
 98
 99// Make a backup copy of person_custom_master before making changes to the table.  This
100// makes it possible to recover from an error.
101
102$sSQL = "DROP TABLE IF EXISTS `temp_person_custom_master`";
103RunQuery($sSQL, TRUE);
104
105$sSQL = "CREATE TABLE IF NOT EXISTS `temp_person_custom_master` (
106  `custom_Order` smallint(6) NOT NULL default '0',
107  `custom_Field` varchar(5) NOT NULL default '',
108  `custom_Name` varchar(40) NOT NULL default '',
109  `custom_Special` mediumint(8) unsigned default NULL,
110  `custom_Side` enum('left','right') NOT NULL default 'left',
111  `type_ID` tinyint(4) NOT NULL default '0'
112) ENGINE=MyISAM";
113RunQuery($sSQL, TRUE);
114
115$sSQL = "INSERT INTO `temp_person_custom_master` 
116SELECT `custom_Order`, `custom_Field`, `custom_Name`, `custom_Special`, `custom_Side`, `type_ID` 
117FROM `person_custom_master` ";
118RunQuery($sSQL, TRUE);
119
120// ********************************************************
121// ********************************************************
122// Begin modifying tables now that backups are available
123// The $bStopOnError argument to RunQuery can now be changed from
124// TRUE to FALSE now that backup copies of all tables are available
125
126$sSQL = "DROP TABLE IF EXISTS `menuconfig_mcf`";
127if (!RunQuery($sSQL, FALSE))
128    break;
129
130$sSQL = "CREATE TABLE `menuconfig_mcf` (
131  `mid` int(11) NOT NULL auto_increment,
132  `name` varchar(20) NOT NULL,
133  `parent` varchar(20) NOT NULL,
134  `ismenu` tinyint(1) NOT NULL,
135  `content` varchar(100) NOT NULL,
136  `uri` varchar(255) NOT NULL,
137  `statustext` varchar(255) NOT NULL,
138  `security_grp` varchar(50) NOT NULL,
139  `session_var` varchar(50) default NULL,
140  `session_var_in_text` tinyint(1) NOT NULL,
141  `session_var_in_uri` tinyint(1) NOT NULL,
142  `url_parm_name` varchar(50) default NULL,
143  `active` tinyint(1) NOT NULL,
144  `sortorder` tinyint(3) NOT NULL,
145  PRIMARY KEY  (`mid`)
146) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=81 ";
147if (!RunQuery($sSQL, FALSE))
148    break;
149
150$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (1, 'ROOT', '', 1, '".gettext('Main')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 0)";
151if (!RunQuery($sSQL, FALSE))
152    break;
153
154$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (2, 'main', 'root', 1, '".gettext('Main')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
155if (!RunQuery($sSQL, FALSE))
156    break;
157
158
159$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (3, 'logoff', 'main', 0, '".gettext('Log Off')."', 'Default.php?Logoff=True', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
160if (!RunQuery($sSQL, FALSE))
161    break;
162
163$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (4, 'chgpassword', 'main', 0, '".gettext('Change My Password')."', 'UserPasswordChange.php', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
164if (!RunQuery($sSQL, FALSE))
165    break;
166
167$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (5, 'chgsetting', 'main', 0, '".gettext('Change My Settings')."', 'SettingsIndividual.php', '', 'bAll', NULL, 0, 0, NULL, 1, 0)";
168if (!RunQuery($sSQL, FALSE))
169    break;
170
171$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (6, 'admin', 'root', 1, '".gettext('Admin')."', '', '', 'bAdmin', NULL, 0, 0, NULL, 1, 2)";
172if (!RunQuery($sSQL, FALSE))
173    break;
174
175$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (7, 'editusers', 'admin', 0, '".gettext('Edit Users')."', 'UserList.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 1)";
176if (!RunQuery($sSQL, FALSE))
177    break;
178
179$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (8, 'addnewuser', 'admin', 0, '".gettext('Add New User')."', 'UserEditor.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 2)";
180if (!RunQuery($sSQL, FALSE))
181    break;
182
183$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (9, 'custompersonfld', 'admin', 0, '".gettext('Edit Custom Person Fields')."', 'PersonCustomFieldsEditor.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 3)";
184if (!RunQuery($sSQL, FALSE))
185    break;
186
187$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (10, 'donationfund', 'admin', 0, '".gettext('Edit Donation Funds')."', 'DonationFundEditor.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 4)";
188if (!RunQuery($sSQL, FALSE))
189    break;
190
191$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (11, 'dbbackup', 'admin', 0, '".gettext('Backup Database')."', 'BackupDatabase.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 5)";
192if (!RunQuery($sSQL, FALSE))
193    break;
194
195$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (12, 'cvsimport', 'admin', 0, '".gettext('CSV Import')."', 'CSVImport.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 6)";
196if (!RunQuery($sSQL, FALSE))
197    break;
198
199$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (13, 'accessreport', 'admin', 0, '".gettext('Access report')."', 'AccessReport.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 7)";
200if (!RunQuery($sSQL, FALSE))
201    break;
202
203$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (14, 'generalsetting', 'admin', 0, '".gettext('Edit General Settings')."', 'SettingsGeneral.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 8)";
204if (!RunQuery($sSQL, FALSE))
205    break;
206
207$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (15, 'reportsetting', 'admin', 0, '".gettext('Edit Report Settings')."', 'SettingsReport.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 9)";
208if (!RunQuery($sSQL, FALSE))
209    break;
210
211$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (16, 'userdefault', 'admin', 0, '".gettext('Edit User Default Settings')."', 'SettingsUser.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 10)";
212if (!RunQuery($sSQL, FALSE))
213    break;
214
215$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (17, 'envelopmgr', 'admin', 0, '".gettext('Envelope Manager')."', 'ManageEnvelopes.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 11)";
216if (!RunQuery($sSQL, FALSE))
217    break;
218
219if (! $bRegistered) {
220	$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (18, 'register', 'admin', 0, '".gettext('Please select this option to register ChurchInfo after configuring.')."', 'Register.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 12)";
221} else {
222	$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (18, 'register', 'admin', 0, '".gettext('Update registration')."', 'Register.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 12)";
223}
224if (!RunQuery($sSQL, FALSE))
225    break;
226
227$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (19, 'people', 'root', 1, '".gettext('People/Families')."', '', 'People/Families', 'bAll', NULL, 0, 0, NULL, 1, 3)";
228if (!RunQuery($sSQL, FALSE))
229    break;
230
231$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (20, 'newperson', 'people', 0, '".gettext('Add New Person')."', 'PersonEditor.php', '', 'bAddRecords', NULL, 0, 0, NULL, 1, 1)";
232if (!RunQuery($sSQL, FALSE))
233    break;
234
235$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (21, 'viewperson', 'people', 0, '".gettext('View All Persons')."', 'SelectList.php?mode=person', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
236if (!RunQuery($sSQL, FALSE))
237    break;
238
239$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (22, 'classes', 'people', 0, '".gettext('Classification Manager')."', 'OptionManager.php?mode=classes', '', 'bMenuOptions', NULL, 0, 0, NULL, 1, 3)";
240if (!RunQuery($sSQL, FALSE))
241    break;
242
243$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (23, 'separator1', 'people', 0, '---------------------------', '', '', 'bAll', NULL, 0, 0, NULL, 1, 4)";
244if (!RunQuery($sSQL, FALSE))
245    break;
246
247$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (24, 'volunteeropportunity', 'people', 0, '".gettext('Edit volunteer opportunities')."', 'VolunteerOpportunityEditor.php', '', 'bAll', NULL, 0, 0, NULL, 1, 5)";
248if (!RunQuery($sSQL, FALSE))
249    break;
250
251$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (25, 'separator2', 'people', 0, '---------------------------', '', '', 'bAll', NULL, 0, 0, NULL, 1, 6)";
252if (!RunQuery($sSQL, FALSE))
253    break;
254
255$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (26, 'newfamily', 'people', 0, '".gettext('Add New Family')."', 'FamilyEditor.php', '', 'bAddRecords', NULL, 0, 0, NULL, 1, 7)";
256if (!RunQuery($sSQL, FALSE))
257    break;
258
259$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (27, 'viewfamily', 'people', 0, '".gettext('View All Families')."', 'SelectList.php?mode=family', '', 'bAll', NULL, 0, 0, NULL, 1, 8)";
260if (!RunQuery($sSQL, FALSE))
261    break;
262
263$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (28, 'familygeotools', 'people', 0, '".gettext('Family Geographic Utilties')."', 'GeoPage.php', '', 'bAll', NULL, 0, 0, NULL, 1, 9)";
264if (!RunQuery($sSQL, FALSE))
265    break;
266
267$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (29, 'familymap', 'people', 0, '".gettext('Family Map')."', 'MapUsingGoogle.php?GroupID=-1', '', 'bAll', NULL, 0, 0, NULL, 1, 10)";
268if (!RunQuery($sSQL, FALSE))
269    break;
270
271$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (30, 'rolemanager', 'people', 0, '".gettext('Family Roles Manager')."', 'OptionManager.php?mode=famroles', '', 'bMenuOptions', NULL, 0, 0, NULL, 1, 11)";
272if (!RunQuery($sSQL, FALSE))
273    break;
274
275$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (31, 'events', 'root', 1, '".gettext('Events')."', '', 'Events', 'bAll', NULL, 0, 0, NULL, 1, 4)";
276if (!RunQuery($sSQL, FALSE))
277    break;
278
279$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (32, 'listevent', 'events', 0, '".gettext('List Church Events')."', 'ListEvents.php', 'List Church Events', 'bAll', NULL, 0, 0, NULL, 1, 1)";
280if (!RunQuery($sSQL, FALSE))
281    break;
282
283$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (33, 'addevent', 'events', 0, '".gettext('Add Church Event')."', 'EventNames.php', 'Add Church Event', 'bAll', NULL, 0, 0, NULL, 1, 2)";
284if (!RunQuery($sSQL, FALSE))
285    break;
286
287$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (34, 'eventype', 'events', 0, '".gettext('List Event Types')."', 'EventNames.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 3)";
288if (!RunQuery($sSQL, FALSE))
289    break;
290
291$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (83, 'eventcheckin', 'events', 0, '".gettext('Check-in and Check-out')."', 'Checkin.php', '', 'bAll', NULL, 0, 0, NULL, 1, 4)";
292if (!RunQuery($sSQL, FALSE))
293    break;
294
295$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (35, 'deposit', 'root', 1, '".gettext('Deposit')."', '', '', 'bFinance', NULL, 0, 0, NULL, 1, 5)";
296if (!RunQuery($sSQL, FALSE))
297    break;
298
299$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (36, 'newdeposit', 'deposit', 0, '".gettext('Create New Deposit')."', 'DepositSlipEditor.php?DepositType=Bank', '', 'bFinance', NULL, 0, 0, NULL, 1, 1)";
300if (!RunQuery($sSQL, FALSE))
301    break;
302
303$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (37, 'viewdeposit', 'deposit', 0, '".gettext('View All Deposits')."', 'FindDepositSlip.php', '', 'bFinance', NULL, 0, 0, NULL, 1, 2)";
304if (!RunQuery($sSQL, FALSE))
305    break;
306
307$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (38, 'depositreport', 'deposit', 0, '".gettext('Deposit Reports')."', 'FinancialReports.php', '', 'bFinance', NULL, 0, 0, NULL, 1, 3)";
308if (!RunQuery($sSQL, FALSE))
309    break;
310
311$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (39, 'separator3', 'deposit', 0, '---------------------------', '', '', 'bFinance', NULL, 0, 0, NULL, 1, 4)";
312if (!RunQuery($sSQL, FALSE))
313    break;
314
315$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (40, 'depositslip', 'deposit', 0, '".gettext('Edit Deposit Slip')."', 'DepositSlipEditor.php', '', 'bFinance', 'iCurrentDeposit', 1, 1, 'DepositSlipID', 1, 5)";
316if (!RunQuery($sSQL, FALSE))
317    break;
318
319$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (41, 'cart', 'root', 1, '".gettext('Cart')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 6)";
320if (!RunQuery($sSQL, FALSE))
321    break;
322
323$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (42, 'viewcart', 'cart', 0, '".gettext('List Cart Items')."', 'CartView.php', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
324if (!RunQuery($sSQL, FALSE))
325    break;
326
327$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (43, 'emptycart', 'cart', 0, '".gettext('Empty Cart')."', 'CartView.php?Action=EmptyCart', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
328if (!RunQuery($sSQL, FALSE))
329    break;
330
331$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (44, 'carttogroup', 'cart', 0, '".gettext('Empty Cart to Group')."', 'CartToGroup.php', '', 'bManageGroups', NULL, 0, 0, NULL, 1, 3)";
332if (!RunQuery($sSQL, FALSE))
333    break;
334
335$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (45, 'carttofamily', 'cart', 0, '".gettext('Empty Cart to Family')."', 'CartToFamily.php', '', 'bAddRecords', NULL, 0, 0, NULL, 1, 4)";
336if (!RunQuery($sSQL, FALSE))
337    break;
338
339$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (46, 'carttoevent', 'cart', 0, '".gettext('Empty Cart to Event')."', 'CartToEvent.php', 'Empty Cart contents to Event', 'bAll', NULL, 0, 0, NULL, 1, 5)";
340if (!RunQuery($sSQL, FALSE))
341    break;
342
343$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (47, 'report', 'root', 1, '".gettext('Data/Reports')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 7)";
344if (!RunQuery($sSQL, FALSE))
345    break;
346
347$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (48, 'cvsexport', 'report', 0, '".gettext('CSV Export Records')."', 'CSVExport.php', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
348if (!RunQuery($sSQL, FALSE))
349    break;
350
351$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (49, 'querymenu', 'report', 0, '".gettext('Query Menu')."', 'QueryList.php', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
352if (!RunQuery($sSQL, FALSE))
353    break;
354
355$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (50, 'reportmenu', 'report', 0, '".gettext('Reports Menu')."', 'ReportList.php', '', 'bAll', NULL, 0, 0, NULL, 1, 3)";
356if (!RunQuery($sSQL, FALSE))
357    break;
358
359$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (51, 'groups', 'root', 1, '".gettext('Groups')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 8)";
360if (!RunQuery($sSQL, FALSE))
361    break;
362
363$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (52, 'listgroups', 'groups', 0, '".gettext('List Groups')."', 'GroupList.php', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
364if (!RunQuery($sSQL, FALSE))
365    break;
366
367$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (53, 'newgroup', 'groups', 0, '".gettext('Add a New Group')."', 'GroupEditor.php', '', 'bManageGroups', NULL, 0, 0, NULL, 1, 2)";
368if (!RunQuery($sSQL, FALSE))
369    break;
370
371$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (54, 'editgroup', 'groups', 0, '".gettext('Edit Group Types')."', 'OptionManager.php?mode=grptypes', '', 'bMenuOptions', NULL, 0, 0, NULL, 1, 3)";
372if (!RunQuery($sSQL, FALSE))
373    break;
374
375$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (55, 'assigngroup', 'group', 0, '".gettext('Group Assignment Helper')."', 'SelectList.php?mode=groupassign', '', 'bAll', NULL, 0, 0, NULL, 1, 4)";
376if (!RunQuery($sSQL, FALSE))
377    break;
378
379$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (56, 'properties', 'root', 1, '".gettext('Properties')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 9)";
380if (!RunQuery($sSQL, FALSE))
381    break;
382
383$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (57, 'peopleproperty', 'properties', 0, '".gettext('People Properties')."', 'PropertyList.php?Type=p', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
384if (!RunQuery($sSQL, FALSE))
385    break;
386
387$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (58, 'familyproperty', 'properties', 0, '".gettext('Family Properties')."', 'PropertyList.php?Type=f', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
388if (!RunQuery($sSQL, FALSE))
389    break;
390
391$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (59, 'groupproperty', 'properties', 0, '".gettext('Group Properties')."', 'PropertyList.php?Type=g', '', 'bAll', NULL, 0, 0, NULL, 1, 3)";
392if (!RunQuery($sSQL, FALSE))
393    break;
394
395$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (60, 'propertytype', 'properties', 0, '".gettext('Property Types')."', 'PropertyTypeList.php', '', 'bAll', NULL, 0, 0, NULL, 1, 4)";
396if (!RunQuery($sSQL, FALSE))
397    break;
398
399$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (64, 'help', 'root', 1, '".gettext('Help')."', '', '', 'bAll', NULL, 0, 0, NULL, 1, 127)";
400if (!RunQuery($sSQL, FALSE))
401    break;
402
403$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (65, 'about', 'help', 0, '".gettext('About ChurchInfo')."', 'Help.php?page=About', '', 'bAll', NULL, 0, 0, NULL, 1, 1)";
404if (!RunQuery($sSQL, FALSE))
405    break;
406
407$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (66, 'wiki', 'help', 0, '".gettext('Wiki Documentation')."', 'JumpToWiki.php', '', 'bAll', NULL, 0, 0, NULL, 1, 2)";
408if (!RunQuery($sSQL, FALSE))
409    break;
410
411$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (67, 'helppeople', 'help', 0, '".gettext('People')."', 'Help.php?page=People', '', 'bAll', NULL, 0, 0, NULL, 1, 3)";
412if (!RunQuery($sSQL, FALSE))
413    break;
414
415$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (68, 'helpfamily', 'help', 0, '".gettext('Families')."', 'Help.php?page=Family', '', 'bAll', NULL, 0, 0, NULL, 1, 4)";
416if (!RunQuery($sSQL, FALSE))
417    break;
418
419$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (69, 'helpgeofeature', 'help', 0, '".gettext('Geographic features')."', 'Help.php?page=Geographic', '', 'bAll', NULL, 0, 0, NULL, 1, 5)";
420if (!RunQuery($sSQL, FALSE))
421    break;
422
423$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (70, 'helpgroups', 'help', 0, '".gettext('Groups')."', 'Help.php?page=Groups', '', 'bAll', NULL, 0, 0, NULL, 1, 6)";
424if (!RunQuery($sSQL, FALSE))
425    break;
426
427$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (71, 'helpfinance', 'help', 0, '".gettext('Finances')."', 'Help.php?page=Finances', '', 'bAll', NULL, 0, 0, NULL, 1, 7)";
428if (!RunQuery($sSQL, FALSE))
429    break;
430
431$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (72, 'helpreports', 'help', 0, '".gettext('Reports')."', 'Help.php?page=Reports', '', 'bAll', NULL, 0, 0, NULL, 1, 8)";
432if (!RunQuery($sSQL, FALSE))
433    break;
434
435$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (73, 'helpadmin', 'help', 0, '".gettext('Administration')."', 'Help.php?page=Admin', '', 'bAll', NULL, 0, 0, NULL, 1, 9)";
436if (!RunQuery($sSQL, FALSE))
437    break;
438
439$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (74, 'helpcart', 'help', 0, '".gettext('Cart')."', 'Help.php?page=Cart', '', 'bAll', NULL, 0, 0, NULL, 1, 10)";
440if (!RunQuery($sSQL, FALSE))
441    break;
442
443$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (75, 'helpproperty', 'help', 0, '".gettext('Properties')."', 'Help.php?page=Properties', '', 'bAll', NULL, 0, 0, NULL, 1, 11)";
444if (!RunQuery($sSQL, FALSE))
445    break;
446
447$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (76, 'helpnotes', 'help', 0, '".gettext('Notes')."', 'Help.php?page=Notes', '', 'bAll', NULL, 0, 0, NULL, 1, 12)";
448if (!RunQuery($sSQL, FALSE))
449    break;
450
451$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (77, 'helpcustomfields', 'help', 0, '".gettext('Custom Fields')."', 'Help.php?page=Custom', '', 'bAll', NULL, 0, 0, NULL, 1, 13)";
452if (!RunQuery($sSQL, FALSE))
453    break;
454
455$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (78, 'helpclassification', 'help', 0, '".gettext('Classifications')."', 'Help.php?page=Class', '', 'bAll', NULL, 0, 0, NULL, 1, 14)";
456if (!RunQuery($sSQL, FALSE))
457    break;
458
459$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (79, 'helpcanvass', 'help', 0, '".gettext('Canvass Support')."', 'Help.php?page=Canvass', '', 'bAll', NULL, 0, 0, NULL, 1, 15)";
460if (!RunQuery($sSQL, FALSE))
461    break;
462
463$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (80, 'helpevents', 'help', 0, '".gettext('Events')."', 'Help.php?page=Events', '', 'bAll', NULL, 0, 0, NULL, 1, 16)";
464if (!RunQuery($sSQL, FALSE))
465    break;
466
467$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (81, 'menusetup', 'admin', '0', '".gettext('Menu Options')."', 'MenuSetup.php', '', 'bAdmin', NULL , 0, 0, NULL , 1, 13)";
468if (!RunQuery($sSQL, FALSE))
469    break;
470
471$sSQL = "INSERT INTO `menuconfig_mcf` VALUES (82, 'customfamilyfld', 'admin', 0, '".gettext('Edit Custom Family Fields')."', 'FamilyCustomFieldsEditor.php', '', 'bAdmin', NULL, 0, 0, NULL, 1, 3)";
472if (!RunQuery($sSQL, FALSE))
473    break;
474
475$sSQL = "ALTER TABLE `config_cfg` ADD `cfg_category` VARCHAR( 20 ) NULL AFTER `cfg_section` ";
476if (!RunQuery($sSQL, FALSE))
477    break;
478
479$sSQL = "INSERT INTO `config_cfg` VALUES (61, 'iEventPeriodStartHr', '7', 'number', '7', 'Church Event Valid Period Start Hour (0-23)', 'General', '')";
480if (!RunQuery($sSQL, FALSE))
481    break;
482
483$sSQL = "INSERT INTO `config_cfg` VALUES (62, 'iEventPeriodEndHr', '18', 'number', '18', 'Church Event Valid Period End Hour (0-23, must be greater than iEventStartHr)', 'General', '')";
484if (!RunQuery($sSQL, FALSE))
485    break;
486
487$sSQL = "INSERT INTO `config_cfg` VALUES (63, 'iEventPeriodIntervalMin', '15', 'number', '15', 'Event Period interval (in minutes)', 'General', '')";
488if (!RunQuery($sSQL, FALSE))
489    break;
490
491$sSQL = "INSERT INTO `config_cfg` VALUES (64, 'sDistanceUnit', 'miles', 'text', 'miles', 'Unit used to measure distance, miles or km.', 'General', '')";
492if (!RunQuery($sSQL, FALSE))
493    break;
494
495$sSQL = "DROP TABLE IF EXISTS `family_custom`";
496if (!RunQuery($sSQL, FALSE))
497    break;
498
499$sSQL = "CREATE TABLE `family_custom` (
500  `fam_ID` mediumint(9) NOT NULL default '0',
501  PRIMARY KEY  (`fam_ID`)
502) ENGINE=MyISAM DEFAULT CHARSET=utf8";
503if (!RunQuery($sSQL, FALSE))
504    break;
505
506$sSQL = "DROP TABLE IF EXISTS `family_custom_master`";
507if (!RunQuery($sSQL, FALSE))
508    break;
509
510$sSQL = "CREATE TABLE `family_custom_master` (
511  `fam_custom_Order` smallint(6) NOT NULL default '0',
512  `fam_custom_Field` varchar(5) NOT NULL default '',
513  `fam_custom_Name` varchar(40) NOT NULL default '',
514  `fam_custom_Special` mediumint(8) unsigned default NULL,
515  `fam_custom_Side` enum('left','right') NOT NULL default 'left',
516  `fam_custom_FieldSec` tinyint(4) NOT NULL default '1',
517  `type_ID` tinyint(4) NOT NULL default '0'
518) ENGINE=MyISAM DEFAULT CHARSET=utf8";
519if (!RunQuery($sSQL, FALSE))
520    break;
521
522$sSQL = "INSERT INTO `list_lst` VALUES (5, 1, 1, 'bAll')";
523if (!RunQuery($sSQL, FALSE))
524    break;
525
526$sSQL = "INSERT INTO `list_lst` VALUES (5, 2, 2, 'bAdmin')";
527if (!RunQuery($sSQL, FALSE))
528    break;
529
530$sSQL = "INSERT INTO `list_lst` VALUES (5, 3, 3, 'bAddRecords')";
531if (!RunQuery($sSQL, FALSE))
532    break;
533
534$sSQL = "INSERT INTO `list_lst` VALUES (5, 4, 4, 'bEditRecords')";
535if (!RunQuery($sSQL, FALSE))
536    break;
537
538$sSQL = "INSERT INTO `list_lst` VALUES (5, 5, 5, 'bDeleteRecords')";
539if (!RunQuery($sSQL, FALSE))
540    break;
541
542$sSQL = "INSERT INTO `list_lst` VALUES (5, 6, 6, 'bMenuOptions')";
543if (!RunQuery($sSQL, FALSE))
544    break;
545
546$sSQL = "INSERT INTO `list_lst` VALUES (5, 7, 7, 'bManageGroups')";
547if (!RunQuery($sSQL, FALSE))
548    break;
549
550$sSQL = "INSERT INTO `list_lst` VALUES (5, 8, 8, 'bFinance')";
551if (!RunQuery($sSQL, FALSE))
552    break;
553
554$sSQL = "INSERT INTO `list_lst` VALUES (5, 9, 9, 'bNotes')";
555if (!RunQuery($sSQL, FALSE))
556    break;
557
558$sSQL = "INSERT INTO `list_lst` VALUES (5, 10, 10, 'bCommunication')";
559if (!RunQuery($sSQL, FALSE))
560    break;
561
562$sSQL = "INSERT INTO `list_lst` VALUES (5, 11, 11, 'bCanvasser')";
563if (!RunQuery($sSQL, FALSE))
564    break;
565
566$sSQL = "ALTER TABLE `userconfig_ucfg` ADD `ucfg_cat` VARCHAR( 20 ) NOT NULL AFTER `ucfg_permission` ";
567if (!RunQuery($sSQL, FALSE))
568   break;
569
570$sSQL = "UPDATE `userconfig_ucfg` SET `ucfg_cat` = 'SECURITY' WHERE `userconfig_ucfg`.`ucfg_per_id` =0 AND `userconfig_ucfg`.`ucfg_id` =5 ";
571if (!RunQuery($sSQL, FALSE))
572    break;
573
574$sSQL = "UPDATE `userconfig_ucfg` SET `ucfg_cat` = 'SECURITY' WHERE `userconfig_ucfg`.`ucfg_per_id` =0 AND `userconfig_ucfg`.`ucfg_id` =6 ";
575if (!RunQuery($sSQL, FALSE))
576    break;
577
578$sSQL = "INSERT INTO `userconfig_ucfg` VALUES ('', '10', 'bAddEvent', '0', 'boolean', 'Allow user to add new event', 'FALSE', 'SECURITY')";
579if (!RunQuery($sSQL, FALSE))
580    break;
581
582$sSQL = "INSERT INTO `userconfig_ucfg` VALUES ('', '11', 'bSeePrivacyData', '0', 'boolean', 'Allow user to see member privacy data, e.g. Birth Year, Age.', 'FALSE', 'SECURITY')";
583if (!RunQuery($sSQL, FALSE))
584    break;
585
586$sSQL = "ALTER TABLE `person_custom_master` ADD `custom_FieldSec` TINYINT( 4 ) NOT NULL AFTER `custom_Side` ;";
587if (!RunQuery($sSQL, FALSE))
588    break;
589
590
591
592if (mysql_num_rows(RunQuery("SELECT * FROM person_custom_master"))> 0) {
593
594	$sSQL = "UPDATE `person_custom_master` SET `custom_FieldSec` = '1'";	
595    if (!RunQuery($sSQL, FALSE))
596        break;
597}
598
599$sSQL = "ALTER TABLE `event_attend` ADD `checkin_date` datetime";
600if (!RunQuery($sSQL, FALSE))
601    break;
602
603$sSQL = "ALTER TABLE `event_attend` ADD `checkin_id` int(11)";
604if (!RunQuery($sSQL, FALSE))
605    break;
606
607$sSQL = "ALTER TABLE `event_attend` ADD `checkout_date` datetime";
608if (!RunQuery($sSQL, FALSE))
609    break;
610
611$sSQL = "ALTER TABLE `event_attend` ADD `checkout_id` int(11)";
612if (!RunQuery($sSQL, FALSE))
613    break;
614
615$queryText = <<<EOD
616SELECT per_ID as AddToCart,CONCAT('<a
617href=PersonView.php?PersonID=',per_ID,'>',per_FirstName,'
618',per_LastName,'</a>') AS Name,
619CONCAT(per_BirthMonth,'/',per_BirthDay,'/',per_BirthYear) AS 'Birth Date',
620YEAR(CURRENT_DATE) - per_BirthYear - 1 AS 'Age'
621FROM person_per
622WHERE
623DATE_ADD(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay),INTERVAL
624~min~ YEAR) <= CURDATE()
625AND
626DATE_ADD(CONCAT(per_BirthYear,'-',per_BirthMonth,'-',per_BirthDay),INTERVAL
627(~max~ + 1) YEAR) >= CURDATE()
628EOD;
629
630$sSQL = "UPDATE `query_qry` SET `qry_SQL` = '" . 
631         mysql_real_escape_string($queryText) . 
632         "' WHERE `query_qry`.`qry_ID` = 4 "; 
633if (!RunQuery($sSQL, FALSE))
634	break;
635
636$sSQL = "ALTER IGNORE TABLE `event_attend` ADD UNIQUE (`event_id`, `person_id`) ";
637if (!RunQuery($sSQL, FALSE))
638    break;
639
640$sSQL = "INSERT INTO `queryparameteroptions_qpo` VALUES ('', '15', 'Email', 'per_Email') ";
641if (!RunQuery($sSQL, FALSE))
642    break;
643
644$sSQL = "INSERT INTO `queryparameteroptions_qpo` VALUES ('', '15', 'WorkEmail', 'per_WorkEmail') ";
645if (!RunQuery($sSQL, FALSE))
646    break;
647
648$queryText = <<<EOD
649Enter any part of the following: Name, City, State, Zip, Home Phone, Email, or Work Email.
650EOD;
651
652$sSQL = "UPDATE `queryparameters_qrp` SET `qrp_Description` ='" .
653		mysql_real_escape_string($queryText) .
654		"' WHERE `queryparameters_qrp`.`qrp_ID` = 14 ";
655if (!RunQuery($sSQL, FALSE))
656    break;
657
658$queryText = <<<EOD
659SELECT per_ID as AddToCart, CONCAT('<a href=PersonView.php?PersonID=',per_ID,'>',per_FirstName,' ',per_MiddleName,' ',per_LastName,'</a>') AS Name, 
660per_City as City, per_State as State,
661per_Zip as ZIP, per_HomePhone as HomePhone, per_Email as Email, per_WorkEmail as WorkEmail
662FROM person_per 
663WHERE ~searchwhat~ LIKE '%~searchstring~%'
664EOD;
665
666$sSQL = "UPDATE `query_qry` SET `qry_SQL` = '" . 
667         mysql_real_escape_string($queryText) . 
668         "' WHERE `query_qry`.`qry_ID` = 15 "; 
669if (!RunQuery($sSQL, FALSE))
670	break;
671
672$queryText = <<<EOD
673Search by any part of Name, City, State, Zip, Home Phone, Email, or Work Email.
674EOD;
675
676$sSQL = "UPDATE `query_qry` SET `qry_Description` = '" . 
677         mysql_real_escape_string($queryText) . 
678         "' WHERE `query_qry`.`qry_ID` = 15 "; 
679if (!RunQuery($sSQL, FALSE))
680	break;
681
682// If we got this far it means all queries ran without error.  It is okay to update
683// the version information.
684
685
686$sSQL = "INSERT INTO `version_ver` (`ver_version`, `ver_date`) VALUES ('".$sVersion."',NOW())";
687RunQuery($sSQL, FALSE); // False means do not stop on error
688break;
689
690}  // End of for  
691
692
693$sError = mysql_error();
694$sSQL_Last = $sSQL;
695
696// Let's check if MySQL database is in sync with PHP code
697    $sSQL = 'SELECT * FROM version_ver ORDER BY ver_ID DESC';
698    $aRow = mysql_fetch_array(RunQuery($sSQL));
699    extract($aRow);
700
701    if ($ver_version == $sVersion) {
702        // We're good.  Clean up by dropping the
703        // temporary tables
704        $sSQL  = "DROP TABLE IF EXISTS `tempconfig_tcfg`, `templist_tlst`, ";
705        $sSQL .= "`tempuserconfig_tucfg`, `temp_person_custom_master`";
706        RunQuery($sSQL, TRUE);
707
708    } else {
709        // An error occured.  Clean up by restoring
710        // tables to their original condition by using
711        // the temporary tables.
712
713        $sSQL  = "DROP TABLE IF EXISTS `config_cfg`, `list_lst`, ";
714        $sSQL .= "`userconfig_ucfg`, `person_custom_master`";
715        RunQuery($sSQL, TRUE);
716
717        $sSQL  = "RENAME TABLE `tempconfig_tcfg`           TO `config_cfg`, ";
718        $sSQL .= "             `templist_tlst`             TO `list_lst`, ";
719        $sSQL .= "             `tempuserconfig_tucfg`      TO `userconfig_ucfg`, ";
720        $sSQL .= "             `temp_person_custom_master` TO `person_custom_master`";
721        RunQuery($sSQL, TRUE);
722
723    }
724
725$sSQL = $sSQL_Last;
726
727?>