source: trunk/Upload/install/index.php @ 74

Revision 74, 74.7 KB checked in by someotherguy, 3 years ago (diff)

Begin re-coding user-side.

Line 
1<?php
2
3/*
4#======================================================
5|    <#TAG_NAME_TAG#>
6|    =====================================
7|    <#TAG_DEVELOPERS_TAG#>
8|    <#TAG_COPYRIGHT_TAG#>
9|    <#TAG_URL_TAG#>
10|    =====================================
11|    Email: <#TAG_EMAIL_TAG#>
12#======================================================
13|    @ Version: <#TAG_VER_HUMAN_TAG#>
14|    @ Version Int: <#TAG_VER_INT_TAG#>
15|    @ Version Num: <#TAG_VER_NUM_TAG#>
16|    @ Build: <#TAG_VER_BUILD_TAG#>
17#======================================================
18|    | Trellis Desk Installation Index
19#======================================================
20*/
21
22ob_start();
23
24#=============================
25# Safe and Secure
26#=============================
27
28ini_set( 'register_globals', 0 );
29
30if ( @ini_get( 'register_globals' ) )
31{
32        while ( list( $key, $value ) = each( $_REQUEST ) )
33        {
34                unset( $$key );
35        }
36}
37
38$input = get_post();
39
40#=============================
41# Itsy Bitsy Stuff
42#=============================
43
44define( 'VER_NUM', '20011028' );
45define( 'VER_HUM', 'v2.0 Alpha 1' );
46
47error_reporting( E_ERROR | E_WARNING | E_PARSE );
48
49#=============================
50# Define Our Paths
51#=============================
52
53define( "HD_PATH", "../" );
54define( 'HD_INC', HD_PATH ."includes/" );
55define( 'HD_SRC', HD_PATH ."sources/" );
56define( 'HD_SKIN', HD_PATH ."skin/" );
57
58define( 'HD_DEBUG', false );
59
60#=============================
61# Security Check
62#=============================
63
64if ( file_exists( './install.lock' ) && ! $input['step'] != 8 && ! $input['submit'] )
65{
66        step_0('The installer has been locked.  Please delete the <i>install.lock</i> file before continuing.');
67}
68
69#=============================
70# Load Core & Check Steps
71#=============================
72
73if ( $input['step'] > 1 )
74{
75        require_once HD_PATH ."core/a5.php";
76
77        $core = new a5core();
78
79        if ( $input['step'] != 8 || $input['submit'] )
80        {
81                if ( ! $core->cache->data['install']['check_ran'] )
82                {
83                        step_1('Hold on there!  We need to run a system check before you can jump to that step.');
84                }
85
86                if ( ! $core->cache->data['install']['sys_check'] )
87                {
88                        step_1('You must correct all of the failed errors before continuing.');
89                }
90
91                if ( $input['step'] > 3 && ! $core->cache->data['install']['sql_connect'] && ! $input['submit'] )
92                {
93                        step_3( 'Hold on there!  We need to connect to your database before you can jump to that step.', 1 );
94                }
95        }
96
97        if ( ! $input['adv'] )
98        {
99                if ( $input['step'] == 7 || ( $input['step'] == 8 && $input['submit'] ) )
100                {
101                        if ( ! $core->cache->data['install']['admin_set'] )
102                        {
103                                step_4( 'Hold on there!  You need to create your admin account before you can jump to that step.', 1 );
104                        }
105
106                        if ( ! $core->cache->data['install']['set_set'] && ! $input['submit'] )
107                        {
108                                step_5( 'Hold on there!  You need to configure your general settings before you can jump to that step.', 1 );
109                        }
110
111                        if ( ! $core->cache->data['install']['skin_set'] && ! $input['submit'] )
112                        {
113                                step_6( 'Hold on there!  We need to write your skin files before you can jump to that step.', 1 );
114                        }
115                }
116        }
117}
118
119if ( $input['step'] === 'a' )
120{
121        require_once HD_PATH ."core/a5.php";
122
123        $core = new a5core();
124
125        if ( ! $core->cache->data['install']['check_ran'] )
126        {
127                step_1('Hold on there!  We need to run a system check before you can jump to that step.');
128        }
129
130        if ( ! $core->cache->data['install']['sys_check'] )
131        {
132                step_1('You must correct all of the failed errors before continuing.');
133        }
134}
135
136#=============================
137# Let's Get This Party Started
138#=============================
139
140switch( $input['step'] )
141{
142        case 1:
143                step_1();
144    break;
145        case 2:
146                step_2();
147    break;
148        case 3:
149                step_3();
150    break;
151        case 4:
152                step_4();
153    break;
154        case 5:
155                step_5();
156    break;
157        case 6:
158                step_6();
159    break;
160        case 7:
161                step_7();
162    break;
163        case 8:
164                step_8();
165    break;
166        case 'a':
167                step_a();
168    break;
169
170        default:
171                step_0();
172    break;
173}
174
175function step_0($error='')
176{
177        $content = "";
178
179        if ( $error ) $content .= "<div class='critical'>{$error}</div>";
180
181        /*if ( ini_get('allow_url_fopen') )
182        {
183                $version_check = file_get_contents( 'http://core.accord5.com/trellis/version_check.php?type=text' );
184
185                if ( intval( $version_check ) > VER_NUM )
186                {
187                        $version_txt = "<span style='color:#D85C08'>There is a newer version of Trellis Desk available for <a href='http://www.accord5.com/products/trellis'>download</a>.  We recommended downloading the latest version before continuing the installation.</span>";
188                }
189                else
190                {
191                        $version_txt = "It looks like you have the latest version of Trellis Desk.  To begin, click the button below.";
192                }
193        }
194        else
195        {
196                $version_txt = "Due to your PHP's security settings, we were unable to check for the latest version of Trellis Desk.  We recommend checking the <a href='http://www.accord5.com/products/trellis'>Trellis Desk product page</a> to make sure you have the latest version.";
197        }*/
198
199        $content .= "<div class='groupbox'>About the Install Center</div>
200                                <div class='option1'>Hello and welcome to the Trellis Desk Install Center. The Install Center will guide you through your Trellis Desk installation.  At any time, you can go back and make changes to previous steps.  On behalf of ACCORD5, we thank you for choosing and supporting Trellis Desk.</div>
201                                <br />
202                                <div class='groupbox'>Version Check</div>
203                                <div class='option1'>Your Version: ". VER_HUM ." (". VER_NUM .")<br /><br />". $version_txt ."<br /><br /><span style='color:#ff0000;font-weight:bold'>WARNING! This is ALPHA software and does not come with a warranty of any kind. It is not ready for production / live use. There are many bugs and areas to-be-completed. Please install at your own risk.</span></div>
204                                <div class='formtail'><div class='fb_pad'><a href='index.php?step=1' class='fake_button'>Let's Begin!</a></div></div>";
205
206        do_output( $content, 0 );
207}
208
209function step_1($error='')
210{
211        $content = "";
212        $captcha = 0;
213        $config_found = 0;
214        $uploads = 0;
215        $chmod = 0;
216        $fatal = 0;
217        $sys_check = 0;
218
219        $success = "<span style='color:#49701B'>Success</span>";
220        $warning = "<span style='color:#D85C08'>Warning</span>";
221        $failed = "<span style='color:#AC241A'>Failed</span>";
222        $info_warning = "style='padding-top:8px;font-size:12px;'";
223        $info_failed = "style='padding-top:8px;font-size:12px;color:#AC241A'";
224
225        if ( $error ) $content .= "<div class='critical'>{$error}</div>";
226
227        $content .= "<div class='groupbox'>Installed Software &amp; Configuration</div>
228                                <table width='100%' cellpadding='0' cellspacing='0'>
229                                <tr>
230                                        <td class='option1' width='80%'>PHP Version (". PHP_VERSION .")</td>
231                                        <td class='option1' width='20%' align='right'>";
232
233        if ( version_compare( PHP_VERSION, '5.2', '>=' ) )
234        {
235                $content .= $success ."</td>
236                                </tr>";
237        }
238        else
239        {
240                $content .= $failed ."</td>
241                                </tr>
242                                <tr>
243                                        <td class='infopop' colspan='2' {$info_failed}>Trellis Desk cannot be installed as it requires PHP version <b>5.2</b> or later.</td>
244                                </tr>";
245
246                $fatal = 1;
247        }
248
249        $content .= "<tr>
250                                        <td class='option1'>Safe Mode</td>
251                                        <td class='option1' align='right'>";
252
253        if( ini_get('safe_mode') )
254        {
255                $content .= $warning ."</td>
256                                </tr>
257                                <tr>
258                                        <td class='infopop' colspan='2' {$info_warning}>Safe mode in PHP is enabled.  You can continue, however this may result in unexpected behavior with Trellis Desk.</td>
259                                </tr>";
260        }
261        else
262        {
263                $content .= $success ."</td>
264                                </tr>";
265        }
266
267        $memory_limit_bytes = return_bytes( ini_get('memory_limit') );
268        $memory_limit_ini = ini_get('memory_limit');
269
270        if ( $memory_limit_ini == '-1' )
271        {
272                $memory_limit = 'No Limit';
273        }
274        elseif ( $memory_limit_bytes )
275        {
276                $memory_limit = format_size( $memory_limit_bytes );
277        }
278        else
279        {
280                $memory_limit = 'No Limit';
281        }
282
283        $content .= "<tr>
284                                        <td class='option1'>Memory Limit (". $memory_limit .")</td>
285                                        <td class='option1' align='right'>";
286
287        if( $memory_limit_ini && $memory_limit_ini != '-1' && $memory_limit_bytes < 5120 )
288        {
289                $content .= $warning ."</td>
290                                </tr>
291                                <tr>
292                                        <td class='infopop' colspan='2' {$info_warning}>Your PHP's memory limit is set to ". $memory_limit .".  We recommend that this value is set to 5 MB or more.</td>
293                                </tr>";
294        }
295        else
296        {
297                $content .= $success ."</td>
298                                </tr>";
299        }
300
301        $content .= "<tr>
302                                        <td class='option1'>GB Library</td>
303                                        <td class='option1' align='right'>";
304
305        if( extension_loaded('gd') )
306        {
307                $content .= $success ."</td>
308                                </tr>";
309
310                $gd_info = gd_info();
311
312                $content .= "<tr>
313                                                <td class='option1'>FreeType Support</td>
314                                                <td class='option1' align='right'>";
315
316                if( $gd_info['FreeType Support'] )
317                {
318                        $content .= $success ."</td>
319                                        </tr>";
320
321                        $captcha = 1;
322                }
323                else
324                {
325                        $content .= $warning ."</td>
326                                        </tr>
327                                        <tr>
328                                                <td class='infopop' colspan='2' {$info_warning}>Your GB Library does not support FreeType, therefore security CAPTCHAs will be disabled.</td>
329                                        </tr>";
330                }
331        }
332        else
333        {
334                $content .= $warning ."</td>
335                                </tr>
336                                <tr>
337                                        <td class='infopop' colspan='2' {$info_warning}>PHP could not load the GB Library, therefore security CAPTCHAs will be disabled.</td>
338                                </tr>";
339        }
340
341        $content .= "<tr>
342                                        <td class='option1'>File Uploads</td>
343                                        <td class='option1' align='right'>";
344
345        if( ini_get('file_uploads') )
346        {
347                $content .= $success ."</td>
348                                </tr>";
349
350                $uploads = 1;
351
352                $upload_max_filesize_bytes = return_bytes( ini_get('upload_max_filesize') );
353                $upload_max_filesize = format_size( $upload_max_filesize_bytes );
354
355                $content .= "<tr>
356                                                <td class='option1'>Maximum Upload Size (". $upload_max_filesize .")</td>
357                                                <td class='option1' align='right'>";
358
359                if( $upload_max_filesize_bytes >= 2097152 )
360                {
361                        $content .= $success ."</td>
362                                        </tr>";
363                }
364                else
365                {
366                        $content .= $warning ."</td>
367                                        </tr>
368                                        <tr>
369                                                <td class='infopop' colspan='2' {$info_warning}>PHP's maximum file upload size is set to ". $upload_max_filesize .".  For your convenience, we recommend that this value is set to at least 2 MB.</td>
370                                        </tr>";
371                }
372
373                $post_max_size_bytes = return_bytes( ini_get('post_max_size') );
374
375                $content .= "<tr>
376                                                <td class='option1'>Maximum POST Size (". format_size( return_bytes( ini_get('post_max_size') ) ) .")</td>
377                                                <td class='option1' align='right'>";
378
379                if( $post_max_size_bytes > $upload_max_filesize_bytes )
380                {
381                        $content .= $success ."</td>
382                                        </tr>";
383                }
384                else
385                {
386                        $content .= $warning ."</td>
387                                        </tr>
388                                        <tr>
389                                                <td class='infopop' colspan='2' {$info_warning}>PHP's maximum POST size less than the maximum file upload size, therefore your file uploads will be limited to ". format_size( $post_max_size_bytes ) .".</td>
390                                        </tr>";
391                }
392        }
393        else
394        {
395                $content .= $warning ."</td>
396                                </tr>
397                                <tr>
398                                        <td class='infopop' colspan='2' {$info_warning}>File uploads are not enabled in PHP, therefore you will not be able to upload attachments to Trellis Desk.</td>
399                                </tr>";
400        }
401
402        $content .= "</table>
403                                <br />
404                                <div class='groupbox'>File Permissions &amp; Config File</div>
405                                <table width='100%' cellpadding='0' cellspacing='0'>
406                                <tr>
407                                        <td class='option1' width='80%'>Configuration File</td>
408                                        <td class='option1' width='20%' align='right'>";
409
410        if ( ! file_exists( HD_PATH .'config.php' ) )
411        {
412                if ( ! file_exists( HD_PATH .'config.php.dist') )
413                {
414                        $content .= $failed ."</td>
415                                        </tr>
416                                        <tr>
417                                                <td class='infopop' colspan='2' {$info_failed}>Trellis Desk could not locate your <i>config.php</i>.  Please upload <i>config.php.dist</i> and rename it to <i>config.php</i>.</td>
418                                        </tr>";
419
420                        $fatal = 1;
421                }
422                else
423                {
424                        if ( ! @rename( HD_PATH .'config.php.dist', HD_PATH .'config.php' ) )
425                        {
426                                $content .= $failed ."</td>
427                                                </tr>
428                                                <tr>
429                                                        <td class='infopop' colspan='2' {$info_failed}>Trellis Desk coult not rename <i>config.php.dist</i> for you. Please rename <i>config.php.dist</i> to <i>config.php</i>.</td>
430                                                </tr>";
431
432                                $fatal = 1;
433                        }
434                        else
435                        {
436                                $config_found = 1;
437                        }
438                }
439        }
440        else
441        {
442                $config_found = 1;
443        }
444
445        if ( $config_found )
446        {
447                if ( ! is_writable( HD_PATH .'config.php' ) )
448                {
449                        @chmod( HD_PATH .'config.php', 0777 );
450                }
451
452                if ( ! is_writable( HD_PATH .'config.php' ) )
453                {
454                        $content .= $failed ."</td>
455                        </tr>
456                        <tr>
457                                <td class='infopop' colspan='2' {$info_failed}>Trellis Desk does not have permission to write to <i>config.php</i>.  Please CHMOD this file to 0777.</td>
458                        </tr>";
459
460                        $fatal = 1;
461                }
462                else
463                {
464                        $content .= $success ."</td>
465                                        </tr>";
466                }
467        }
468
469        $files = array(
470                                        'core/cache'            => array( 'Cache Folder', 0777 ),
471                                        'core/tmp'                      => array( 'Temp Folder', 0777 ),
472                                        'skin'                          => array( 'Skin Folder', 0777 ),
473                                        'skin/s1/compile'       => array( 'Skin Compile Folder', 0777 ),
474                                 );
475
476        if ( $uploads ) $files['uploads'] = array( 'Uploads Folder', 0777 );
477
478        while ( list( $ck_file, $ck_perm ) = each( $files ) )
479        {
480                $content .= "<tr>
481                                                <td class='option1'>". $ck_perm[0] ."</td>
482                                                <td class='option1' align='right'>";
483
484                if ( ! is_writable( HD_PATH . $ck_file ) )
485                {
486                        @chmod( HD_PATH . $ck_file, $ck_perm[1] );
487                }
488
489                if ( ! is_writable( HD_PATH . $ck_file ) )
490                {
491                        $content .= $failed ."</td>
492                                        </tr>
493                                        <tr>
494                                                <td class='infopop' colspan='2' {$info_failed}>Trellis Desk does not have permission to write to <i>". $ck_file ."</i>.  Please CHMOD this file/folder to 0777.</td>
495                                        </tr>";
496
497                        $fatal = 1;
498                }
499                else
500                {
501                        $content .= $success ."</td>
502                                        </tr>";
503                }
504        }
505
506        $content .= "<tr>
507                                        <td class='option1'>Install Folder</td>
508                                        <td class='option1' align='right'>";
509
510        if( ! is_writable( './') )
511        {
512                $content .= $warning ."</td>
513                                </tr>
514                                <tr>
515                                        <td class='infopop' colspan='2' {$info_warning}>This <i>install</i> directory is not writeable, therefore the Install Center will be unable to create a lock file when installation is complete.  The lock file prevents the installer from being run twice and is recommended for security.  We recommened you CHMOD this <i>install</i> directory to 0777, however you may continue without doing so.</td>
516                                </tr>";
517        }
518        else
519        {
520                $content .= $success ."</td>
521                                </tr>";
522        }
523
524        if ( $fatal )
525        {
526                $button = "<a href='index.php?step=1' class='fake_button'>Try Again</a>";
527        }
528        else
529        {
530                $button = "<a href='index.php?step=2' class='fake_button'>Continue</a>";
531                $sys_check = 1;
532        }
533
534        if ( is_writable( HD_PATH .'core/cache' ) )
535        {
536                require_once HD_PATH ."core/a5.php";
537
538                $core = new a5core();
539
540                $to_cache = array(
541                                                  'sys_check'   => $sys_check,
542                                                  'check_ran'   => 1,
543                                                  'captcha'             => $captcha,
544                                                  'uploads'             => $uploads,
545                                                  );
546
547                $core->add( 'install', $to_cache );
548
549                $core->shut_down();
550        }
551
552        $content .= "</table>
553                                <div class='formtail'><div class='fb_pad'>{$button}</div></div>";
554
555        do_output( $content, 1 );
556}
557
558function step_2()
559{
560        global $core;
561
562        $content = "<div class='groupbox'>Guided or Advanced</div>
563                                <div class='option1'>The Install Center offers you two ways to complete you Trellis Desk installation.  You can choose to continue with the guided installation or go advanced for more experienced users.  The guided installation will take you through six more steps, each one with detailed instructions.  Advance will allow you to finish the installation in one more step, while collecting only the necessary information to complete the installation.  Take your pick below.</div>
564                                <div class='formtail'><div class='fb_pad'><a href='index.php?step=a' class='fake_button'>Advanced</a></div>";
565
566        # &nbsp;<a href='index.php?step=3' class='fake_button'>Continue with Guided</a></div>
567
568        do_output( $content, 2 );
569}
570
571function step_3($error='', $bypass=0)
572{
573        global $core;
574
575        $content = "";
576
577        if ( $error )
578        {
579                $content .= "<div class='critical'>{$error}</div>";
580        }
581
582        if ( ! $error || ( $error && $bypass ) )
583        {
584                if ( ! $_POST['sql_host'] ) $_POST['sql_host'] = 'localhost';
585                if ( ! $_POST['sql_prefix'] ) $_POST['sql_prefix'] = 'td_';
586        }
587
588        if ( $core->cache->data['install']['sql_connect'] && ! $error )
589        {
590                $_POST['sql_host'] = $core->cache->data['install']['sql_host'];
591                $_POST['sql_user'] = $core->cache->data['install']['sql_user'];
592                $_POST['sql_db'] = $core->cache->data['install']['sql_db'];
593                $_POST['sql_prefix'] = $core->cache->data['install']['sql_prefix'];
594
595                $content .= "<div class='alert'>Trellis Desk already has your database credentials stored.  If you would like to change them, edit the information below and click Continue.  Otherwise, <a href='index.php?step=4'>click here</a>.</div>";
596        }
597
598        $content .= "<form action='index.php?step=4' method='post'>
599                                <div class='groupbox'>Database Credentials</div>
600                                <div class='option1'>Trellis Desk needs a <a href='http://www.mysql.com/' target='_blank'>MySQL database</a> to store your data such as users and tickets.  Please enter your database credentials below.  If you are unsure about this information, contact your hosting provider.</div>
601                                <table width='100%' cellpadding='0' cellspacing='0'>
602                                <tr>
603                                        <td class='option2' width='25%'>MySQL Host</td>
604                                        <td class='option2' width='75%'><input type='text' name='sql_host' id='sql_host' value='{$_POST['sql_host']}' size='40' /></td>
605                                </tr>
606                                <tr>
607                                        <td colspan='2'>
608                                                <div class='infopop'>
609                                                        <a onclick=\"javascript:Effect.toggle('info1','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
610                                                        <div id='info1' style='display: none;'>
611                                                        <div>
612                                                                The MySQL Host is the location of your MySQL server.  This can be a domain or IP address.  If your MySQL service is located on this machine, as it is in most cases, you can leave this at <i>localhost</i>.
613                                                        </div>
614                                                        </div>
615                                                </div>
616                                        </td>
617                                </tr>
618                                <tr>
619                                        <td class='option1'>MySQL Username</td>
620                                        <td class='option1'><input type='text' name='sql_user' id='sql_user' value='{$_POST['sql_user']}' size='40' /></td>
621                                </tr>
622                                <tr>
623                                        <td colspan='2'>
624                                                <div class='infopop'>
625                                                        <a onclick=\"javascript:Effect.toggle('info2','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
626                                                        <div id='info2' style='display: none;'>
627                                                        <div>
628                                                                This is your MySQL username used to connect to your MySQL Server.  This user must have SELECT, CREATE, INSERT, ALTER, UPDATE, DROP, DELETE, and INDEX permissions to the MySQL database (see below).
629                                                        </div>
630                                                        </div>
631                                                </div>
632                                        </td>
633                                </tr>
634                                <tr>
635                                        <td class='option2'>MySQL Password</td>
636                                        <td class='option2'><input type='password' name='sql_pass' id='sql_pass' value='' size='40' /></td>
637                                </tr>
638                                <tr>
639                                        <td colspan='2'>
640                                                <div class='infopop'>
641                                                        <a onclick=\"javascript:Effect.toggle('info3','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
642                                                        <div id='info3' style='display: none;'>
643                                                        <div>
644                                                                Simply your password for the MySQL username you entered above.
645                                                        </div>
646                                                        </div>
647                                                </div>
648                                        </td>
649                                </tr>
650                                <tr>
651                                        <td class='option1'>Password Confirm</td>
652                                        <td class='option1'><input type='password' name='sql_pass_b' id='sql_pass_b' value='' size='40' /></td>
653                                </tr>
654                                <tr>
655                                        <td colspan='2'>
656                                                <div class='infopop'>
657                                                        <a onclick=\"javascript:Effect.toggle('info4','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
658                                                        <div id='info4' style='display: none;'>
659                                                        <div>
660                                                                No, we are not doing this just for fun. It's for security.  Please enter the same password you just entered above.
661                                                        </div>
662                                                        </div>
663                                                </div>
664                                        </td>
665                                </tr>
666                                <tr>
667                                        <td class='option2'>MySQL Database</td>
668                                        <td class='option2'><input type='text' name='sql_db' id='sql_db' value='{$_POST['sql_db']}' size='40' /></td>
669                                </tr>
670                                <tr>
671                                        <td colspan='2'>
672                                                <div class='infopop'>
673                                                        <a onclick=\"javascript:Effect.toggle('info5','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
674                                                        <div id='info5' style='display: none;'>
675                                                        <div>
676                                                                This is the name of the MySQL database where your Trellis Desk data will be stored.  The MySQL user entered above must have permission to access this database.
677                                                        </div>
678                                                        </div>
679                                                </div>
680                                        </td>
681                                </tr>
682                                <tr>
683                                        <td class='option1'>MySQL Table Prefix</td>
684                                        <td class='option1'><input type='text' name='sql_prefix' id='sql_prefix' value='{$_POST['sql_prefix']}' size='4' /></td>
685                                </tr>
686                                <tr>
687                                        <td colspan='2'>
688                                                <div class='infopop'>
689                                                        <a onclick=\"javascript:Effect.toggle('info6','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
690                                                        <div id='info6' style='display: none;'>
691                                                        <div>
692                                                                The MySQL Table Prefix is the prefix Trellis Desk will place in front of all its table names.  This is especially useful for storing multiple Trellis Desk installations in the same database.  If you are unclear on what this does, it's best to leave it at the default, <i>td_</i>.
693                                                        </div>
694                                                        </div>
695                                                </div>
696                                        </td>
697                                </tr>
698                                </table>
699                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Continue' class='button' /></div>
700                                </form>";
701
702        do_output( $content, 3 );
703}
704
705function step_4($error='', $bypass=0)
706{
707        global $core, $input;
708
709        if ( $input['submit'] && ! $error )
710        {
711                if ( $_POST['sql_pass'] != $_POST['sql_pass_b'] )
712                {
713                        step_3('Your MySQL passwords do not match.');
714                }
715
716                if ( ! @mysql_connect( $_POST['sql_host'], $_POST['sql_user'], $_POST['sql_pass'] ) )
717                {
718                        step_3('We could not connect to the MySQL Server.  Please check that your MySQL credentails are correct and try again.');
719                }
720
721                $mysql_ver = mysql_get_server_info();
722
723                if ( strpos( $mysql_ver, '-' ) )
724                {
725                        $mysql_ver = substr( $mysql_ver, 0, strpos( $mysql_ver, '-' ) );
726                }
727
728                if ( version_compare( $mysql_ver, '4.1', '<' ) )
729                {
730                        step_3('Sorry, Trellis Desk cannot be installed as it requires MySQL version 4.1 or later.');
731                }
732
733                if ( ! @mysql_select_db( $_POST['sql_db'] ) )
734                {
735                        step_3('We could not connect to the MySQL Database.  Please check that your MySQL credentails are correct and try again.');
736                }
737
738                $tables = array();
739                $sql_exists = 0;
740
741                if ( $tables_sql = @mysql_query('SHOW TABLES') )
742                {
743                        while( $tables_result = mysql_fetch_array( $tables_sql ) )
744                        {
745                                $tables[ $tables_result[0] ] = 1;
746                        }
747                }
748
749                if ( $tables[ $_POST['sql_db'] .'upg_history'] ) $sql_exists = 1;
750
751                $to_cache = array(
752                                                  'sql_connect' => 1,
753                                                  'sql_host'    => $_POST['sql_host'],
754                                                  'sql_user'    => $_POST['sql_user'],
755                                                  'sql_pass'    => $_POST['sql_pass'],
756                                                  'sql_db'              => $_POST['sql_db'],
757                                                  'sql_prefix'  => $_POST['sql_prefix'],
758                                                  'sql_exists'  => $sql_exists,
759                                                  );
760
761                $core->add( 'install', $to_cache );
762        }
763
764        $content = "";
765
766        if ( $error )
767        {
768                $content .= "<div class='critical'>{$error}</div>";
769        }
770
771        if ( ! $error || ( $error && $bypass ) )
772        {
773                if ( ! $input['admin_dst_active'] ) $input['admin_dst_active'] = 0;
774                if ( ! $input['admin_rte_enable'] ) $input['admin_rte_enable'] = 1;
775                if ( ! $input['admin_email_ticket'] ) $input['admin_email_ticket'] = 1;
776                if ( ! $input['admin_email_reply'] ) $input['admin_email_reply'] = 1;
777        }
778
779        if ( $core->cache->data['install']['admin_set'] && ! $error )
780        {
781                $input['admin_user'] = $core->cache->data['install']['admin_user'];
782                $input['admin_email'] = $core->cache->data['install']['admin_email'];
783                $input['admin_time_zone'] = $core->cache->data['install']['admin_time_zone'];
784                $input['admin_dst_active'] = $core->cache->data['install']['admin_dst_active'];
785                $input['admin_rte_enable'] = $core->cache->data['install']['admin_rte_enable'];
786                $input['admin_email_ticket'] = $core->cache->data['install']['admin_email_ticket'];
787                $input['admin_email_reply'] = $core->cache->data['install']['admin_email_reply'];
788
789                $content .= "<div class='alert'>Trellis Desk already has your admin account credentials stored.  If you would like to change them, edit the information below and click Continue.  Otherwise, <a href='index.php?step=5'>click here</a>.</div>";
790        }
791
792        ( $input['admin_dst_active'] ) ? $dst_select1 = " checked='checked'" : $dst_select0 = " checked='checked'";
793        ( $input['admin_rte_enable'] ) ? $rte_select1 = " checked='checked'" : $rte_select0 = " checked='checked'";
794
795        if ( $input['admin_email_ticket'] ) $email_ticket_select1 = " checked='checked'";
796        if ( $input['admin_email_reply'] ) $email_reply_select1 = " checked='checked'";
797
798        $content .= "<form action='index.php?step=5' method='post'>
799                                <div class='groupbox'>Your Admin Account Credentials</div>
800                                <div class='option1'>You will now create your admin account for your Trellis Desk installation.  This account will be used to access the Administrator Control Panel and has the highest level of access.  Please choose these credentials carefully.</div>
801                                <table width='100%' cellpadding='0' cellspacing='0'>
802                                <tr>
803                                        <td class='option2' width='25%'>Username</td>
804                                        <td class='option2' width='75%'><input type='text' name='admin_user' id='admin_user' value='{$input['admin_user']}' size='40' /></td>
805                                </tr>
806                                <tr>
807                                        <td colspan='2'>
808                                                <div class='infopop'>
809                                                        <a onclick=\"javascript:Effect.toggle('info1','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
810                                                        <div id='info1' style='display: none;'>
811                                                        <div>
812                                                                This is the username that you will use to login to the Administrator Control Panel.
813                                                        </div>
814                                                        </div>
815                                                </div>
816                                        </td>
817                                </tr>
818                                <tr>
819                                        <td class='option1'>Password</td>
820                                        <td class='option1'><input type='password' name='admin_pass' id='admin_pass' value='' size='40' /></td>
821                                </tr>
822                                <tr>
823                                        <td colspan='2'>
824                                                <div class='infopop'>
825                                                        <a onclick=\"javascript:Effect.toggle('info2','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
826                                                        <div id='info2' style='display: none;'>
827                                                        <div>
828                                                                This is your password that you will use, along with your username, to login to the Administrator Control Panel.
829                                                        </div>
830                                                        </div>
831                                                </div>
832                                        </td>
833                                </tr>
834                                <tr>
835                                        <td class='option2'>Confirm Password</td>
836                                        <td class='option2'><input type='password' name='admin_pass_b' id='admin_pass_b' value='' size='40' /></td>
837                                </tr>
838                                <tr>
839                                        <td colspan='2'>
840                                                <div class='infopop'>
841                                                        <a onclick=\"javascript:Effect.toggle('info3','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
842                                                        <div id='info3' style='display: none;'>
843                                                        <div>
844                                                                Please confirm your password for security.  Be sure not to forget it!
845                                                        </div>
846                                                        </div>
847                                                </div>
848                                        </td>
849                                </tr>
850                                <tr>
851                                        <td class='option1'>Email Address</td>
852                                        <td class='option1'><input type='text' name='admin_email' id='admin_email' value='{$input['admin_email']}' size='40' /></td>
853                                </tr>
854                                <tr>
855                                        <td colspan='2'>
856                                                <div class='infopop'>
857                                                        <a onclick=\"javascript:Effect.toggle('info4','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
858                                                        <div id='info4' style='display: none;'>
859                                                        <div>
860                                                                Your email address that you wish to be attached to your admin account.  This email address will receive email notifications from Trellis Desk for events such as a new ticket submission, etc.  You can manage your email notification preferences in My Account after the installation is complete.
861                                                        </div>
862                                                        </div>
863                                                </div>
864                                        </td>
865                                </tr>
866                                <tr>
867                                        <td class='option1'>Time Zone</td>
868                                        <td class='option1'><select name='admin_time_zone' id='admin_time_zone'>". build_time_zone_drop( $input['admin_time_zone'] ) ."</select></td>
869                                </tr>
870                                <tr>
871                                        <td colspan='2'>
872                                                <div class='infopop'>
873                                                        <a onclick=\"javascript:Effect.toggle('info5','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
874                                                        <div id='info5' style='display: none;'>
875                                                        <div>
876                                                                Please select your time zone, regardless of Daylight Savings (you will select that below).
877                                                        </div>
878                                                        </div>
879                                                </div>
880                                        </td>
881                                </tr>
882                                <tr>
883                                        <td class='option1'>DST Active</td>
884                                        <td class='option1' style='font-weight: normal'>
885                                                <label for='dst_active1'><input type='radio' name='admin_dst_active' id='dst_active1' value='1' class='radio'{$dst_select1} /> Yes</label>&nbsp;&nbsp;<label for='dst_active0'><input type='radio' name='admin_dst_active' id='dst_active0' value='0' class='radio'{$dst_select0} /> No</label>
886                                        </td>
887                                </tr>
888                                <tr>
889                                        <td colspan='2'>
890                                                <div class='infopop'>
891                                                        <a onclick=\"javascript:Effect.toggle('info6','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
892                                                        <div id='info6' style='display: none;'>
893                                                        <div>
894                                                                Please select Yes if Daylight Saving Time is currently active in your time zone.
895                                                        </div>
896                                                        </div>
897                                                </div>
898                                        </td>
899                                </tr>
900                                <tr>
901                                        <td class='option2'>Rich Text Editor</td>
902                                        <td class='option2' style='font-weight: normal'>
903                                                <label for='rte_enable1'><input type='radio' name='admin_rte_enable' id='rte_enable1' value='1' class='radio'{$rte_select1} /> Enabled</label>&nbsp;&nbsp;<label for='rte_enable0'><input type='radio' name='admin_rte_enable' id='rte_enable0' value='0' class='radio'{$rte_select0} /> Disabled</label>
904                                        </td>
905                                </tr>
906                                <tr>
907                                        <td colspan='2'>
908                                                <div class='infopop'>
909                                                        <a onclick=\"javascript:Effect.toggle('info7','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
910                                                        <div id='info7' style='display: none;'>
911                                                        <div>
912                                                                Select whether or not you would like to use the rich text editor. The rich text editor allows you to apply text styles such as bold to ticket replies, etc.
913                                                        </div>
914                                                        </div>
915                                                </div>
916                                        </td>
917                                </tr>
918                                <tr>
919                                        <td class='option2'>Email Notifications</td>
920                                        <td class='option2' style='font-weight: normal'>
921                                                <label for='email_staff_new_ticket1'><input type='checkbox' name='admin_email_ticket' id='email_staff_new_ticket1' value='1' class='ckbox'{$email_ticket_select1} /> New Tickets in My Departments</label>
922                                                <div style='margin-top:3px'><label for='email_staff_ticket_reply1'><input type='checkbox' name='admin_email_reply' id='email_staff_ticket_reply1' value='1' class='ckbox'{$email_reply_select1} /> New Replies in My Departments</label></div>
923                                        </td>
924                                </tr>
925                                <tr>
926                                        <td colspan='2'>
927                                                <div class='infopop'>
928                                                        <a onclick=\"javascript:Effect.toggle('info8','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
929                                                        <div id='info8' style='display: none;'>
930                                                        <div>
931                                                                Select the event types for which you would like to receive email notifications for.  For example, if you selecet New Tickets in My Departments, you will receive an email notification for every new ticket created in your departments.
932                                                        </div>
933                                                        </div>
934                                                </div>
935                                        </td>
936                                </tr>
937                                </table>
938                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Continue' class='button' /></div>
939                                </form>";
940
941        do_output( $content, 4 );
942}
943
944function step_5($error='', $bypass=0)
945{
946        global $core, $input;
947
948        if ( $input['submit'] && ! $error )
949        {
950                if ( ! $input['admin_user'] )
951                {
952                        step_4('Please enter a username.');
953                }
954
955                if ( $input['admin_pass'] != $input['admin_pass_b'] )
956                {
957                        step_4('Your passwords do not match.');
958                }
959
960                if ( ! validate_email( $input['admin_email'] ) )
961                {
962                        step_4('Please enter a valid email address.');
963                }
964
965                require HD_PATH .'config.php';
966
967        $pwsalt = '';
968                $lksalt = '';
969                $rksalt = '';
970
971                while( strlen( $pwsalt ) < 16 ) $pwsalt .= chr( rand( 32, 126 ) );
972                while( strlen( $lksalt ) < 8 ) $lksalt .= chr( rand( 32, 126 ) );
973                while( strlen( $rksalt ) < 8 ) $rksalt .= chr( rand( 32, 126 ) );
974
975                $lksalt .= uniqid( rand(), true );
976                $rksalt .= uniqid( rand(), true );
977
978                $pwhash = hash( 'whirlpool', $pwsalt . $input['admin_pass'] . $config['pass_key'] );
979                $lkhash = str_replace( "=", "", base64_encode( strrev( hash( 'whirlpool', $lksalt . $config['cookie_key'] ) ) ) );
980                $rkhash = md5( $rksalt . $config['rss_key'] );
981
982                $to_cache = array(
983                                                  'admin_set'                   => 1,
984                                                  'admin_user'                  => $input['admin_user'],
985                                                  'admin_pass_hash'             => $pwhash,
986                                                  'admin_pass_salt'             => $pwsalt,
987                                                  'admin_login_key'             => $lkhash,
988                                                  'admin_email'                 => $input['admin_email'],
989                                                  'admin_time_zone'             => $input['admin_time_zone'],
990                                                  'admin_dst_active'    => $input['admin_dst_active'],
991                                                  'admin_rte_enable'    => $input['admin_rte_enable'],
992                                                  'admin_email_ticket'  => $input['admin_email_ticket'],
993                                                  'admin_email_reply'   => $input['admin_email_reply'],
994                                                  'admin_rss_key'               => $rkhash,
995                                  'pass_key'                    => $config['pass_key'],
996                                  'cookie_key'                  => $config['cookie_key'],
997                                  'session_key'                 => $config['session_key'],
998                                  'rss_key'                         => $config['rss_key'],
999                                                  );
1000
1001                $core->add( 'install', $to_cache );
1002        }
1003
1004        $content = "";
1005
1006        if ( $error )
1007        {
1008                $content .= "<div class='critical'>{$error}</div>";
1009        }
1010
1011        if ( ! $error || ( $error && $bypass ) )
1012        {
1013                if ( ! $core->cache->data['install']['admin_email'] ) $core->cache->data['install']['admin_email'] = $input['admin_email'];
1014
1015                if ( ! $input['set_hd_name'] ) $input['set_hd_name'] = 'Trellis Desk';
1016                if ( ! $input['set_out_email'] ) $input['set_out_email'] = $core->cache->data['install']['admin_email'];
1017                if ( ! $input['set_email_val'] ) $input['set_email_val'] = 1;
1018                if ( ! $input['set_admin_val'] ) $input['set_admin_val'] = 0;
1019                if ( ! $input['set_tickets_suggest'] ) $input['set_tickets_suggest'] = 1;
1020                if ( ! $input['set_news_comments'] ) $input['set_news_comments'] = 1;
1021                if ( ! $input['set_allow_kb_comment'] ) $input['set_allow_kb_comment'] = 1;
1022                if ( ! $input['set_allow_kb_rating'] ) $input['set_allow_kb_rating'] = 1;
1023                if ( ! $input['set_allow_reply_rating'] ) $input['set_allow_reply_rating'] = 1;
1024        }
1025
1026        if ( $core->cache->data['install']['set_set'] && ! $error )
1027        {
1028                $input['set_hd_name'] = $core->cache->data['install']['set_hd_name'];
1029                $input['set_out_email'] = $core->cache->data['install']['set_out_email'];
1030                $input['set_email_val'] = $core->cache->data['install']['set_email_val'];
1031                $input['set_admin_val'] = $core->cache->data['install']['set_admin_val'];
1032                $input['set_tickets_suggest'] = $core->cache->data['install']['set_tickets_suggest'];
1033                $input['set_news_comments'] = $core->cache->data['install']['set_news_comments'];
1034                $input['set_allow_kb_comment'] = $core->cache->data['install']['set_allow_kb_comment'];
1035                $input['set_allow_kb_rating'] = $core->cache->data['install']['set_allow_kb_rating'];
1036                $input['set_allow_reply_rating'] = $core->cache->data['install']['set_allow_reply_rating'];
1037
1038                $content .= "<div class='alert'>Trellis Desk already has your settings stored.  If you would like to change them, edit the information below and click Continue.  Otherwise, <a href='index.php?step=6'>click here</a>.</div>";
1039        }
1040
1041        ( $input['set_email_val'] ) ? $email_val_select1 = " checked='checked'" : $email_val_select0 = " checked='checked'";
1042        ( $input['set_admin_val'] ) ? $admin_val_select1 = " checked='checked'" : $admin_val_select0 = " checked='checked'";
1043        ( $input['set_tickets_suggest'] ) ? $tickets_suggest_select1 = " checked='checked'" : $tickets_suggest_select0 = " checked='checked'";
1044        ( $input['set_news_comments'] ) ? $news_comments_select1 = " checked='checked'" : $news_comments_select0 = " checked='checked'";
1045        ( $input['set_allow_kb_comment'] ) ? $kb_comments_select1 = " checked='checked'" : $kb_comments_select0 = " checked='checked'";
1046        ( $input['set_allow_kb_rating'] ) ? $kb_rating_select1 = " checked='checked'" : $kb_rating_select0 = " checked='checked'";
1047        ( $input['set_allow_reply_rating'] ) ? $ticket_rating_select1 = " checked='checked'" : $ticket_rating_select0 = " checked='checked'";
1048
1049        $content .= "<form action='index.php?step=6' method='post'>
1050                                <div class='groupbox'>System Settings</div>
1051                                <div class='option1'>Below you can configure common settings for Trellis Desk.  It is safe to skip this step by leaving the settings at their default values and clicking Continue.</div>
1052                                <table width='100%' cellpadding='0' cellspacing='0'>
1053                                <tr>
1054                                        <td class='option2' width='30%'>Help Desk Name</td>
1055                                        <td class='option2' width='70%'><input type='text' name='set_hd_name' id='set_hd_name' value='{$input['set_hd_name']}' size='40' /></td>
1056                                </tr>
1057                                <tr>
1058                                        <td colspan='2'>
1059                                                <div class='infopop'>
1060                                                        <a onclick=\"javascript:Effect.toggle('info1','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1061                                                        <div id='info1' style='display: none;'>
1062                                                        <div>
1063                                                                This is the name of your help desk system. It's used when relating to this system.  For example, you could use <i>ACCORD5 Customer Service</i>.
1064                                                        </div>
1065                                                        </div>
1066                                                </div>
1067                                        </td>
1068                                </tr>
1069                                <tr>
1070                                        <td class='option1'>Outgoing Email</td>
1071                                        <td class='option1'><input type='text' name='set_out_email' id='set_out_email' value='{$input['set_out_email']}' size='40' /></td>
1072                                </tr>
1073                                <tr>
1074                                        <td colspan='2'>
1075                                                <div class='infopop'>
1076                                                        <a onclick=\"javascript:Effect.toggle('info2','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1077                                                        <div id='info2' style='display: none;'>
1078                                                        <div>
1079                                                                This email will be used when Trellis Desk sends emails to your users (From header).
1080                                                        </div>
1081                                                        </div>
1082                                                </div>
1083                                        </td>
1084                                </tr>
1085                                <tr>
1086                                        <td class='option2'>Require Email Validation</td>
1087                                        <td class='option2' style='font-weight: normal'>
1088                                                <label for='email_validation1'><input type='radio' name='set_email_val' id='email_validation1' value='1' class='radio'{$email_val_select1} /> Yes</label>&nbsp;&nbsp;<label for='email_validation0'><input type='radio' name='set_email_val' id='email_validation0' value='0' class='radio'{$email_val_select0} /> No</label>
1089                                        </td>
1090                                </tr>
1091                                <tr>
1092                                        <td colspan='2'>
1093                                                <div class='infopop'>
1094                                                        <a onclick=\"javascript:Effect.toggle('info3','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1095                                                        <div id='info3' style='display: none;'>
1096                                                        <div>
1097                                                                If set to yes, users will be required to verify their email before being placed in the users group.
1098                                                        </div>
1099                                                        </div>
1100                                                </div>
1101                                        </td>
1102                                </tr>
1103                                <tr>
1104                                        <td class='option1'>Require Admin Validation</td>
1105                                        <td class='option1' style='font-weight: normal'>
1106                                                <label for='admin_validation1'><input type='radio' name='set_admin_val' id='admin_validation1' value='1' class='radio'{$admin_val_select1} /> Yes</label>&nbsp;&nbsp;<label for='admin_validation0'><input type='radio' name='set_admin_val' id='admin_validation0' value='0' class='radio'{$admin_val_select0} /> No</label>
1107                                        </td>
1108                                </tr>
1109                                <tr>
1110                                        <td colspan='2'>
1111                                                <div class='infopop'>
1112                                                        <a onclick=\"javascript:Effect.toggle('info4','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1113                                                        <div id='info4' style='display: none;'>
1114                                                        <div>
1115                                                                If set to yes, an administrator must approve all new accounts before they are moved into the users group.
1116                                                        </div>
1117                                                        </div>
1118                                                </div>
1119                                        </td>
1120                                </tr>
1121                                <tr>
1122                                        <td class='option2'>Enable KB Suggestions</td>
1123                                        <td class='option2' style='font-weight: normal'>
1124                                                <label for='tickets_suggest1'><input type='radio' name='set_tickets_suggest' id='tickets_suggest1' value='1' class='radio'{$tickets_suggest_select1} /> Yes</label>&nbsp;&nbsp;<label for='tickets_suggest0'><input type='radio' name='set_tickets_suggest' id='tickets_suggest0' value='0' class='radio'{$tickets_suggest_select0} /> No</label>
1125                                        </td>
1126                                </tr>
1127                                <tr>
1128                                        <td colspan='2'>
1129                                                <div class='infopop'>
1130                                                        <a onclick=\"javascript:Effect.toggle('info5','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1131                                                        <div id='info5' style='display: none;'>
1132                                                        <div>
1133                                                                If enabled, Trellis Desk will search the knowledge base for articles that might answer the users' inquiry before the ticket is sent.
1134                                                        </div>
1135                                                        </div>
1136                                                </div>
1137                                        </td>
1138                                </tr>
1139                                <tr>
1140                                        <td class='option1'>Enable News Commenting</td>
1141                                        <td class='option1' style='font-weight: normal'>
1142                                                <label for='news_comments1'><input type='radio' name='set_news_comments' id='news_comments1' value='1' class='radio'{$news_comments_select1} /> Yes</label>&nbsp;&nbsp;<label for='news_comments0'><input type='radio' name='set_news_comments' id='news_comments0' value='0' class='radio'{$news_comments_select0} /> No</label>
1143                                        </td>
1144                                </tr>
1145                                <tr>
1146                                        <td colspan='2'>
1147                                                <div class='infopop'>
1148                                                        <a onclick=\"javascript:Effect.toggle('info6','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1149                                                        <div id='info6' style='display: none;'>
1150                                                        <div>
1151                                                                If set to yes, users will be able to comment on announcements. (Per group permission are also be applied).
1152                                                        </div>
1153                                                        </div>
1154                                                </div>
1155                                        </td>
1156                                </tr>
1157                                <tr>
1158                                        <td class='option2'>Enable KB Commenting</td>
1159                                        <td class='option2' style='font-weight: normal'>
1160                                                <label for='allow_kb_comment1'><input type='radio' name='set_allow_kb_comment' id='allow_kb_comment1' value='1' class='radio'{$kb_comments_select1} /> Yes</label>&nbsp;&nbsp;<label for='allow_kb_comment0'><input type='radio' name='set_allow_kb_comment' id='allow_kb_comment0' value='0' class='radio'{$kb_comments_select0} /> No</label>
1161                                        </td>
1162                                </tr>
1163                                <tr>
1164                                        <td colspan='2'>
1165                                                <div class='infopop'>
1166                                                        <a onclick=\"javascript:Effect.toggle('info7','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1167                                                        <div id='info7' style='display: none;'>
1168                                                        <div>
1169                                                                If set to yes, users will be able to comment on knowledge base articles. (Per group permission are also be applied).
1170                                                        </div>
1171                                                        </div>
1172                                                </div>
1173                                        </td>
1174                                </tr>
1175                                <tr>
1176                                        <td class='option1'>Enable KB Rating</td>
1177                                        <td class='option1' style='font-weight: normal'>
1178                                                <label for='allow_kb_rating1'><input type='radio' name='set_allow_kb_rating' id='allow_kb_rating1' value='1' class='radio'{$kb_rating_select1} /> Yes</label>&nbsp;&nbsp;<label for='allow_kb_rating0'><input type='radio' name='set_allow_kb_rating' id='allow_kb_rating0' value='0' class='radio'{$kb_rating_select0} /> No</label>
1179                                        </td>
1180                                </tr>
1181                                <tr>
1182                                        <td colspan='2'>
1183                                                <div class='infopop'>
1184                                                        <a onclick=\"javascript:Effect.toggle('info8','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1185                                                        <div id='info8' style='display: none;'>
1186                                                        <div>
1187                                                                If set to yes, users will be able to rate knowledge base articles. (Per group permission are also be applied).
1188                                                        </div>
1189                                                        </div>
1190                                                </div>
1191                                        </td>
1192                                </tr>
1193                                <tr>
1194                                        <td class='option2'>Enable Staff Reply Rating</td>
1195                                        <td class='option2' style='font-weight: normal'>
1196                                                <label for='allow_reply_rating1'><input type='radio' name='set_allow_reply_rating' id='allow_reply_rating1' value='1' class='radio'{$ticket_rating_select1} /> Yes</label>&nbsp;&nbsp;<label for='allow_reply_rating0'><input type='radio' name='set_allow_reply_rating' id='allow_reply_rating0' value='0' class='radio'{$ticket_rating_select0} /> No</label>
1197                                        </td>
1198                                </tr>
1199                                <tr>
1200                                        <td colspan='2'>
1201                                                <div class='infopop'>
1202                                                        <a onclick=\"javascript:Effect.toggle('info9','blind',{duration: 0.5});\" class='fake_link'><img src='../images/default/toggle.gif' alt='+' /> Toggle information</a>
1203                                                        <div id='info9' style='display: none;'>
1204                                                        <div>
1205                                                                If set to yes, users will be able to rate staff replies to tickets as a positive (helpful) or negative (not-so-helpful) response.
1206                                                        </div>
1207                                                        </div>
1208                                                </div>
1209                                        </td>
1210                                </tr>
1211                                </table>
1212                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Continue' class='button' /></div>
1213                                </form>";
1214
1215        do_output( $content, 5 );
1216}
1217
1218function step_6($error='')
1219{
1220        global $core, $input;
1221
1222        if ( $input['submit'] && ! $error )
1223        {
1224                if ( ! $input['set_hd_name'] )
1225                {
1226                        step_5('Please enter a help desk name.');
1227                }
1228
1229                if ( ! validate_email( $input['set_out_email'] ) )
1230                {
1231                        step_5('Please enter a valid outgoing email address.');
1232                }
1233
1234                $to_cache = array(
1235                                                  'set_set'                                     => 1,
1236                                                  'set_hd_name'                         => $input['set_hd_name'],
1237                                                  'set_out_email'                       => $input['set_out_email'],
1238                                                  'set_email_val'                       => $input['set_email_val'],
1239                                                  'set_admin_val'                       => $input['set_admin_val'],
1240                                                  'set_tickets_suggest'         => $input['set_tickets_suggest'],
1241                                                  'set_news_comments'           => $input['set_news_comments'],
1242                                                  'set_allow_kb_comment'        => $input['set_allow_kb_comment'],
1243                                                  'set_allow_kb_rating'         => $input['set_allow_kb_rating'],
1244                                                  'set_allow_reply_rating'      => $input['set_allow_reply_rating'],
1245                                                  );
1246
1247                $core->add( 'install', $to_cache );
1248        }
1249
1250        $content = "";
1251
1252        if ( $error ) $content .= "<div class='critical'>{$error}</div>";
1253
1254        if ( is_dir( HD_PATH .'skin/s1' ) || is_dir( HD_PATH .'skin/s2' ) )
1255        {
1256                $content .= "<div class='critical'>We have detected existing skin files in the <i>skin</i> directory.  By continuing, these will files will be overwritten with default templates and CSS.</div>";
1257        }
1258
1259        $content .= "<form action='index.php?step=7' method='post'>
1260                                <div class='groupbox'>Install Skin Sets</div>
1261                                <div class='option1'>The Trellis Desk Install Center will now install your skin sets by writing the skin templates and CSS to the <i>skin</i> directory.  Please click Continue below.</div>
1262                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Continue' class='button' /></div>
1263                                </form>";
1264
1265        do_output( $content, 6 );
1266}
1267
1268function step_7($error='')
1269{
1270        global $core, $input;
1271
1272        if ( $input['submit'] && ! $error )
1273        {
1274                /*$parser = new td_parser();
1275
1276                $skins = array( 1 => 'skin_trellis_desk_default_td.xml', 2 => 'skin_trellis_desk_classic_td.xml' );
1277
1278                while ( list( $skin_id, $skin_file ) = each( $skins ) )
1279                {
1280                        $data = $parser->parseFile( './'. $skin_file );
1281                        $sinfo = $data[0];
1282                        $templates = $data[1];
1283
1284                        if ( ! is_dir( HD_PATH .'skin/s'. $skin_id ) && ! @ mkdir( HD_PATH .'skin/s'. $skin_id ) )
1285                        {
1286                                step_6('We could not create the directory <i>skin/s'. $skin_id .'</i>.  Please CHMOD <i>skin</i> to 0777.');
1287                        }
1288
1289                        while ( list( , $tinfo ) = each( $templates ) )
1290                        {
1291                                if( $handlet = @fopen( HD_PATH .'skin/s'. $skin_id .'/'. $tinfo['tname'], 'w' ) )
1292                                {
1293                                        if ( ! @fwrite( $handlet, $tinfo['tcontent'] ) )
1294                                        {
1295                                                step_6('We could not write to the file <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i>.  Please CHMOD <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i> to 0777.');
1296                                        }
1297
1298                                        @fclose($handlet);
1299                                }
1300                                else
1301                                {
1302                                        step_6('We could not create the file <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i>.  Please CHMOD <i>skin/s'. $skin_id .'</i> to 0777.');
1303                                }
1304                        }
1305
1306                        if( $handle = @fopen( HD_PATH .'skin/s'. $skin_id .'/style.css', 'w' ) )
1307                        {
1308                                if ( ! @fwrite( $handle, $sinfo['sk_css'] ) )
1309                                {
1310                                        step_6('We could not write to the file <i>skin/s'. $skin_id .'/style.css</i>.  Please CHMOD <i>skin/s'. $skin_id .'/style.css</i> to 0777.');
1311                                }
1312
1313                                @fclose($handle);
1314                        }
1315                        else
1316                        {
1317                                step_6('We could not create the file <i>skin/s'. $skin_id .'/style.css</i>.  Please CHMOD <i>skin/s'. $skin_id .'</i> to 0777.');
1318                        }
1319                }*/
1320
1321                $core->add( 'install', array( 'skin_set' => 1 ) );
1322        }
1323
1324        $content = "";
1325
1326        if ( $error ) $content .= "<div class='critical'>{$error}</div>";
1327
1328        if ( $core->cache->data['install']['sql_exists'] ) $content .= "<div class='critical'>We have detected that an installation of Trellis Desk already exists.  By completing this installation, you will overwrite your all your data and start over fresh.</div>";
1329
1330        $content .= "<form action='index.php?step=8' method='post'>
1331                                <div class='groupbox'>Write Installation Data</div>
1332                                <div class='option1'>The Trellis Desk Install Center has finished gathering the required information to install Trellis Desk.  To complete the installation, click the Complete Installation button below.  Trellis Desk will install its database structure and write to the configuration file.  After you complete this step, you will be presented with a security check report.</div>
1333                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Complete Installation' class='button' /></div>
1334                                </form>";
1335
1336        do_output( $content, 7 );
1337}
1338
1339function step_8()
1340{
1341        global $core, $input;
1342
1343        $installed = 0;
1344
1345        if ( $input['submit'] )
1346        {
1347                if ( $input['adv'] )
1348                {
1349                        if ( ! $input['admin_user'] )
1350                        {
1351                                step_a('Please enter a username.');
1352                        }
1353
1354                        if ( $input['admin_pass'] != $input['admin_pass_b'] )
1355                        {
1356                                step_a('Your admin passwords do not match.');
1357                        }
1358
1359                        if ( ! validate_email( $input['admin_email'] ) )
1360                        {
1361                                step_a('Please enter a valid email address.');
1362                        }
1363
1364                        if ( $input['sql_pass'] != $input['sql_pass_b'] )
1365                        {
1366                                step_a('Your MySQL passwords do not match.');
1367                        }
1368
1369                        /*$parser = new td_parser();
1370
1371                        $skins = array( 1 => 'skin_trellis_desk_default_td.xml', 2 => 'skin_trellis_desk_classic_td.xml' );
1372
1373                        while ( list( $skin_id, $skin_file ) = each( $skins ) )
1374                        {
1375                                $data = $parser->parseFile( './'. $skin_file );
1376                                $sinfo = $data[0];
1377                                $templates = $data[1];
1378
1379                                if ( ! is_dir( HD_PATH .'skin/s'. $skin_id ) && ! @ mkdir( HD_PATH .'skin/s'. $skin_id ) )
1380                                {
1381                                        step_a('We could not create the directory <i>skin/s'. $skin_id .'</i>.  Please CHMOD <i>skin</i> to 0777.');
1382                                }
1383
1384                                while ( list( , $tinfo ) = each( $templates ) )
1385                                {
1386                                        if( $handlet = @fopen( HD_PATH .'skin/s'. $skin_id .'/'. $tinfo['tname'], 'w' ) )
1387                                        {
1388                                                if ( ! @fwrite( $handlet, $tinfo['tcontent'] ) )
1389                                                {
1390                                                        step_a('We could not write to the file <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i>.  Please CHMOD <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i> to 0777.');
1391                                                }
1392
1393                                                @fclose($handlet);
1394                                        }
1395                                        else
1396                                        {
1397                                                step_a('We could not create the file <i>skin/s'. $skin_id .'/'. $tinfo['tname'] .'</i>.  Please CHMOD <i>skin/s'. $skin_id .'</i> to 0777.');
1398                                        }
1399                                }
1400
1401                                if( $handle = @fopen( HD_PATH .'skin/s'. $skin_id .'/style.css', 'w' ) )
1402                                {
1403                                        if ( ! @fwrite( $handle, $sinfo['sk_css'] ) )
1404                                        {
1405                                                step_a('We could not write to the file <i>skin/s'. $skin_id .'/style.css</i>.  Please CHMOD <i>skin/s'. $skin_id .'/style.css</i> to 0777.');
1406                                        }
1407
1408                                        @fclose($handle);
1409                                }
1410                                else
1411                                {
1412                                        step_a('We could not create the file <i>skin/s'. $skin_id .'/style.css</i>.  Please CHMOD <i>skin/s'. $skin_id .'</i> to 0777.');
1413                                }
1414                        }*/
1415
1416                require HD_PATH .'config.php';
1417
1418                $pwsalt = '';
1419                $lksalt = '';
1420                $rksalt = '';
1421
1422                while( strlen( $pwsalt ) < 16 ) $pwsalt .= chr( rand( 32, 126 ) );
1423                while( strlen( $lksalt ) < 8 ) $lksalt .= chr( rand( 32, 126 ) );
1424                while( strlen( $rksalt ) < 8 ) $rksalt .= chr( rand( 32, 126 ) );
1425
1426                $lksalt .= uniqid( rand(), true );
1427                $rksalt .= uniqid( rand(), true );
1428
1429                $pwhash = hash( 'whirlpool', $pwsalt . $input['admin_pass'] . $config['pass_key'] );
1430                $lkhash = str_replace( "=", "", base64_encode( strrev( hash( 'whirlpool', $lksalt . $config['cookie_key'] ) ) ) );
1431                $rkhash = md5( $rksalt . $config['rss_key'] );
1432
1433                        $new_cache = array(
1434                                                                'sql_host'                                      => $_POST['sql_host'],
1435                                                                'sql_user'                                      => $_POST['sql_user'],
1436                                                                'sql_pass'                                      => $_POST['sql_pass'],
1437                                                                'sql_db'                                        => $_POST['sql_db'],
1438                                                                'sql_prefix'                            => $_POST['sql_prefix'],
1439                                                                'admin_user'                            => $input['admin_user'],
1440                                                                'admin_pass_hash'                       => $pwhash,
1441                                                                'admin_pass_salt'                       => $pwsalt,
1442                                                                'admin_login_key'                       => $lkhash,
1443                                                                'admin_email'                           => $input['admin_email'],
1444                                                                'admin_time_zone'                       => 0,
1445                                                                'admin_dst_active'                      => 0,
1446                                                                'admin_rte_enable'                      => 1,
1447                                                                'admin_email_ticket'            => 1,
1448                                                                'admin_email_reply'                     => 1,
1449                                                                'admin_rss_key'                         => $rkhash,
1450                                                                'set_hd_name'                           => 'Trellis Desk',
1451                                                                'set_out_email'                         => $input['admin_email'],
1452                                                                'set_email_val'                         => 1,
1453                                                                'set_admin_val'                         => 0,
1454                                                                'set_tickets_suggest'           => 1,
1455                                                                'set_news_comments'                     => 1,
1456                                                                'set_allow_kb_comment'          => 1,
1457                                                                'set_allow_kb_rating'           => 1,
1458                                                                'set_allow_reply_rating'        => 1,
1459                                        'pass_key'                              => $config['pass_key'],
1460                                        'cookie_key'                        => $config['cookie_key'],
1461                                        'session_key'                       => $config['session_key'],
1462                                        'rss_key'                               => $config['rss_key'],
1463                                                                );
1464
1465                        $core->cache->data['install'] = array_merge( $new_cache, $core->cache->data['install'] );
1466
1467                        $error_fun = 'step_a';
1468                }
1469                else
1470                {
1471                        $error_fun = 'step_7';
1472                }
1473
1474                if ( ! $handle = @fopen( HD_PATH .'config.php', 'w' ) )
1475                {
1476                        $error_fun('We could not write to the configuration file.  Please make sure that <i>config.php</i> is CHMODed to 0777.');
1477                }
1478
1479                $url = str_replace( "/install/index.php", "", $_SERVER['HTTP_REFERER'] );
1480                $url = str_replace( "/install/", "", $url );
1481                $url = str_replace( "/install", "", $url );
1482                $url = str_replace( "index.php", "", $url );
1483                $url = substr( $url, 0, strpos( $url, '?' ) );
1484                $url = str_replace( "?", "", $url );
1485
1486                $path = str_replace( "/install/index.php", "", $_SERVER['SCRIPT_FILENAME'] );
1487                $path = str_replace( "/install/", "", $path );
1488                $path = str_replace( "/install", "", $path );
1489                $path = str_replace( "index.php", "", $path );
1490
1491                $dir = dirname( dirname( __FILE__ ) );
1492                $position = strrpos( $path, '/' ) + 1;
1493                $cookie_path = substr($path, $position);
1494
1495                $upload_path = $path ."/uploads";
1496                $upload_url = $url ."/uploads";
1497
1498                $file_data = "<?php\n\n";
1499
1500                $file_data .= "\$config['driver'] = 'mysql';\n";
1501                $file_data .= "\$config['host'] = '". $core->cache->data['install']['sql_host'] ."';\n";
1502                $file_data .= "\$config['user'] = '". $core->cache->data['install']['sql_user'] ."';\n";
1503                $file_data .= "\$config['pass'] = '". $core->cache->data['install']['sql_pass'] ."';\n";
1504                $file_data .= "\$config['name'] = '". $core->cache->data['install']['sql_db'] ."';\n";
1505                $file_data .= "\$config['prefix'] = '". $core->cache->data['install']['sql_prefix'] ."';\n\n";
1506                $file_data .= "\$config['pass_key'] = '". $core->cache->data['install']['pass_key'] ."';\n";
1507                $file_data .= "\$config['cookie_key'] = '". $core->cache->data['install']['cookie_key'] ."';\n";
1508                $file_data .= "\$config['session_key'] = '". $core->cache->data['install']['session_key'] ."';\n";
1509                $file_data .= "\$config['rss_key'] = '". $core->cache->data['install']['rss_key'] ."';\n\n";
1510                $file_data .= "\$config['hd_url'] = '". $url ."';\n";
1511                $file_data .= "\$config['fallback_lang'] = 'en';\n";
1512                $file_data .= "\$config['fallback_skin'] = 1;\n";
1513                $file_data .= "\$config['acp_session_timeout'] = 3;\n\n";
1514                $file_data .= "\$config['start'] = '". time() ."';\n\n";
1515
1516                $file_data .= "?>";
1517
1518                if ( ! @fwrite( $handle, $file_data ) )
1519                {
1520                        $error_fun('We could not write to the configuration file.  Please make sure that <i>config.php</i> is CHMODed to 0777.');
1521                }
1522
1523                @fclose($handle);
1524
1525                if ( ! @mysql_connect( $core->cache->data['install']['sql_host'], $core->cache->data['install']['sql_user'], $core->cache->data['install']['sql_pass'] ) )
1526                {
1527                        $error_fun('We could not connect to the MySQL Server.  Please check that your MySQL credentails are correct and try again.');
1528                }
1529
1530                if ( ! @mysql_select_db( $core->cache->data['install']['sql_db'] ) )
1531                {
1532                        $error_fun('We could not connect to the MySQL Database.  Please check that your MySQL credentails are correct and try again.');
1533                }
1534
1535                require_once "./sql_queries.php";
1536
1537                while ( list( , $sql_query ) = each( $SQL ) )
1538                {
1539                        if ( ! @mysql_query($sql_query) )
1540                        {
1541                                $error_fun('An error encountered while trying to run the following SQL Query.<br /><br />'. $sql_query .'<br /><br />MySQL returned the following error.<br /><br />'. mysql_error() .'<br /><br />'. mysql_errno() );
1542                        }
1543                }
1544
1545                /*$new_session = md5( time() . '1' . uniqid( rand(), true ) );
1546
1547                mysql_query( "INSERT INTO ". $core->cache->data['install']['sql_prefix'] ."sessions SET s_id = '". $new_session ."', s_uid = 1, s_uname = '". $core->cache->data['install']['admin_user'] ."', s_ipadd = '". $input['ip_address'] ."', s_time = ". time() );
1548
1549                setcookie( 'hdsid', $new_session, time() + ( 20 * 60 ), '/'. $cookie_path .'/' );
1550
1551                setcookie( 'hduid', 1, time() + ( 60 * 60 * 24 * 365 ), '/'. $cookie_path .'/' );
1552                setcookie( 'hdphash', $core->cache->data['install']['admin_login_key'], time() + ( 60 * 60 * 24 * 365 ), '/'. $cookie_path .'/' );*/
1553
1554                require_once "../includes/trellis.php";
1555                $trellis = new trellis(1);
1556
1557                # is this still necessary ?
1558                $trellis->cache->data['settings']['news']['rte'] = 1;
1559                $trellis->cache->data['settings']['news']['portal_amount'] = 3;
1560
1561                $trellis->load_functions( 'rebuild' );
1562
1563                $trellis->rebuild->settings_cache();
1564                $trellis->rebuild->departs_cache();
1565                $trellis->rebuild->categories_cache();
1566                $trellis->rebuild->groups_cache();
1567                $trellis->rebuild->news_cache(3);
1568                $trellis->rebuild->langs_cache();
1569                $trellis->rebuild->skins_cache();
1570                $trellis->rebuild->pfields_cache();
1571                $trellis->rebuild->dfields_cache();
1572                $trellis->rebuild->rtemplates_cache();
1573                $trellis->rebuild->priorities_cache();
1574                $trellis->rebuild->flags_cache();
1575                $trellis->rebuild->staff_cache();
1576                $trellis->rebuild->statuses_cache();
1577
1578                $installed = 1;
1579
1580                /*$to_cache = array( 'clear_time' => time() );
1581
1582                $trellis->core->add( 'install', $to_cache, 1 );*/
1583
1584                $trellis->core->shut_down_q();
1585                $trellis->core->shut_down();
1586
1587                $content .= "<div class='alert'>Congratulations!  Your Trellis Desk installation is now complete.  <a href='". $url ."/admin.php' target='_blank'>Click here</a> to go to your new help desk administrative control panel.</div>";
1588
1589                if ( $l_handle = @fopen( './install.lock', 'w' ) )
1590                {
1591                        @fwrite( $l_handle, time() );
1592
1593                        @fclose($l_handle);
1594                }
1595        }
1596        elseif ( $input['clear'] )
1597        {
1598                if ( is_writable( HD_PATH .'core/cache/'. base64_encode( 'install' ) .'.A5' ) )
1599                {
1600                        $to_cache = array( 'clear_time' => time() );
1601
1602                        $core->add( 'install', $to_cache, 1 );
1603
1604                        $core->shut_down();
1605                }
1606        }
1607
1608        $success = "<span style='color:#49701B'>Success</span>";
1609        $warning = "<span style='color:#D85C08'>Warning</span>";
1610        $failed = "<span style='color:#AC241A'>Failed</span>";
1611        $info_warning = "style='padding-top:8px;font-size:12px;'";
1612        $info_failed = "style='padding-top:8px;font-size:12px;color:#AC241A'";
1613
1614        $content .= "<form action='index.php?step=8' method='post'><div class='groupbox'>Protect Your Installation</div>
1615                                <table width='100%' cellpadding='0' cellspacing='0'>
1616                                <tr>
1617                                        <td class='option1' width='80%'>Installation Data</td>
1618                                        <td class='option1' width='20%' align='right'>";
1619
1620
1621        $install_data = 0;
1622
1623        if ( file_exists( HD_PATH .'core/cache/'. base64_encode( 'install' ) .'.A5' ) )
1624        {
1625                $raw_data = file_get_contents( HD_PATH .'core/cache/'. base64_encode( 'install' ) .'.A5' );
1626
1627                $install_cache = unserialize( base64_decode( $raw_data ) );
1628
1629                if ( $install_cache['sql_user'] || $install_cache['sql_pass'] || $install_cache['sql_db'] || $install_cache['admin_pass_hash'] )
1630                {
1631                        $content .= $failed ."</td>
1632                                        </tr>
1633                                        <tr>
1634                                                <td class='infopop' colspan='2' {$info_failed}>Your installation data is still in Trellis Desk's cache!  This means someone could steal information such as your SQL and admin passwords.  Please click the Clear Installation Data button below.  The Install Center will attempt to clear this data for you.  If this does not work, please delete the <b><i>core/cache/". base64_encode( 'install' ) .".A5</i></b> file immediately.</td>
1635                                        </tr>";
1636
1637                        $install_data = 1;
1638                }
1639                else
1640                {
1641                        $content .= $success ."</td>
1642                                        </tr>";
1643                }
1644        }
1645        else
1646        {
1647                $content .= $success ."</td>
1648                                </tr>";
1649        }
1650
1651        $content .= "<tr>
1652                                        <td class='option2'>Configuration File</td>
1653                                        <td class='option2' align='right'>";
1654
1655        if( is_writable( HD_PATH .'config.php' ) )
1656        {
1657                @chmod( HD_PATH .'config.php', 0644 );
1658        }
1659
1660        if( is_writable( HD_PATH .'config.php' ) )
1661        {
1662                $content .= $warning ."</td>
1663                                </tr>
1664                                <tr>
1665                                        <td class='infopop' colspan='2' {$info_warning}>Your configuration file is still writeable.  We recommend that you CHMOD <i>config.php</i> to 0644 for added security.</td>
1666                                </tr>";
1667        }
1668        else
1669        {
1670                $content .= $success ."</td>
1671                                </tr>";
1672        }
1673
1674        $content .= "<tr>
1675                                        <td class='option1'>Install Folder</td>
1676                                        <td class='option1' align='right'>";
1677
1678        if( is_dir( HD_PATH .'install/' ) )
1679        {
1680                $content .= $warning ."</td>
1681                                </tr>
1682                                <tr>
1683                                        <td class='infopop' colspan='2' {$info_warning}>Your <i>install</i> directory still exists.  We recommend renaming or deleting this <i>install</i> directory for added security.</td>
1684                                </tr>";
1685        }
1686        else
1687        {
1688                $content .= $success ."</td>
1689                                </tr>";
1690        }
1691
1692        $content .= "</table>";
1693
1694        if ( $install_data )
1695        {
1696                if ( $installed )
1697                {
1698                        $content .= "<div class='option2'>Your Trellis Desk installation is complete.  However, your installation data still exists in cache.  It is recommended that you click Clear Installation Data below to remove any private installation data.</div>";
1699                }
1700
1701                $content .= "<div class='formtail'><input type='submit' name='clear' id='clear_button' value='Clear Installation Data' class='button' /></div>";
1702        }
1703        elseif ( $installed )
1704        {
1705                $content .= "<div class='formtail'><div class='fb_pad'><a href='". $url ."' class='fake_button'>Go To Help Desk</a></div></div>";
1706        }
1707
1708        $content .= "</form>";
1709
1710        do_output( $content, 8 );
1711}
1712
1713function step_a($error='')
1714{
1715        global $core, $input;
1716
1717        $content = "";
1718
1719        if ( $error )
1720        {
1721                $content .= "<div class='critical'>{$error}</div>";
1722        }
1723        else
1724        {
1725                if ( ! $_POST['sql_host'] ) $_POST['sql_host'] = 'localhost';
1726                if ( ! $_POST['sql_prefix'] ) $_POST['sql_prefix'] = 'td_';
1727        }
1728
1729        $content .= "<form action='index.php?step=8' method='post'>
1730                                <input type='hidden' name='adv' value='1' />
1731                                <div class='groupbox'>Configuration</div>
1732                                <table width='100%' cellpadding='0' cellspacing='0'>
1733                                <tr>
1734                                        <td class='option1' width='25%'>MySQL Host</td>
1735                                        <td class='option1' width='75%'><input type='text' name='sql_host' id='sql_host' value='{$_POST['sql_host']}' size='40' /></td>
1736                                </tr>
1737                                <tr>
1738                                        <td class='option2'>MySQL Username</td>
1739                                        <td class='option2'><input type='text' name='sql_user' id='sql_user' value='{$_POST['sql_user']}' size='40' /></td>
1740                                </tr>
1741                                <tr>
1742                                        <td class='option1'>MySQL Password</td>
1743                                        <td class='option1'><input type='password' name='sql_pass' id='sql_pass' value='' size='40' /></td>
1744                                </tr>
1745                                <tr>
1746                                        <td class='option2'>Password Confirm</td>
1747                                        <td class='option2'><input type='password' name='sql_pass_b' id='sql_pass_b' value='' size='40' /></td>
1748                                </tr>
1749                                <tr>
1750                                        <td class='option1'>MySQL Database</td>
1751                                        <td class='option1'><input type='text' name='sql_db' id='sql_db' value='{$_POST['sql_db']}' size='40' /></td>
1752                                </tr>
1753                                <tr>
1754                                        <td class='option2'>MySQL Table Prefix</td>
1755                                        <td class='option2'><input type='text' name='sql_prefix' id='sql_prefix' value='{$_POST['sql_prefix']}' size='4' /></td>
1756                                </tr>
1757                                </table><br />
1758
1759                                <div class='groupbox'>Admin Account</div>
1760                                <table width='100%' cellpadding='0' cellspacing='0'>
1761                                <tr>
1762                                        <td class='option1' width='25%'>Username</td>
1763                                        <td class='option1' width='75%'><input type='text' name='admin_user' id='admin_user' value='{$input['admin_user']}' size='40' /></td>
1764                                </tr>
1765                                <tr>
1766                                        <td class='option2'>Password</td>
1767                                        <td class='option2'><input type='password' name='admin_pass' id='admin_pass' value='' size='40' /></td>
1768                                </tr>
1769                                <tr>
1770                                        <td class='option1'>Confirm Password</td>
1771                                        <td class='option1'><input type='password' name='admin_pass_b' id='admin_pass_b' value='' size='40' /></td>
1772                                </tr>
1773                                <tr>
1774                                        <td class='option2'>Email Address</td>
1775                                        <td class='option2'><input type='text' name='admin_email' id='admin_email' value='{$input['admin_email']}' size='40' /></td>
1776                                </tr>
1777                                </table>
1778                                <div class='formtail'><input type='submit' name='submit' id='continue_button' value='Complete Installation' class='button' /></div>
1779                                </form>";
1780
1781        do_output( $content, 'a' );
1782}
1783
1784function do_output($content, $step=0)
1785{
1786        global $core, $input;
1787
1788        $wrapper = <<<EOF
1789<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1790<html xmlns="http://www.w3.org/1999/xhtml">
1791<head>
1792        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
1793        <title>Trellis Desk :: Install Center</title>
1794        <style type="text/css" media="all">
1795                @import "../includes/global.css";
1796                @import "../includes/local.css";
1797        </style>
1798        <script src='../includes/scripts/common.js' type='text/javascript'></script>
1799        <script src='../includes/scripts/prototype.js' type='text/javascript'></script>
1800        <script src='../includes/scripts/scriptaculous.js' type='text/javascript'></script>
1801</head>
1802<body>
1803<div id="acpwrap">
1804
1805        <!-- GLOBAL: Header block -->
1806        <div id="header">
1807        <div class="lefty">
1808        <img src="../images/default/install_logo.jpg" alt="Trellis Desk Install Center" width="264" height="56" />
1809        </div>
1810    </div>
1811
1812    <!-- GLOBAL: Navigation bar -->
1813    <div id="navbar">
1814        <div class="righty">
1815        </div>
1816        <div class="lefty">
1817                </div>
1818        <ul>
1819                <li class="current"><a href="index.php">Install Center</a></li>
1820                <li><a href="http://docs.accord5.com/trellis/install" target="_blank">Getting Started</a></li>
1821                <li><a href="http://docs.accord5.com/trellis" target="_blank">Documentation</a></li>
1822                <li><a href="../upgrade/">Upgrade Center</a></li>
1823                <li><a href="http://customer.accord5.com/trellis" target="_blank">Help &amp; Support</a></li>
1824        </ul>
1825    </div>
1826
1827    <!-- GLOBAL: Content block -->
1828    <div id="content">
1829        <div id="acpblock">
1830
1831                <!-- GLOBAL: Page ID -->
1832            <p class="pageid">Install Center</p>
1833
1834            <!-- GLOBAL: Info bar -->
1835            <div id="infobar">Your first step into setting up a powerful, robust help desk solution for your business.</div>
1836
1837            <!-- GLOBAL: ACP inner container -->
1838            <!-- This is where the action happens! -->
1839            <div id="acpinner">
1840
1841                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
1842                        <tr>
1843                                <td width="22%" valign="top">
1844
1845                <!-- LEFT SIDE -->
1846                <!-- GLOBAL: ACP page menu -->
1847                                <div id="acpmenu">
1848                    <div class="menucat"><a href='index.php'>Install Trellis Desk</a></div>
1849                        <ul>
1850                        <% STEPS %>
1851                    </ul>
1852                                        <div id="acphelp"><a href="http://docs.accord5.com">View product documentation</a></div>
1853                </div>
1854
1855                                </td>
1856                                <td width="78%" valign="top">
1857
1858                <!-- RIGHT SIDE -->
1859                <!-- GLOBAL: ACP page content -->
1860                <div id="acppage">
1861                        <h1><% TITLE %></h1>
1862                                        <% CONTENT %>
1863                </div>
1864
1865                                </td>
1866                        </tr>
1867                        </table>
1868
1869            </div>
1870            <br class="end" />
1871
1872            <!-- GLOBAL: Copyright bar -->
1873                <div id='powerbar'>
1874                <div class='lefty'>Powered by Trellis Desk <% VERSION %>, &copy; <% YEAR %> <a href='http://www.accord5.com/'>ACCORD5</a></div>
1875            </div>
1876
1877        </div>
1878    </div>
1879    <div id="close">
1880    <div class="righty"></div>
1881    <div class="lefty"></div>
1882    </div>
1883</div>
1884</body>
1885</html>
1886EOF;
1887
1888        $wrapper = str_replace( "<% STEPS %>"   , build_steps_list($step)       , $wrapper );
1889        $wrapper = str_replace( "<% TITLE %>"   , get_page_title($step)         , $wrapper );
1890        $wrapper = str_replace( "<% CONTENT %>" , $content                                      , $wrapper );
1891        $wrapper = str_replace( "<% VERSION %>" , VER_HUM                                       , $wrapper );
1892        $wrapper = str_replace( "<% YEAR %>"    , date('Y')                                     , $wrapper );
1893
1894        header ('Content-type: text/html; charset=utf-8');
1895
1896        print $wrapper;
1897
1898        if ( $step > 1 && ! $input['clear'] )
1899        {
1900                $core->shut_down();
1901        }
1902
1903        exit();
1904}
1905
1906function build_steps_list($step)
1907{
1908        global $input;
1909
1910        $html = "";
1911
1912        $steps = array(
1913                                        0 => 'Introduction',
1914                                        1 => 'System Check',
1915                                        2 => 'Installation Type',
1916                                        3 => 'Database Setup',
1917                                        4 => 'Create Admin Account',
1918                                        5 => 'Configure General Settings',
1919                                        6 => 'Write Skin Files',
1920                                        7 => 'Finish Installation',
1921                                        'a' => 'Advanced Installation',
1922                                        8 => 'Security Check',
1923                                        );
1924
1925        if ( $step === 'a' || $input['adv'] )
1926        {
1927                unset( $steps[6] );
1928        }
1929
1930        while( list( $num, $name ) = each( $steps ) )
1931        {
1932                if ( ( $num === 'a' && ( $step === 'a' || $input['adv'] ) ) || $num !== 'a' )
1933                {
1934                        if ( $step === $num )
1935                        {
1936                                $html .= "<li><a href='index.php?step=". $num ."'><b>". $name ."</b></a></li>";
1937                        }
1938                        else
1939                        {
1940                                $html .= "<li><a href='index.php?step=". $num ."'>". $name ."</a></li>";
1941                        }
1942                }
1943        }
1944
1945        return $html;
1946}
1947
1948function get_page_title($step)
1949{
1950        $titles = array(
1951                                        0 => 'Welcome to Trellis Desk',
1952                                        1 => 'System Check',
1953                                        2 => 'Installation Type',
1954                                        3 => 'Database Setup',
1955                                        4 => 'Create Admin Account',
1956                                        5 => 'Configure General Settings',
1957                                        6 => 'Write Skin Files',
1958                                        7 => 'Finish Installation',
1959                                        8 => 'Security Check',
1960                                        'a' => 'Advanced Installation'
1961                                        );
1962
1963        return $titles[ $step ];
1964}
1965
1966function get_post()
1967{
1968        $data = array();
1969
1970        #=============================
1971        # $_GET Data
1972        #=============================
1973
1974        if ( is_array( $_GET ) )
1975        {
1976                while ( list( $n, $v ) = each( $_GET ) )
1977                {
1978                        if ( is_array( $_GET[$n] ) )
1979                        {
1980                                while ( list( $n2, $v2 ) = each( $_GET[$n] ) )
1981                                {
1982                                          $data[ sanitize_data($n)][ sanitize_data($n2) ] = sanitize_data($v2);
1983                                }
1984                        }
1985                        else
1986                        {
1987                                $data[ sanitize_data($n) ] = sanitize_data($v);
1988                        }
1989                }
1990        }
1991
1992        #=============================
1993        # $_POST Data
1994        #=============================
1995
1996        if ( is_array( $_POST ) )
1997        {
1998                while ( list( $n, $v ) = each( $_POST ) )
1999                {
2000                        if ( is_array( $_POST[$n] ) )
2001                        {
2002                                while ( list( $n2, $v2 ) = each( $_POST[$n] ) )
2003                                {
2004                                          $data[ sanitize_data($n) ][ sanitize_data($n2) ] = sanitize_data($v2);
2005                                }
2006                        }
2007                        else
2008                        {
2009                                $data[ sanitize_data($n) ] = sanitize_data($v);
2010                        }
2011                }
2012        }
2013
2014        #=============================
2015        # Other Junk
2016        #=============================
2017
2018        $data['ip_address'] = sanitize_data( $_SERVER['REMOTE_ADDR'] );
2019
2020        return $data;
2021}
2022
2023function sanitize_data($data, $noquotes=0)
2024{
2025        if ( $data == "" )
2026        {
2027                return FALSE;
2028        }
2029
2030        if ( $noquotes )
2031        {
2032                if ( get_magic_quotes_gpc() )
2033                {
2034                $data = trim( htmlentities( $data, ENT_COMPAT, 'UTF-8' ) );
2035                }
2036                else
2037                {
2038                        $data = trim( htmlentities( addslashes( $data ), ENT_COMPAT, 'UTF-8' ) );
2039                }
2040        }
2041        else
2042        {
2043                if ( get_magic_quotes_gpc() )
2044                {
2045                        $data = trim( stripslashes( htmlentities( $data, ENT_QUOTES, 'UTF-8' ) ) );
2046                }
2047                else
2048                {
2049                $data = trim( htmlentities( $data, ENT_QUOTES, 'UTF-8' ) );
2050                }
2051        }
2052
2053        // Other :)
2054        $data = str_replace( "(", '&#40;', $data );
2055        $data = str_replace( ")", '&#41;', $data );
2056
2057        // Unicode
2058        $data = preg_replace( "/&amp;#([0-9]+);/s", "&#\\1;", $data );
2059
2060        return $data;
2061}
2062
2063function return_bytes($val)
2064{
2065        $val = trim($val);
2066    $last = strtolower($val{strlen($val)-1});
2067    switch($last)
2068        {
2069        case 'g':
2070            $val *= 1024;
2071        case 'm':
2072            $val *= 1024;
2073        case 'k':
2074            $val *= 1024;
2075    }
2076
2077    return $val;
2078}
2079
2080function format_size($bytes)
2081{
2082        if ( $bytes < 1024 )
2083        {
2084                return $bytes .' bytes';
2085        }
2086
2087        $kb = $bytes / 1024;
2088
2089        if ( $kb < 1024 )
2090        {
2091                return round( $kb, 2 ) .' KB';
2092        }
2093
2094        $mb = $kb / 1024;
2095
2096        if ( $mb < 1024 )
2097        {
2098                return round( $mb, 2 ) .' MB';
2099        }
2100}
2101
2102function build_time_zone_drop($select=0)
2103{
2104        $zone[-12] = 'GMT - 12:00 Hours';
2105        $zone[-11] = 'GMT - 11:00 Hours';
2106        $zone[-10] = 'GMT - 10:00 Hours';
2107        $zone[-9] = 'GMT - 9:00 Hours';
2108        $zone[-8] = 'GMT - 8:00 Hours';
2109        $zone[-7] = 'GMT - 7:00 Hours';
2110        $zone[-6] = 'GMT - 6:00 Hours';
2111        $zone[-5] = 'GMT - 5:00 Hours';
2112        $zone[-4] = 'GMT - 4:00 Hours';
2113        $zone[-3.5] = 'GMT - 3:30 Hours';
2114        $zone[-3] = 'GMT - 3:00 Hours';
2115        $zone[-2] = 'GMT - 2:00 Hours';
2116        $zone[-1] = 'GMT - 1:00 Hours';
2117        $zone[0] = 'GMT';
2118        $zone[1] = 'GMT + 1:00 Hours';
2119        $zone[2] = 'GMT + 2:00 Hours';
2120        $zone[3] = 'GMT + 3:00 Hours';
2121        $zone[3.5] = 'GMT + 3:30 Hours';
2122        $zone[4] = 'GMT + 4:00 Hours';
2123        $zone[4.5] = 'GMT + 4:30 Hours';
2124        $zone[5] = 'GMT + 5:00 Hours';
2125        $zone[5.5] = 'GMT + 5:30 Hours';
2126        $zone[6] = 'GMT + 6:00 Hours';
2127        $zone[7] = 'GMT + 7:00 Hours';
2128        $zone[8] = 'GMT + 8:00 Hours';
2129        $zone[9] = 'GMT + 9:00 Hours';
2130        $zone[9.5] = 'GMT + 9:30 Hours';
2131        $zone[10] = 'GMT + 10:00 Hours';
2132        $zone[11] = 'GMT + 11:00 Hours';
2133        $zone[12] = 'GMT + 12:00 Hours';
2134
2135        $html = ""; // Initialize for Security
2136
2137        while ( list( $id, $value ) = each( $zone ) )
2138        {
2139                if ( $id == $select )
2140                {
2141                        $html .= "<option value='". $id ."' selected='selected'>{$value}</option>";
2142                }
2143                else
2144                {
2145                        $html .= "<option value='". $id ."'>{$value}</option>";
2146                }
2147        }
2148
2149        return $html;
2150}
2151
2152function validate_email($email)
2153{
2154        if( ereg( "^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])*$", $email ) )
2155        {
2156                return $email;
2157        }
2158        else
2159        {
2160                return FALSE;
2161        }
2162}
2163
2164class td_parser {
2165
2166        function startElement($parser, $name, $attr)
2167        {
2168                $this->xml_current_element = $name;
2169
2170                $my_var = 'xml_'. $name;
2171                $this->$my_var = "";
2172        }
2173
2174        function endElement($parser, $name)
2175        {
2176                $elements = array( 'tname', 'tcontent' );
2177                $elementsb = array( 'sk_name', 'sk_img_dir', 'sk_author', 'sk_author_email', 'sk_author_web', 'sk_notes', 'sk_css' );
2178
2179                if( strcmp( $name, "template" ) == 0 )
2180                {
2181                        while ( list( , $element ) = each( $elements ) )
2182                        {
2183                                $my_var = 'xml_'. $element;
2184                                $temp[ $element ] = base64_decode( preg_replace( "/\s/", "", $this->$my_var ) );
2185                        }
2186
2187                        $this->xml_templates[] = $temp;
2188
2189                        $this->xml_tname = "";
2190                        $this->xml_tcontent = "";
2191                }
2192
2193                if( strcmp( $name, "skin_info" ) == 0 )
2194                {
2195                        while ( list( , $element ) = each( $elementsb ) )
2196                        {
2197                                $my_var = 'xml_'. $element;
2198                                $this->xml_skin_info[ $element ] = base64_decode( preg_replace( "/\s/", "", $this->$my_var ) );
2199                        }
2200                }
2201        }
2202
2203        function characterData($parser, $data)
2204        {
2205                $elements = array( 'tname', 'tcontent', 'sk_name', 'sk_img_dir', 'sk_author', 'sk_author_email', 'sk_author_web', 'sk_notes', 'sk_css' );
2206
2207                while ( list( , $element ) = each( $elements ) )
2208                {
2209                        if( $this->xml_current_element == $element )
2210                        {
2211                                $my_var = 'xml_'. $element;
2212                                $this->$my_var .= $data;
2213                        }
2214                }
2215        }
2216
2217        function parseFile($xml_file)
2218        {
2219                $xml_parser = xml_parser_create();
2220
2221                xml_set_object( $xml_parser, $this );
2222
2223                xml_set_element_handler($xml_parser, "startElement", "endElement");
2224                xml_set_character_data_handler($xml_parser, "characterData");
2225
2226                xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
2227
2228                if( !( $fp = fopen( $xml_file, "r" ) ) )
2229                {
2230                        die("Cannot open ". $xml_file);
2231                }
2232
2233                while( ( $data = fread( $fp, 4096 ) ) )
2234                {
2235                        if( !xml_parse( $xml_parser, $data, feof($fp) ) )
2236                        {
2237                                die( sprintf("XML error at line %d column %d ", xml_get_current_line_number($xml_parser), xml_get_current_column_number($xml_parser) ) );
2238                        }
2239                }
2240
2241                xml_parser_free($xml_parser);
2242
2243                return array( $this->xml_skin_info, $this->xml_templates );
2244        }
2245}
2246
2247?>
Note: See TracBrowser for help on using the repository browser.