Menu

[r8]: / includes / upgrade_funcs.inc.php  Maximize  Restore  History

Download this file

628 lines (531 with data), 21.2 kB

  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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
<?php
/*
** Application name: phpCollab
** Path by root: ../inlcudes/upgrade_funcs.inc.php
** Since: 2.5 rc3
** Authors: Norman77 / Mindblender
**
** =============================================================================
**
** phpCollab - Project Managment
**
** -----------------------------------------------------------------------------
** Please refer to license, copyright, and credits in README.TXT
**
** -----------------------------------------------------------------------------
** FILE: upgrade.php
**
** DESC: Functions used in the upgrade file and procedures
**
** =============================================================================
** CVS Tags and Keywords
** Last Editor : $Author: norman77 $
** Last Edit : $Date: 2009/01/21 21:29:18 $
** Version : $Revision: 1.2 $
** =============================================================================
*/
/**
* getParameter
* Get's a parameter from GET or POST (auto detected, POST first) that is safe for use
* in queries or use unchecked.. will return type that's in the paramter..
* Returns null if parameter was not found.
* @return mixed
* @param String $paramName
*/
function getParameter($paramName) {
//Let's sanatize the param just in case, let's be extermly paranoid here
$paramName = sanatize($paramName, false);
$ret = null;
if (array_key_exists($paramName, $_POST)) {
$ret = sanatize($_POST[$paramName]);
} elseif (array_key_exists($paramName, $_GET)) {
$ret = sanatize($_GET[$paramName]);
}
return $ret;
}
/**
* sanatize
* Returns a clean version of data.
* If allowSpecChars is true, will allow special characters (shift of numbers) otherwise it's only
* letters and numbers (including space and period)
* @return String
* @param object $data
* @param object $allowSpecChars[optional]
*/
function sanatize($data, $allowSpecChars = false) {
if (!$allowSpecChars) {
$data = preg_replace('/^\W+|\W+$/', '', $data);
}
return $data;
}
/**
* checkDatabase()
* Check to see if the database should be upgraded from 2.4 to 2.5
* @return bool
*/
function checkDatabase($errorMsg = '') {
$settingsFile = dirname(realpath(__FILE__)) . "/settings.php";
include_once($settingsFile);
if (file_exists($settingsFile)) {
//first see if these database tables are missing from the table
if (!array_key_exists("invoices", $tableCollab) ||
!array_key_exists("invoices_items", $tableCollab) ||
!array_key_exists("services", $tableCollab) ||
!array_key_exists("newsdeskcomments", $tableCollab) ||
!array_key_exists("newsdeskposts", $tableCollab)) {
//-------------
return true; // Database should be upgraded
} else {
$errorMsg = "It appears that the tables have already been added. Manual update is only possible at this time.";
}
}
return false;
}
/**
* convertDB()
* Converts the DB, check's if it should be done first (ie: adding fields/tables)
* @return bool
*/
function convertDB() {
$settingsFile = dirname(realpath(__FILE__)) . "/settings.php";
include($settingsFile); // Reimport :)
echo ":: Connecting to DB Server....";
$errorMsg = null;
$conn = connectDB($databaseType, MYSERVER, MYLOGIN, MYPASSWORD, MYDATABASE);
if (!empty($conn)) {
echo "<font style='font-weight: bold;color: green'>done</font> :: <br />";
} else {
echo "<font style='font-weight: bold;color: red'>ERROR</font> :: <br />";
return false;
}
echo ":: Beggining Database Conversion... :: <br /><ul>";
//Add Tables
echo "<li>Adding new tables...";
//Add the DB Vars and let's try to do this stuffs..
if (addTables($databaseType, $conn, $tablePrefix, &$errorMsg))
echo "<font style='color: green;font-weight: bold'>completed</font>";
else {
echo "<font style='color: red;font-weight: bold'>error</font>";
if (!empty($errorMsg)) echo "<br /><b>Error Messages: </b>$errorMsg";
return false;
}
//Now let's reset the Error message, just in case
$errorMsg = null;
//Modify existing tables
echo "<li>Updating existing tables...";
if (modTables($databaseType, $conn, $tablePrefix, &$errorMsg))
echo "<font style='color: green;font-weight: bold'>completed</font>";
else {
echo "<font style='color: red;font-weight: bold'>error</font>";
if (!empty($errorMsg)) echo "<br /><b>Error Messages: </b>$errorMsg";
return false;
}
//Run tests
$errorMsg = null;
// echo "<li>Verifying everything went okay...";
echo "</ul>:: Ending Conversion ::";
return true;
}
/**
* addTables
* Adds new tables to the database, dependant on the type. Connectino is already established in conn
* @return bool
* @param String $type
* @param object $conn
* @param object $prefix[optional]
* @param object $errorMsg[optional]
*/
function addTables($type, $conn, $prefix = "", $errorMsg = null) {
if (empty($type) || empty($conn)) { return false;}
$tableFields = array(
"invoices" => array(
"id" => "mediumint_auto",
"project" => "mediumint",
"header_note" => "text",
"footer_note" => "text",
"date_sent" => "varchar10",
"due_date" => "varchar10",
"total_ex_tax" => "float",
"tax_rate" => "float",
"tax_amount" => "float",
"total_inc_tax" => "float",
"status" => "char1",
"active" => "char1",
"created" => "varchar16",
"modified" => "varchar16",
"published" => "char1"
),
"invoices_items" => array(
"id" => "mediumint_auto",
"invoice" => "mediumint",
"position" => "mediumint",
"mod_type" => "char1",
"mod_value" => "mediumint",
"title" => "varchar155",
"description" => "text",
"worked_hours" => "float",
"amount_ex_tax" => "float",
"rate_type" => "varchar10",
"rate_value" => "float",
"status" => "char1",
"active" => "char1",
"completed" => "char1",
"created" => "varchar16",
"modified" => "varchar16"
),
"services" => array(
"id" => "mediumint_auto",
"name" => "varchar155",
"name_print" => "varchar155",
"hourly_rate" => "float"
),
"newsdeskcomments" => array(
"id" => "mediumint_auto",
"post_id" => "mediumint",
"name" => "mediumint",
"comment" => "text"
),
"newsdeskposts" => array(
"id" => "mediumint_auto",
"pdate" => "varchar16",
"title" => "varchar155",
"author" => "mediumint",
"related" => "varchar155",
"content" => "text",
"links" => "text",
"rss" => "char1"
)
);
//Get DB Vaars
$dbvar = dirname(realpath(__FILE__)) . "/db_var.inc.php";
require_once($dbvar);
// okay let's start it up
foreach (array_keys($tableFields) as $table) {
//Let's do the PGSQL Stuff
if ($type == "postgresql") {
//Create the sequence..
$sql = "CREATE SEQUENCE {$prefix}{$table}_seq start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1";
$db_mediumint_auto[$type] = "int4 DEFAULT nextval('" . $prefix . "{$table}_seq'::text) NOT NULL";
pg_query($conn, $sql);
if (pg_last_error($conn) != 0) {
$errorMsg = "PGSQL Panic: " . pg_last_error($conn);
return;
}
}
//Continuing on..
// Create table and such
$t_sql = "CREATE TABLE {$prefix}{$table} (";
//Do all the fields
$tf_sql = '';
foreach ($tableFields[$table] as $field => $ftype) {
$mytype = '';
eval("\$mytype = \$db_{$ftype}['$type'];");
$tf_sql .= "$field $mytype, ";
}
$t_sql .= $tf_sql . "PRIMARY KEY(id))";
if ($type == "mysql") {
mysql_query($t_sql, $conn);
if (mysql_errno($conn) != 0) {
$errorMsg = "MYSQL Panic! : " . mysql_error($conn) . "<br />Could not continue, upgrade was not completed.";
return;
}
} elseif ($type == "mssql") {
mssql_query($t_sql, $conn);
if (mssql_get_last_message() != 0) {
$errorMsg = "MSSQL Panic! : " . mssql_get_last_message() . "<br />Could not continue, upgrade was not completed.";
return;
}
} elseif ($type == "postgresql") {
pg_query($conn, $t_sql);
if (pg_last_error($conn) != 0) {
$errorMsg = "PG-SQL Panic! : " . pg_last_error($conn) . "<br />Could not continue, upgrade was not completed.";
return;
}
}
}
return true;
}
/**
* modTables
* Modifies tables, depending on what's in the array in the function
* @return bool
* @param String $type
* @param object $conn
* @param object $prefix[optional]
* @param object $errorMsg[optional]
*/
function modTables($type, $conn, $prefix = "", $errorMsg = null) {
//Get DB Vaars
$dbvar = dirname(realpath(__FILE__)) . "/db_var.inc.php";
include($dbvar);
if (empty($type) || empty($conn)) { return false;}
$tableFields = array(
"calendar" => array(
"broadcast" => "char1",
"location" => "varchar155"
),
"notifications" => array(
"uploadFile" => "char1"
),
"organizations" => array(
"hourly_rate" => "float"
),
"projects" => array(
"invoicing" => "char1",
"hourly_rate" => "float"
),
"sorting" => array(
"invoices" => "varchar155",
"newsdesk" => "varchar155"
),
"tasks" => array(
"invoicing" => "char1",
"worked_hours" => "float"
)
);
//Get DB Vaars
$dbvar = dirname(realpath(__FILE__)) . "/db_var.inc.php";
require_once($dbvar);
// okay let's start it up
foreach (array_keys($tableFields) as $table) {
//Continuing on..
// Create table and such
$t_sql = "ALTER TABLE {$prefix}{$table} ";
//Do all the fields
$tf_sql = '';
foreach ($tableFields[$table] as $field => $ftype) {
$mytype = '';
eval("\$mytype = \$db_{$ftype}['$type'];");
if ($tf_sql != '' ) $tf_sql .= ", ADD $field $mytype";
else $tf_sql = "ADD $field $mytype";
}
$t_sql .= $tf_sql;
if ($type == "mysql") {
mysql_query($t_sql, $conn);
if (mysql_errno($conn) != 0) {
$errorMsg = "MYSQL Panic! : " . mysql_error($conn) . "<br />Could not continue, upgrade was not completed.";
return;
}
} elseif ($type == "mssql") {
mssql_query($t_sql, $conn);
if (mssql_get_last_message() != 0) {
$errorMsg = "MSSQL Panic! : " . mssql_get_last_message() . "<br />Could not continue, upgrade was not completed.";
return;
}
} elseif ($type == "postgresql") {
pg_query($conn, $t_sql);
if (pg_last_error($conn) != 0) {
$errorMsg = "PG-SQL Panic! : " . pg_last_error($conn) . "<br />Could not continue, upgrade was not completed.";
return;
}
}
}
return true;
}
/**
* connectDB
* Connects to the Database, dependant on the server type
* @return object
* @param String $db Database Type
* @param String $server
* @param String $user
* @param String $pwd
* @param String $dbname
*/
function connectDB($db, $server, $user, $pwd, $dbname) {
$my = null;
switch ($db) {
case 'mysql':
$my = mysql_connect($server, $user, $pwd, true);
mysql_select_db($dbname, $my);
break;
case 'postgresql':
$my = pg_connect("host=$server port=55432 dbname=$dbname user=$user password=$pwd");
break;
case 'sqlserver':
$my = @mssql_connect($server, $user, $pwd);
mssql_select_db($dbname, $my);
break;
}
return $my;
}
function rewriteConfig($settingsFile) {
//Okay this is the icky part.. We are going to open this up and you know do all the stuff
include($settingsFile);
$myserver = MYSERVER;
$mylogin = MYLOGIN;
$mypassword = MYPASSWORD;
$mydatabase = MYDATABASE;
if (defined("SMTPSERVER")) $smtpserver = SMTPSERVER; else $smtpserver = '';
if (defined("SMTPLOGIN")) $smtplogin = SMTPLOGIN; else $smtplogin = '';
if (defined("SMTPPASSWORD")) $smtppassword = SMTPPASSWORD; else $smtppassword = '';
if (defined("FTPSERVER")) $ftpserver = FTPSERVER; else $ftpserver = '';
if (defined("FTPLOGIN")) $ftplogin = FTPLOGIN; else $ftplogin = '';
if (defined("FTPPASSWORD")) $ftppassword = FTPPASSWORD; else $ftppassword = '';
$theme = THEME;
$version = "2.5";
$docType = addslashes($setDoctype);
$docDesc = addslashes($setDescription);
$docWords = addslashes($setKeywords);
$content = <<<STAMP
<?php
#Application name: PhpCollab
#Status page: 2
#Path by root: ../includes/settings.php
# installation type
\$installationType = "$installationType"; //select "offline" or "online"
# select database application
\$databaseType = "$databaseType"; //select "sqlserver", "postgresql" or "mysql"
# database parameters
define('MYSERVER','$myserver');
define('MYLOGIN','$mylogin');
define('MYPASSWORD','$mypassword');
define('MYDATABASE','$mydatabase');
# notification method
\$notificationMethod = "$notificationMethod"; //select "mail" or "smtp"
# smtp parameters (only if \$notificationMethod == "smtp")
define('SMTPSERVER','$smtpserver');
define('SMTPLOGIN','$smtplogin');
define('SMTPPASSWORD','$smtppassword');
# create folder method
\$mkdirMethod = "$mkdirMethod"; //select "FTP" or "PHP"
# ftp parameters (only if \$mkdirMethod == "FTP")
define('FTPSERVER','$ftpserver');
define('FTPLOGIN','$ftplogin');
define('FTPPASSWORD','$ftppassword');
# PhpCollab root according to ftp account (only if \$mkdirMethod == "FTP")
\$ftpRoot = "$ftpRoot"; //no slash at the end
# Invoicing module
\$enableInvoicing = "true";
# theme choice
define('THEME','$theme');
# newsdesk limiter
\$newsdesklimit = 1;
# if 1 the admin logs in his homepage
\$adminathome = 0;
# session.trans_sid forced
\$trans_sid = "$trans_sid";
# timezone GMT management
\$gmtTimezone = "$gmtTimezone";
# language choice
\$langDefault = "$langdefault";
# Mantis bug tracking parameters
// Should bug tracking be enabled?
\$enableMantis = "$enableMantis";
// Mantis installation directory
\$pathMantis = "$pathMantis"; // add slash at the end
# CVS parameters
// Should CVS be enabled?
\$enable_cvs = "$enable_cvs";
// Should browsing CVS be limited to project members?
\$cvs_protected = "$cvs_protected";
// Define where CVS repositories should be stored
\$cvs_root = "$cvs_root"; //no slash at the end
// Who is the owner CVS files?
// Note that this should be user that runs the web server.
// Most *nix systems use "httpd" or "nobody"
\$cvs_owner = "$cvs_owner";
// CVS related commands
\$cvs_co = "$cvs_co";
\$cvs_rlog = "$cvs_rlog";
\$cvs_cmd = "$cvs_cmd";
# https related parameters
\$pathToOpenssl = "$pathToOpenssl";
# login method, set to "CRYPT" in order CVS authentication to work (if CVS support is enabled)
\$loginMethod = "$loginMethod"; //select "MD5", "CRYPT", or "PLAIN"
# enable LDAP
\$useLDAP = "$useLDAP";
\$configLDAP[ldapserver] = "{$configLDAP[ldapserver]}";
\$configLDAP[searchroot] = "{$configLDAP[searchroot]}";
# htaccess parameters
\$htaccessAuth = "$htaccessAuth";
\$fullPath = "$fullPath"; //no slash at the end
# file management parameters
\$fileManagement = "$fileManagement";
\$maxFileSize = $maxFileSize; //bytes limit for upload
\$root = "$root"; //no slash at the end
# security issue to disallow php files upload
\$allowPhp = "$allowPhp";
# project site creation
\$sitePublish = "$sitePublish";
# enable update checker
\$updateChecker = "$updateChecker";
# e-mail notifications
\$notifications = "$notifications";
# show peer review area
\$peerReview = "$peerReview";
# show items for home
\$showHomeBookmarks = "true";
\$showHomeProjects = "true";
\$showHomeTasks = "true";
\$showHomeSubtasks = "true";
\$showHomeDiscussions = "true";
\$showHomeReports = "true";
\$showHomeNotes = "true";
\$showHomeNewsdesk = "true";
# security issue to disallow auto-login from external link
\$forcedLogin = "$forcedLogin";
# table prefix
\$tablePrefix = "$myprefix";
# database tables
\$tableCollab["assignments"] = "{$myprefix}assignments";
\$tableCollab["calendar"] = "{$myprefix}calendar";
\$tableCollab["files"] = "{$myprefix}files";
\$tableCollab["logs"] = "{$myprefix}logs";
\$tableCollab["members"] = "{$myprefix}members";
\$tableCollab["notes"] = "{$myprefix}notes";
\$tableCollab["notifications"] = "{$myprefix}notifications";
\$tableCollab["organizations"] = "{$myprefix}organizations";
\$tableCollab["posts"] = "{$myprefix}posts";
\$tableCollab["projects"] = "{$myprefix}projects";
\$tableCollab["reports"] = "{$myprefix}reports";
\$tableCollab["sorting"] = "{$myprefix}sorting";
\$tableCollab["tasks"] = "{$myprefix}tasks";
\$tableCollab["teams"] = "{$myprefix}teams";
\$tableCollab["topics"] = "{$myprefix}topics";
\$tableCollab["phases"] = "{$myprefix}phases";
\$tableCollab["support_requests"] = "{$myprefix}support_requests";
\$tableCollab["support_posts"] = "{$myprefix}support_posts";
\$tableCollab["subtasks"] = "{$myprefix}subtasks";
\$tableCollab["updates"] = "{$myprefix}updates";
\$tableCollab["bookmarks"] = "{$myprefix}bookmarks";
\$tableCollab["bookmarks_categories"] = "{$myprefix}bookmarks_categories";
\$tableCollab["invoices"] = "{$myprefix}invoices";
\$tableCollab["invoices_items"] = "{$myprefix}invoices_items";
\$tableCollab["services"] = "{$myprefix}services";
\$tableCollab["newsdeskcomments"] = "{$myprefix}newsdeskcomments";
\$tableCollab["newsdeskposts"] = "{$myprefix}newsdeskposts";
# PhpCollab version
\$version = "$version";
# demo mode parameters
\$demoMode = "false";
\$urlContact = "$urlContact";
# Gantt graphs
\$activeJpgraph = "$activeJpgraph";
# developement options in footer
\$footerDev = "$footerDev";
# filter to see only logged user clients (in team / owner)
\$clientsFilter = "$clientsFilter";
# filter to see only logged user projects (in team / owner)
\$projectsFilter = "$projectsFilter";
# Enable help center support requests, values "true" or "false"
\$enableHelpSupport = "$enableHelpSupport";
# Return email address given for clients to respond too.
\$supportEmail = "$supportEmail";
# Support Type, either team or admin. If team is selected a notification will be sent to everyone in the team when a new request is added
\$supportType = "$supportType";
# enable the redirection to the last visited page, EXPERIMENTAL DO NOT USE IT
\$lastvisitedpage = false;
# auto-publish tasks added from client site?
\$autoPublishTasks = false;
# html header parameters
\$setDoctype = "$docType";
\$setTitle = "$setTitle";
\$setDescription = "$docDesc";
\$setKeywords = "$docWords";
?>
STAMP;
file_put_contents($settingsFile, $content);
}
/* End of file upgrade_funcs.inc.php */
/* Location: ./includes/upgrade_funcs.inc.php */
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.