Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
831 florian 1
<?php
2
 
3
////////////////////////////////////////////////////////////////////////////////
4
//                                                                            //
5
//   Copyright (C) 2006  Phorum Development Team                              //
6
//   http://www.phorum.org                                                    //
7
//                                                                            //
8
//   This program is free software. You can redistribute it and/or modify     //
9
//   it under the terms of either the current Phorum License (viewable at     //
10
//   phorum.org) or the Phorum License that was distributed with this file    //
11
//                                                                            //
12
//   This program is distributed in the hope that it will be useful,          //
13
//   but WITHOUT ANY WARRANTY, without even the implied warranty of           //
14
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     //
15
//                                                                            //
16
//   You should have received a copy of the Phorum License                    //
17
//   along with this program.                                                 //
18
////////////////////////////////////////////////////////////////////////////////
19
 
20
    if(!defined("PHORUM_ADMIN")) return;
21
 
22
    $error="";
23
    $curr="NEW";
24
    $exists_already=false;
25
 
26
    // reserved names for custom profile fields, extend as needed
27
    $reserved_customfield_names=array('panel','name','value','error');
28
 
29
    if(count($_POST) && $_POST["string"]!=""){
30
        $_POST['string']=trim($_POST['string']);
31
 
32
 
33
        if(!isset($_POST['html_disabled']))
34
            $_POST['html_disabled']=0;
35
 
36
        if($_POST['curr'] == 'NEW') {
37
            // checking names of existing fields
38
            foreach($PHORUM['PROFILE_FIELDS'] as $profile_field) {
39
                if($profile_field['name'] == $_POST['string']) {
40
                    $exists_already = true;
41
                    break;
42
                }
43
            }
44
        }
45
 
46
        if(preg_match("/^[^a-z]/i", $_POST["string"]) || preg_match("/[^a-z0-9_]/i", $_POST["string"])){
47
            $error="Field names can only contain letters, numbers and _.  They must start with a letter.";
48
        } elseif(in_array($_POST['string'],$reserved_customfield_names)) {
49
            $error="This name is reserved for use in phorum itself. Please use a different name for your new custom profile-field.";
50
        } elseif($exists_already) {
51
            $error="A custom profile-field with that name exists. Please use a different name for your new custom profile-field.";
52
        } else {
53
            if(!isset($PHORUM['PROFILE_FIELDS']["num_fields"])) {
54
                if(count($PHORUM['PROFILE_FIELDS'])) {
55
                    $PHORUM['PROFILE_FIELDS']["num_fields"]=count($PHORUM['PROFILE_FIELDS']);
56
                } else {
57
                    $PHORUM['PROFILE_FIELDS']["num_fields"]=0;
58
                }
59
            }
60
 
61
            if($_POST["curr"]!="NEW"){ // editing an existing field
62
                $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['name']=$_POST["string"];
63
                $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['length']=$_POST['length'];
64
                $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['html_disabled']=$_POST['html_disabled'];
65
            } else { // adding a new field
66
                $PHORUM['PROFILE_FIELDS']["num_fields"]++;
67
                $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]=array();
68
                $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['name']=$_POST["string"];
69
                $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['length']=$_POST['length'];
70
                $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['html_disabled']=$_POST['html_disabled'];
71
            }
72
 
73
            if(!phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]))){
74
                $error="Database error while updating settings.";
75
            } else {
76
                echo "Profile Field Updated<br />";
77
            }
78
 
79
        }
80
 
81
    }
82
 
83
    if(isset($_GET["curr"])){
84
        if(isset($_GET["delete"])){
85
            unset($PHORUM["PROFILE_FIELDS"][$_GET["curr"]]);
86
            phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]));
87
            echo "Profile Field Deleted<br />";
88
        } else {
89
            $curr = $_GET["curr"];
90
        }
91
    }
92
 
93
 
94
    if($curr!="NEW"){
95
        $string=$PHORUM["PROFILE_FIELDS"][$curr]['name'];
96
        $length=$PHORUM["PROFILE_FIELDS"][$curr]['length'];
97
        $html_disabled=$PHORUM["PROFILE_FIELDS"][$curr]['html_disabled'];
98
        $title="Edit Profile Field";
99
        $submit="Update";
100
    } else {
101
        settype($string, "string");
102
        $title="Add A Profile Field";
103
        $submit="Add";
104
        $length=255;
105
        $html_disabled=1;
106
    }
107
 
108
    if($error){
109
        phorum_admin_error($error);
110
    }
111
 
112
    include_once "./include/admin/PhorumInputForm.php";
113
 
114
    $frm =& new PhorumInputForm ("", "post", $submit);
115
 
116
    $frm->hidden("module", "customprofile");
117
 
118
    $frm->hidden("curr", "$curr");
119
 
120
    $frm->addbreak($title);
121
 
122
    $frm->addrow("Field Name", $frm->text_box("string", $string, 50));
123
    $frm->addrow("Field Length (Max. 65000)", $frm->text_box("length", $length, 50));
124
    $frm->addrow("Disable HTML", $frm->checkbox("html_disabled",1,"Yes",$html_disabled));
125
 
126
    $frm->show();
127
 
128
    echo "This will only add the field to the list of allowed fields.  You will need to edit the register and profile templates to actually allow users to use the fields.  Use the name you enter here as the name property of the HTML form element.";
129
 
130
    if($curr=="NEW"){
131
 
132
        echo "<hr class=\"PhorumAdminHR\" />";
133
        if(isset($PHORUM['PROFILE_FIELDS']["num_fields"]))
134
            unset($PHORUM['PROFILE_FIELDS']["num_fields"]);
135
 
136
        if(count($PHORUM["PROFILE_FIELDS"])){
137
 
138
            echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"PhorumAdminTable\" width=\"100%\">\n";
139
            echo "<tr>\n";
140
            echo "    <td class=\"PhorumAdminTableHead\">Field</td>\n";
141
            echo "    <td class=\"PhorumAdminTableHead\">Length</td>\n";
142
            echo "    <td class=\"PhorumAdminTableHead\">HTML disabled</td>\n";
143
            echo "    <td class=\"PhorumAdminTableHead\">&nbsp;</td>\n";
144
            echo "</tr>\n";
145
 
146
            foreach($PHORUM["PROFILE_FIELDS"] as $key => $item){
147
                echo "<tr>\n";
148
                echo "    <td class=\"PhorumAdminTableRow\">".$item['name']."</td>\n";
149
                echo "    <td class=\"PhorumAdminTableRow\">".$item['length']."</td>\n";
150
                echo "    <td class=\"PhorumAdminTableRow\">".($item['html_disabled']?"Yes":"No")."</td>\n";
151
                echo "    <td class=\"PhorumAdminTableRow\"><a href=\"$_SERVER[PHP_SELF]?module=customprofile&curr=$key&?edit=1\">Edit</a>&nbsp;&#149;&nbsp;<a href=\"$_SERVER[PHP_SELF]?module=customprofile&curr=$key&delete=1\">Delete</a></td>\n";
152
                echo "</tr>\n";
153
            }
154
 
155
            echo "</table>\n";
156
 
157
        } else {
158
 
159
            echo "No custom fields currently allowed.";
160
 
161
        }
162
 
163
    }
164
 
165
?>