1<?php
2
3// default configuration. These values can be changed
4// via the admin page, so you do not need to edit them here
5// they are used to initialise things
6// if you *do* edit them, make sure they stay in the correct format
7// otherwise you will end up with parse errors and things will stop working
8
9if (!defined('PHPLISTINIT')) {
10    die;
11}
12
13$defaultheader = '</head><body>';
14
15$defaultfooter = '</body></html>';
16
17if (is_file(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendheader.php')) {
18    $defaultheader = file_get_contents(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendheader.php');
19}
20if (is_file(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendfooter.php')) {
21    $defaultfooter = file_get_contents(dirname(__FILE__).'/ui/'.$GLOBALS['ui'].'/frontendfooter.php');
22}
23
24$envHost = getEnv('HOSTNAME');
25$envPort = getEnv('PORT');
26if (isset($_SERVER['HTTP_HOST'])) {
27    $D_website = $_SERVER['HTTP_HOST'];
28} elseif (isset($_SERVER['SERVER_NAME'])) {
29    $D_website = $_SERVER['SERVER_NAME'];
30} elseif(!empty($envHost)) {
31    if ($envPort != 80 && $envPort != 443) {
32        $D_website = "$envHost:$envPort";
33    } else {
34        $D_website = "$envHost";
35    }
36} else {
37    $D_website = s('unable to detect hostname');
38}
39
40$D_domain = $D_website;
41if (preg_match("#^www\.(.*)#i", $D_domain, $regs)) {
42    $D_domain = $regs[1];
43}
44
45// for starters, you want to leave this line as it is.
46$default_config = array(
47
48    /* any next line has the format
49      "name" => array(
50        'value',     // default value
51        'description',
52        'type',      // text, textarea, boolean
53        'allow empty', // 0 or 1 (or false/true)
54        'category'   // general
55      ),
56    */
57
58    // what is your website location (url)
59    'website' => array(
60        'value'       => $D_website,
61        'description' => s('Website address (without http://)'),
62        'infoicon'    => true,
63        'type'        => 'text',
64        'allowempty'  => false, //# indication this value cannot be empty (1 being it can be empty)
65        'category'    => 'general',
66    ),
67
68    // what is your domain (for sending emails)
69    'domain' => array(
70        'value'       => $D_domain,
71        'description' => s('Domain Name of your server (for email)'),
72        'type'        => 'text',
73        'allowempty'  => false,
74        'category'    => 'general',
75    ),
76
77    // admin address is the person who is in charge of this system
78    'admin_address' => array(
79        'value'       => 'webmaster@[DOMAIN]',
80        'description' => s('Person in charge of this system (one email address)'),
81        'type'        => 'email',
82        'allowempty'  => false,
83        'category'    => 'general',
84    ),
85    // name of the organisation
86    'organisation_name' => array(
87        'value'       => '',
88        'description' => s('Name of the organisation'),
89        'type'        => 'text',
90        'allowempty'  => true,
91        'allowtags'   => '<b><i><u><strong><em><h1><h2><h3><h4>',
92        'allowJS'     => false,
93        'category'    => 'general',
94    ),
95// logo of the organisation
96    'organisation_logo' => array(
97        'value'       => '',
98        'description' => s('Logo of the organisation'),
99        'infoicon'    => true,
100        'type'        => 'image',
101        'allowempty'  => true,
102        'category'    => 'general',
103    ),
104    'date_format' => array(
105        'value'       => 'j F Y',
106        'description' => s('Date format'),
107        'infoicon'    => true,
108        'type'        => 'text',
109        'allowempty'  => false,
110        'category'    => 'general',
111    ),
112    'rc_notification' => array(
113        'value'       => 0,
114        'description' => s('Show notification for Release Candidates'),
115        'type'        => 'boolean',
116        'allowempty'  => true,
117        'category'    => 'security',
118    ),
119
120    //# remote processing secret
121    // @TODO previous value generation was limited to 20 hex characters (max), determine if this is enough (80 bits)
122    'remote_processing_secret' => array(
123        'value'       => bin2hex(random_bytes(10)),
124        'description' => s('Secret for remote processing'),
125        'type'        => 'text',
126        'category'    => 'security',
127    ),
128
129    // admin addresses are other people who receive copies of subscriptions
130    'admin_addresses' => array(
131        'value'       => '',
132        'description' => s('List of email addresses to CC in system messages (separate by commas)'),
133        'type'        => 'emaillist',
134        'allowempty'  => true,
135        'category'    => 'reporting',
136    ),
137    'campaignfrom_default' => array(
138        'value'       => '',
139        'description' => s("Default for 'From:' in a campaign"),
140        'type'        => 'text',
141        'allowempty'  => true,
142        'category'    => 'campaign',
143    ),
144    'notifystart_default' => array(
145        'value'       => '',
146        'description' => s("Default for 'address to alert when sending starts'"),
147        'type'        => 'email',
148        'allowempty'  => true,
149        'category'    => 'campaign',
150    ),
151    'notifyend_default' => array(
152        'value'       => '',
153        'description' => s("Default for 'address to alert when sending finishes'"),
154        'type'        => 'email',
155        'allowempty'  => true,
156        'category'    => 'campaign',
157    ),
158    'always_add_googletracking' => array(
159        'value'       => '0',
160        'description' => s('Always add analytics tracking code to campaigns'),
161        'type'        => 'boolean',
162        'allowempty'  => true,
163        'category'    => 'campaign',
164    ),
165    'analytic_tracker' => array(
166        'values'       => array('google' => 'Google Analytics', 'matomo' => 'Matomo'),
167        'value'        => 'google',
168        'description'  => s('Analytics tracking code to add to campaign URLs'),
169        'type'         => 'select',
170        'allowempty'   => false,
171        'category'     => 'campaign',
172    ),
173    // report address is the person who gets the reports
174    'report_address' => array(
175        'value'       => 'listreports@[DOMAIN]',
176        'description' => s('Who gets the reports (email address, separate multiple emails with a comma)'),
177        'type'        => 'emaillist',
178        'allowempty'  => true,
179        'category'    => 'reporting',
180    ),
181
182    // where will messages appear to come from
183    'message_from_address' => array(
184        'value'       => 'noreply@[DOMAIN]',
185        'description' => s('From email address for system messages'),
186        'type'        => 'email',
187        'allowempty'  => 0,
188        'category'    => 'transactional',
189    ),
190
191    'message_from_name' => array(
192        'value'       => s('Webmaster'),
193        'description' => s('Name for system messages'),
194        'type'        => 'text',
195        'allowempty'  => 0,
196        'category'    => 'transactional',
197    ),
198
199    // what is the reply-to on messages?
200    'message_replyto_address' => array(
201        'value'       => 'noreply@[DOMAIN]',
202        'description' => s('Reply-to email address for system messages'),
203        'type'        => 'email',
204        'allowempty'  => 0,
205        'category'    => 'transactional',
206    ),
207
208    // if there is only one visible list, do we hide it and automatically
209    // subscribe users who sign up
210    //# not sure why you would not want this :-) maybe it should not be an option at all
211    'hide_single_list' => array(
212        'value'       => '1',
213        'description' => s('If there is only one visible list, should it be hidden in the page and automatically subscribe users who sign up'),
214        'type'        => 'boolean',
215        'allowempty'  => true,
216        'category'    => 'subscription-ui',
217    ),
218
219    // categories for lists, to organise them a little bit
220    // comma separated list of words
221    'list_categories' => array(
222        'value'       => '',
223        'description' => s('Categories for lists. Separate with commas.'),
224        'infoicon'    => true,
225        'type'        => 'text',
226        'allowempty'  => true,
227        'category'    => 'list-organisation',
228    ),
229
230    'displaycategories' => array(
231        'value'       => 0,
232        'description' => s('Display list categories on subscribe page'),
233        'type'        => 'boolean',
234        'allowempty'  => false,
235        'category'    => 'list-organisation',
236    ),
237
238    // width of a textline field
239    'textline_width' => array(
240        'value'       => '40',
241        'description' => s('Width of a textline field (numerical)'),
242        'type'        => 'integer',
243        'min'         => 20,
244        'max'         => 150,
245        'category'    => 'subscription-ui',
246    ),
247
248    // dimensions of a textarea field
249    'textarea_dimensions' => array(
250        'value'       => '10,40',
251        'description' => s('Dimensions of a textarea field (rows,columns)'),
252        'type'        => 'text',
253        'allowempty'  => 0,
254        'category'    => 'subscription-ui',
255    ),
256
257    // send copies of subscribe, update unsubscribe messages to the administrator
258    'send_admin_copies' => array(
259        'value'       => '0',
260        'description' => s('Send notifications about subscribe, update and unsubscribe'),
261        'type'        => 'boolean',
262        'allowempty'  => true,
263        'category'    => 'reporting',
264    ),
265
266    // the main subscribe page, when there are multiple
267    'defaultsubscribepage' => array(
268        'value'       => 1,
269        'description' => s('The default subscribe page when there are multiple'),
270        'type'        => 'integer',
271        'min'         => 1,
272        'max'         => 999,  // max(id) from subscribepage
273        'allowempty'  => true,
274        'category'    => 'subscription',
275    ),
276
277    // the default template for sending an html message
278    'defaultmessagetemplate' => array(
279        'value'       => 0,
280        'description' => s('The default HTML template to use when sending a message'),
281        'type'        => 'text',
282        'allowempty'  => true,
283        'category'    => 'campaign',
284    ),
285
286    // the template for system messages (welcome confirm subscribe etc)
287    'systemmessagetemplate' => array(
288        'value'       => 0,
289        'description' => s('The HTML wrapper template for system messages'),
290        'type'        => 'integer',
291        'min'         => 0,
292        'max'         => 999, // or max(id) from template
293        'allowempty'  => true,
294        'category'    => 'transactional',
295    ),
296    //# the location of your subscribe script
297    //"public_baseurl" => array("http://[WEBSITE]$pageroot/",
298    //  "Base URL for public pages","text"),
299
300    // the location of your subscribe script
301    'subscribeurl' => array(
302        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=subscribe",
303        'description' => s('URL where subscribers can sign up'),
304        'type'        => 'url',
305        'allowempty'  => 0,
306        'category'    => 'subscription',
307    ),
308
309    // the location of your unsubscribe script:
310    'unsubscribeurl' => array(
311        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=unsubscribe",
312        'description' => s('URL where subscribers can unsubscribe'),
313        'type'        => 'url',
314        'allowempty'  => 0,
315        'category'    => 'subscription',
316    ),
317
318    //0013076: Blacklisting posibility for unknown users
319    // the location of your blacklist script:
320    'blacklisturl' => array(
321        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=donotsend",
322        'description' => s('URL where unknown users can unsubscribe (do-not-send-list)'),
323        'type'        => 'url',
324        'allowempty'  => 0,
325        'category'    => 'subscription',
326    ),
327
328// the location of your confirm script:
329    'confirmationurl' => array(
330        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=confirm",
331        'description' => s('URL where subscribers have to confirm their subscription'),
332        'type'        => 'text',
333        'allowempty'  => 0,
334        'category'    => 'subscription',
335    ),
336
337    // url to change their preferences
338    'preferencesurl' => array(
339        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=preferences",
340        'description' => s('URL where subscribers can update their details'),
341        'type'        => 'text',
342        'allowempty'  => 0,
343        'category'    => 'subscription',
344    ),
345
346    // url to change their preferences
347    'forwardurl' => array(
348        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=forward",
349        'description' => s('URL for forwarding messages'),
350        'type'        => 'text',
351        'allowempty'  => 0,
352        'category'    => 'subscription',
353    ),
354
355    // url to download vcf card
356    'vcardurl' => array(
357        'value'       => $GLOBALS['public_scheme']."://[WEBSITE]$pageroot/?p=vcard",
358        'description' => s('URL for downloading vcf card'),
359        'type'        => 'text',
360        'allowempty'  => 0,
361        'category'    => 'subscription',
362    ),
363
364    'ajax_subscribeconfirmation' => array(
365        'value'       => s('<h3>Thanks, you have been added to our newsletter</h3><p>You will receive an email to confirm your subscription. Please click the link in the email to confirm</p>'),
366        'description' => s('Text to display when subscription with an AJAX request was successful'),
367        'type'        => 'textarea',
368        'allowempty'  => true,
369        'category'    => 'subscription',
370    ),
371
372    // the location of your subscribe script
373    //"subscribe_baseurl" => array("http://[WEBSITE]$pageroot/",
374    //  "Base URL for public pages","text"),
375
376    // the subject of the message
377    'subscribesubject' => array(
378        'value'       => s('Request for confirmation'),
379        'description' => s('Subject of the message subscribers receive when they sign up'),
380        'infoicon'        => true,
381        'type'        => 'text',
382        'allowempty'  => 0,
383        'category'    => 'transactional',
384    ),
385
386    // message that is sent when people sign up to a list
387    // [LISTS] will be replaced with the list of lists they have signed up to
388    // [CONFIRMATIONURL] will be replaced with the URL where a user has to confirm
389    // their subscription
390    'subscribemessage' => array(
391        'value' =>
392' You have been subscribed to the following newsletters:
393
394[LISTS]
395
396
397Please click the following link to confirm it\'s really you:
398
399[CONFIRMATIONURL]
400
401
402In order to provide you with this service we\'ll need to
403
404Transfer your contact information to [DOMAIN]
405Store your contact information in your [DOMAIN] account
406Send you emails from [DOMAIN]
407Track your interactions with these emails for marketing purposes
408
409If this is not correct, or you do not agree, simply take no action and delete this message.'
410    ,
411        'description' => s('Message subscribers receive when they sign up'),
412        'type'        => 'textarea',
413        'allowempty'  => 0,
414        'category'    => 'transactional',
415    ),
416
417    // subject of the message when they unsubscribe
418    'unsubscribesubject' => array(
419        'value'       => s('Goodbye from our Newsletter'),
420        'description' => s('Subject of the message subscribers receive when they unsubscribe'),
421        'type'        => 'text',
422        'allowempty'  => 0,
423        'category'    => 'transactional',
424    ),
425
426    // message that is sent when they unsubscribe
427    'unsubscribemessage' => array(
428        'value' =>
429'Goodbye from our Newsletter, sorry to see you go.
430
431You have been unsubscribed from our newsletters.
432
433This is the last email you will receive from us. Our newsletter system, phpList,
434will refuse to send you any further messages, without manual intervention by our administrator.
435
436If there is an error in this information, you can re-subscribe:
437please go to [SUBSCRIBEURL] and follow the steps.
438
439Thank you'
440  ,
441        'description' => s('Message subscribers receive when they unsubscribe'),
442        'type'        => 'textarea',
443        'allowempty'  => 0,
444        'category'    => 'transactional',
445    ),
446
447    // confirmation of subscription
448    'confirmationsubject' => array(
449        'value'       => s('Welcome to our Newsletter'),
450        'description' => s('Subject of the message subscribers receive after confirming their email address'),
451        'type'        => 'text',
452        'allowempty'  => 0,
453        'category'    => 'transactional',
454    ),
455
456    // message that is sent to confirm subscription
457    'confirmationmessage' => array(
458        'value' =>
459'Welcome to our Newsletter
460
461Please keep this message for later reference.
462
463Your email address has been added to the following newsletter(s):
464[LISTS]
465
466To update your details and preferences please go to [PREFERENCESURL].
467If you do not want to receive any more messages, please go to [UNSUBSCRIBEURL].
468
469Thank you'
470  ,
471        'description' => s('Message subscribers receive after confirming their email address'),
472        'type'        => 'textarea',
473        'allowempty'  => 0,
474        'category'    => 'transactional',
475    ),
476
477    // the subject of the message sent when changing the user details
478    'updatesubject' => array(
479        'value'       => s('[notify] Change of List-Membership details'),
480        'description' => s('Subject of the message subscribers receive when they have changed their details'),
481        'type'        => 'text',
482        'allowempty'  => 0,
483        'category'    => 'transactional',
484    ),
485
486    // the message that is sent when a user updates their information.
487    // just to make sure they approve of it.
488    // confirmationinfo is replaced by one of the options below
489    // userdata is replaced by the information in the database
490    'updatemessage' => array(
491        'value' =>
492'This message is to inform you of a change of your details on our newsletter database
493
494You are currently member of the following newsletters:
495
496[LISTS]
497
498[CONFIRMATIONINFO]
499
500The information on our system for you is as follows:
501
502[USERDATA]
503
504If this is not correct, please update your information at the following location:
505
506[PREFERENCESURL]
507
508Thank you'
509  ,
510        'description' => s('Message subscribers receive when they have changed their details'),
511        'type'        => 'textarea',
512        'allowempty'  => 0,
513        'category'    => 'transactional',
514    ),
515
516    // this is the text that is placed in the [!-- confirmation --] location of the above
517    // message, in case the email is sent to their new email address and they have changed
518    // their email address
519    'emailchanged_text' => array(
520        'value' => '
521  When updating your details, your email address has changed.
522  Please confirm your new email address by visiting this webpage:
523
524  [CONFIRMATIONURL]
525
526  ',
527        'description' => s('Part of the message that is sent to their new email address when subscribers change their information, and the email address has changed'),
528        'type'        => 'textarea',
529        'allowempty'  => 0,
530        'category'    => 'transactional',
531    ),
532
533    // this is the text that is placed in the [!-- confirmation --] location of the above
534    // message, in case the email is sent to their old email address and they have changed
535    // their email address
536    'emailchanged_text_oldaddress' => array(
537        'value' =>
538'Please Note: when updating your details, your email address has changed.
539
540A message has been sent to your new email address with a URL
541to confirm this change. Please visit this website to activate
542your membership.'
543  ,
544        'description' => s('Part of the message that is sent to their old email address when subscribers change their information, and the email address has changed'),
545        'type'        => 'textarea',
546        'allowempty'  => 0,
547        'category'    => 'transactional',
548    ),
549
550    'personallocation_subject' => array(
551        'value'       => s('Your personal location'),
552        'description' => s('Subject of message when subscribers request their personal location'),
553        'type'        => 'text',
554        'allowempty'  => 0,
555        'category'    => 'transactional',
556    ),
557
558    'personallocation_message' => array(
559        'value' =>
560'You have requested your personal location to update your details in our newsletter database.
561The location is below. Please make sure that you use the full line as mentioned below.
562Sometimes email programs wrap the link over multiple lines.
563
564Your personal location is:
565[PREFERENCESURL]
566
567Thank you.'
568  ,
569        'description' => s('Message when subscribers request their personal location'),
570        'type'        => 'textarea',
571        'allowempty'  => 0,
572        'category'    => 'transactional',
573    ),
574
575    'messagefooter' => array(
576        'value' => '--
577
578    <div class="footer" style="text-align:left; font-size: 75%;">
579      <p>This message was sent to [EMAIL] by [FROMEMAIL].</p>
580      <p>To forward this message, please do not use the forward button of your email application, because this message was made specifically for you only. Instead use the <a href="[FORWARDURL]">forward page</a> in our newsletter system.<br/>
581      To change your details and to choose which lists to be subscribed to, visit your personal <a href="[PREFERENCESURL]">preferences page</a>.<br/>
582      Or you can <a href="[UNSUBSCRIBEURL]">opt-out completely</a> from all future mailings.</p>
583    </div>
584
585  ',
586        'description' => s('Default footer for sending a campaign'),
587        'type'        => 'textarea',
588        'allowempty'  => 0,
589        'category'    => 'campaign',
590    ),
591
592    'forwardfooter' => array(
593        'value' => '
594     <div class="footer" style="text-align:left; font-size: 75%;">
595      <p>This message has been forwarded to you by [FORWARDEDBY].</p>
596      <p>You have not been automatically subscribed to this newsletter.</p>
597      <p>If you think this newsletter may interest you, you can <a href="[SUBSCRIBEURL]">Subscribe</a> and you will receive our next newsletter directly to your inbox.</p>
598      <p>You can also <a href="[BLACKLISTURL]">opt out completely</a> from receiving any further email from our newsletter application, phpList.</p>
599    </div>
600  ',
601        'description' => s('Footer used when a message has been forwarded'),
602        'type'        => 'textarea',
603        'allowempty'  => 0,
604        'category'    => 'campaign',
605    ),
606
607    'pageheader' => array(
608        'value'       => $defaultheader,
609        'description' => s('Header of public pages.'),
610        'type'        => 'textarea',
611        'allowempty'  => 0,
612        'category'    => 'subscription-ui',
613    ),
614
615    'pagefooter' => array(
616        'value'       => $defaultfooter,
617        'description' => s('Footer of public pages'),
618        'type'        => 'textarea',
619        'allowempty'  => 0,
620        'category'    => 'subscription-ui',
621    ),
622
623//"html_charset" => array (
624    //"UTF-8",
625    //"Charset for HTML messages",
626    //"text"
627//),
628//"text_charset" => array (
629    //"UTF-8",
630    //"Charset for Text messages",
631    //"text"
632//),
633
634    'personallocation_message' => array(
635        'value' =>
636
637'You have requested your personal location to update your details from our website.
638The location is below. Please make sure that you use the full line as mentioned below.
639Sometimes email programmes can wrap the line into multiple lines.
640
641Your personal location is:
642[PREFERENCESURL]
643
644Thank you.'
645,
646        'description' => s('Message to send when they request their personal location'),
647        'type'        => 'textarea',
648        'allowempty'  => 0,
649        'category'    => 'transactional',
650    ),
651
652    'remoteurl_append' => array(
653        'value'       => '',
654        'description' => s('String to always append to remote URL when using send-a-webpage'),
655        'type'        => 'text',
656        'allowempty'  => true,
657        'category'    => 'campaign',
658    ),
659
660    'wordwrap' => array(
661        'value'       => '75',
662        'description' => s('Width for Wordwrap of Text messages'),
663        'type'        => 'text',
664        'allowempty'  => true,
665        'category'    => 'campaign',
666    ),
667
668    'html_email_style' => array(
669        'value'       => '',
670        'description' => s('CSS for HTML messages without a template'),
671        'type'        => 'textarea',
672        'allowempty'  => true,
673        'category'    => 'campaign',
674    ),
675
676    'alwayssendtextto' => array(
677        'value'       => '',
678        'description' => s('Domains that only accept text emails, one per line'),
679        'type'        => 'textarea',
680        'allowempty'  => true,
681        'category'    => 'campaign',
682    ),
683
684    'tld_last_sync' => array(
685        'value'       => '0',
686        'description' => s('last time TLDs were fetched'),
687        'type'        => 'text',
688        'allowempty'  => true,
689        'category'    => 'system',
690        'hidden'      => true,
691    ),
692    'internet_tlds' => array(
693        'value'       => '',
694        'description' => s('Top level domains'),
695        'type'        => 'textarea',
696        'allowempty'  => true,
697        'category'    => 'system',
698        'hidden'      => true,
699    ),
700
701);
702
703//######### certainly do not edit after this #########
704
705$redfont = '';
706$efont = '';
707
708if (!TEST && REGISTER && defined('VERSION')) {
709    if (strpos(VERSION, 'dev') !== false) {
710        $v = 'dev';
711    } else {
712        $v = VERSION;
713    }
714    $PoweredBy = '<p align="left"><a href="https://www.phplist.com"><img src="'.PHPLIST_POWEREDBY_URLROOT.'/' . $v . '/power-phplist.png" width="88" height="31" title="powered by phplist" alt="powered by phplist" border="0" /></a></p>';
715} else {
716    $PoweredBy = '<center><a href="https://www.phplist.com"><img src="images/power-phplist.png" width="88" height="31" title="powered by phplist" alt="powered by phplist" border="0" /></a></center>';
717}
718
719if (!function_exists('getconfig')) {
720    function getConfig($item)
721    {
722        global $default_config, $domain, $website, $tables;
723
724        if ($item != 'website' && isset($GLOBALS['config'][$item])) {
725            return $GLOBALS['config'][$item];
726        }
727        /*
728            if (!DEVSITE && isset($_SESSION['config'][$item])) {
729              return $_SESSION['config'][$item];
730            }
731        */
732        if (!isset($GLOBALS['config']) || !is_array($GLOBALS['config'])) {
733            $GLOBALS['config'] = array();
734        }
735
736        if (empty($_SESSION['hasconf'])) {
737            $hasconf = Sql_Table_Exists($tables['config'], 1);
738            $_SESSION['hasconf'] = $hasconf;
739        } else {
740            $hasconf = $_SESSION['hasconf'];
741        }
742
743        $value = '';
744        if (!empty($hasconf)) {
745            $req = Sql_Query(sprintf('select value,editable from %s where item = "%s"', $tables['config'],
746                sql_escape($item)));
747            if (!Sql_Affected_Rows() || !$hasconf) {
748                if (isset($default_config[$item])) {
749                    $value = $default_config[$item]['value'];
750                }
751                // save the default value to the database, so we can obtain
752                // the information when running from commandline
753                if (Sql_Table_Exists($tables['config'])) {
754                    saveConfig($item, $value);
755                }
756                //    print "$item => $value<br/>";
757            } else {
758                $row = Sql_Fetch_Row($req);
759                $value = $row[0];
760                if (!empty($default_config[$item]['hidden'])) {
761                    $GLOBALS['noteditableconfig'][] = $item;
762                }
763            }
764        }
765        $value = str_replace('[WEBSITE]', $website, $value);
766        $value = str_replace('[DOMAIN]', $domain, $value);
767        $value = str_replace('<?=VERSION?>', VERSION, $value);
768
769        if (isset($default_config[$item]['type'])) {
770            $type = $default_config[$item]['type'];
771        } else {
772            $type = '';
773        }
774
775        if ($type == 'boolean') {
776            if ($value == '0') {
777                $value = 'false';
778            } elseif ($value == '1') {
779                $value = 'true';
780            }
781            //# cast to bool
782            $value = $value == 'true';
783        }
784
785        //# disallow single quotes in listcategories
786        if ($item == 'list_categories') {
787            $value = str_replace("'", ' ', $value);
788        }
789
790        // if this is a subpage item, and no value was found get the global one
791        if (!$value && strpos($item, ':') !== false) {
792            list($a, $b) = explode(':', $item);
793            $value = getConfig($a);
794            $_SESSION['config'][$item] = $value;
795
796            return $value;
797        } else {
798            $GLOBALS['config'][$item] = stripslashes($value);
799            $_SESSION['config'][$item] = $GLOBALS['config'][$item];
800
801            return $GLOBALS['config'][$item];
802        }
803    }
804} else {
805    reset($default_config);
806    foreach ($default_config as $item => $values) {
807        $val = getConfig($item);
808        saveConfig($item, $values[0], 0);
809    }
810}
811
812function getUserConfig($item, $userid = 0)
813{
814    global $default_config, $tables, $domain, $website;
815    $hasconf = Sql_Table_Exists($tables['config']);
816    $value = '';
817
818    if ($hasconf) {
819        $req = Sql_Query(sprintf('select value,editable from %s where item = "%s"', $tables['config'],
820            sql_escape($item)));
821
822        if (!Sql_Num_Rows($req)) {
823            if (array_key_exists($item, $default_config)) {
824                $value = $default_config[$item]['value'];
825            }
826        } else {
827            $row = Sql_fetch_Row($req);
828            $value = $row[0];
829
830            if ($row[1] == 0) {
831                $GLOBALS['noteditableconfig'][] = $item;
832            }
833        }
834    }
835    // if this is a subpage item, and no value was found get the global one
836    if (!$value && strpos($item, ':') !== false) {
837        list($a, $b) = explode(':', $item);
838        $value = getUserConfig($a, $userid);
839    }
840
841    if ($userid) {
842        $rs = Sql_Query(sprintf('select uniqid, email from '.$tables['user'].' where id = %d', $userid));
843        $user_req = Sql_Fetch_Row($rs);
844        $uniqid = $user_req[0];
845        $email = $user_req[1];
846        // parse for placeholders
847        // do some backwards compatibility:
848        // hmm, reverted back to old system
849
850        $url = getConfig('unsubscribeurl');
851        $sep = strpos($url, '?') !== false ? '&' : '?';
852        $value = str_ireplace('[UNSUBSCRIBEURL]', $url.$sep.'uid='.$uniqid.' ', $value);
853        $url = getConfig('confirmationurl');
854        $sep = strpos($url, '?') !== false ? '&' : '?';
855        $value = str_ireplace('[CONFIRMATIONURL]', $url.$sep.'uid='.$uniqid.' ', $value);
856        $url = getConfig('preferencesurl');
857        $sep = strpos($url, '?') !== false ? '&' : '?';
858        $value = str_ireplace('[PREFERENCESURL]', $url.$sep.'uid='.$uniqid.' ', $value);
859        $value = str_ireplace('[EMAIL]', $email, $value);
860
861        $value = parsePlaceHolders($value, getUserAttributeValues($email));
862    }
863    $value = str_ireplace('[SUBSCRIBEURL]', getConfig('subscribeurl').' ', $value);
864    $value = preg_replace('/\[DOMAIN\]/i', $domain,
865        $value); //@ID Should be done only in one place. Combine getConfig and this one?
866    $value = preg_replace('/\[WEBSITE\]/i', $website, $value);
867
868    if ($value == '0') {
869        $value = 'false';
870    } elseif ($value == '1') {
871        $value = 'true';
872    }
873
874    return $value;
875}
876
877$access_levels = array(
878    0 => 'none',
879    1 => 'all',
880    2 => 'view',
881    //   3 => "edit",
882    4 => 'owner',
883);
884