1<?php
2
3function my_shutdown()
4{
5    // print "Shutting down";
6    // print connection_status(); # with PHP 4.2.1 buggy. http://bugs.php.net/bug.php?id=17774
7}
8
9function output($msg)
10{
11    if ($GLOBALS['commandline']) {
12        @ob_end_clean();
13        $msg = str_replace('<br/>', "\n", $msg);
14        echo strip_tags($msg);
15        @ob_start();
16    } else {
17        echo $msg."\n";
18    }
19}
20
21function parseImportPlaceHolders($templ, $data)
22{
23    $retval = $templ;
24    foreach ($data as $key => $val) {
25        $key = strtoupper($key);
26        //  dbg('Parsing '.$key.' in '.$templ);
27        if (!is_array($val)) {
28            $retval = preg_replace('/\['.preg_quote($key).'\]/i', $val, $retval);
29        }
30    }
31
32    return $retval;
33}
34
35function clearImport()
36{
37    if (isset($_SESSION['import_file']) && is_file($_SESSION['import_file'])) {
38        unlink($_SESSION['import_file']);
39    }
40    unset($_SESSION['import_file']);
41    unset($_SESSION['systemindex']);
42    unset($_SESSION['import_attribute']);
43    unset($_SESSION['test_import']);
44    unset($_SESSION['assign_invalid']);
45    unset($_SESSION['overwrite']);
46    unset($_SESSION['grouptype']);
47}
48
49//# identify system values from the database structure
50$system_attributes = array();
51reset($DBstruct['user']);
52foreach ($DBstruct['user'] as $key => $val) {
53    if (strpos($val[1], 'sys') === false && is_array($val)) {
54        $system_attributes[strtolower($key)] = $val[1];  //# allow columns like "htmlemail" and "foreignkey"
55        $system_attributes_nicename[strtolower($val[1])] = $key; //# allow columns like "Send this user HTML emails" and "Foreign Key"
56    } else {
57        $colname = $val[1];
58        if (strpos($colname, ':')) {
59            list($sys, $colname) = explode(':', $val[1]);
60        }
61        $skip_system_attributes[strtolower($key)] = $colname;
62    }
63}
64$subselect = ' where id > 0 ';
65if ( !isSuperUser()) {
66    $access = accessLevel('import2');
67    if ($access == 'owner') {
68        $subselect = ' where owner = '.$_SESSION['logindetails']['id'];
69    } elseif ($access == 'all') {
70        $subselect = ' where id > 0 ';
71    } elseif ($access == 'none') {
72        $subselect = ' where id = 0 ';
73    }
74}
75
76//# handle terminology change (from user to subscriber)
77$system_attributes['send this user html emails'] = $system_attributes_nicename['send this subscriber html emails'];
78$system_attributes_nicename['send this user html emails'] = $system_attributes_nicename['send this subscriber html emails'];
79
80//# allow mapping a column to a comma separated list of group names
81$system_attributes['groupmapping'] = 'Group Membership';
82if (isset($GLOBALS['config']['usergroup_types'])) {
83    foreach ($GLOBALS['config']['usergroup_types'] as $grouptype => $typedesc) {
84        if (!empty($grouptype)) {
85            $system_attributes['grouptype_'.$grouptype] = $typedesc.' of group';
86        }
87    }
88}
89if (!isset($GLOBALS['assign_invalid_default'])) {
90    $GLOBALS['assign_invalid_default'] = s('Invalid email').' [number]';
91}
92
93$system_attribute_reverse_map = array_reverse($system_attributes, true);
94