PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/campsite/src/include/phorum/include/admin/customprofile.php

https://github.com/joechrysler/Campsite
PHP | 165 lines | 111 code | 36 blank | 18 comment | 32 complexity | 7698b798ce8d6c53201435a28d9e48a4 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. ////////////////////////////////////////////////////////////////////////////////
  3. // //
  4. // Copyright (C) 2006 Phorum Development Team //
  5. // http://www.phorum.org //
  6. // //
  7. // This program is free software. You can redistribute it and/or modify //
  8. // it under the terms of either the current Phorum License (viewable at //
  9. // phorum.org) or the Phorum License that was distributed with this file //
  10. // //
  11. // This program is distributed in the hope that it will be useful, //
  12. // but WITHOUT ANY WARRANTY, without even the implied warranty of //
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
  14. // //
  15. // You should have received a copy of the Phorum License //
  16. // along with this program. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. if(!defined("PHORUM_ADMIN")) return;
  19. $error="";
  20. $curr="NEW";
  21. $exists_already=false;
  22. // reserved names for custom profile fields, extend as needed
  23. $reserved_customfield_names=array('panel','name','value','error');
  24. if(count($_POST) && $_POST["string"]!=""){
  25. $_POST['string']=trim($_POST['string']);
  26. if(!isset($_POST['html_disabled']))
  27. $_POST['html_disabled']=0;
  28. if($_POST['curr'] == 'NEW') {
  29. // checking names of existing fields
  30. foreach($PHORUM['PROFILE_FIELDS'] as $profile_field) {
  31. if($profile_field['name'] == $_POST['string']) {
  32. $exists_already = true;
  33. break;
  34. }
  35. }
  36. }
  37. if(preg_match("/^[^a-z]/i", $_POST["string"]) || preg_match("/[^a-z0-9_]/i", $_POST["string"])){
  38. $error="Field names can only contain letters, numbers and _. They must start with a letter.";
  39. } elseif(in_array($_POST['string'],$reserved_customfield_names)) {
  40. $error="This name is reserved for use in phorum itself. Please use a different name for your new custom profile-field.";
  41. } elseif($exists_already) {
  42. $error="A custom profile-field with that name exists. Please use a different name for your new custom profile-field.";
  43. } else {
  44. if(!isset($PHORUM['PROFILE_FIELDS']["num_fields"])) {
  45. if(count($PHORUM['PROFILE_FIELDS'])) {
  46. $PHORUM['PROFILE_FIELDS']["num_fields"]=count($PHORUM['PROFILE_FIELDS']);
  47. } else {
  48. $PHORUM['PROFILE_FIELDS']["num_fields"]=0;
  49. }
  50. }
  51. if($_POST["curr"]!="NEW"){ // editing an existing field
  52. $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['name']=$_POST["string"];
  53. $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['length']=$_POST['length'];
  54. $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['html_disabled']=$_POST['html_disabled'];
  55. } else { // adding a new field
  56. $PHORUM['PROFILE_FIELDS']["num_fields"]++;
  57. $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]=array();
  58. $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['name']=$_POST["string"];
  59. $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['length']=$_POST['length'];
  60. $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['html_disabled']=$_POST['html_disabled'];
  61. }
  62. if(!phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]))){
  63. $error="Database error while updating settings.";
  64. } else {
  65. echo "Profile Field Updated<br />";
  66. }
  67. }
  68. }
  69. if(isset($_GET["curr"])){
  70. if(isset($_GET["delete"])){
  71. unset($PHORUM["PROFILE_FIELDS"][$_GET["curr"]]);
  72. phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]));
  73. echo "Profile Field Deleted<br />";
  74. } else {
  75. $curr = $_GET["curr"];
  76. }
  77. }
  78. if($curr!="NEW"){
  79. $string=$PHORUM["PROFILE_FIELDS"][$curr]['name'];
  80. $length=$PHORUM["PROFILE_FIELDS"][$curr]['length'];
  81. $html_disabled=$PHORUM["PROFILE_FIELDS"][$curr]['html_disabled'];
  82. $title="Edit Profile Field";
  83. $submit="Update";
  84. } else {
  85. settype($string, "string");
  86. $title="Add A Profile Field";
  87. $submit="Add";
  88. $length=255;
  89. $html_disabled=1;
  90. }
  91. if($error){
  92. phorum_admin_error($error);
  93. }
  94. include_once "./include/admin/PhorumInputForm.php";
  95. $frm = new PhorumInputForm ("", "post", $submit);
  96. $frm->hidden("module", "customprofile");
  97. $frm->hidden("curr", "$curr");
  98. $frm->addbreak($title);
  99. $frm->addrow("Field Name", $frm->text_box("string", $string, 50));
  100. $frm->addrow("Field Length (Max. 65000)", $frm->text_box("length", $length, 50));
  101. $frm->addrow("Disable HTML", $frm->checkbox("html_disabled",1,"Yes",$html_disabled));
  102. $frm->show();
  103. 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.";
  104. if($curr=="NEW"){
  105. echo "<hr class=\"PhorumAdminHR\" />";
  106. if(isset($PHORUM['PROFILE_FIELDS']["num_fields"]))
  107. unset($PHORUM['PROFILE_FIELDS']["num_fields"]);
  108. if(count($PHORUM["PROFILE_FIELDS"])){
  109. echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"PhorumAdminTable\" width=\"100%\">\n";
  110. echo "<tr>\n";
  111. echo " <td class=\"PhorumAdminTableHead\">Field</td>\n";
  112. echo " <td class=\"PhorumAdminTableHead\">Length</td>\n";
  113. echo " <td class=\"PhorumAdminTableHead\">HTML disabled</td>\n";
  114. echo " <td class=\"PhorumAdminTableHead\">&nbsp;</td>\n";
  115. echo "</tr>\n";
  116. foreach($PHORUM["PROFILE_FIELDS"] as $key => $item){
  117. echo "<tr>\n";
  118. echo " <td class=\"PhorumAdminTableRow\">".$item['name']."</td>\n";
  119. echo " <td class=\"PhorumAdminTableRow\">".$item['length']."</td>\n";
  120. echo " <td class=\"PhorumAdminTableRow\">".($item['html_disabled']?"Yes":"No")."</td>\n";
  121. 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";
  122. echo "</tr>\n";
  123. }
  124. echo "</table>\n";
  125. } else {
  126. echo "No custom fields currently allowed.";
  127. }
  128. }
  129. ?>