[ Index ]
 

Code source de Phorum 5.1.25

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/include/admin/ -> customprofile.php (source)

   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          {
  38              // checking names of existing fields and find current max id.
  39              foreach($PHORUM['PROFILE_FIELDS'] as $id => $profile_field) {
  40                  if($id !== 'num_fields' && $profile_field['name'] == $_POST['string']) {
  41                      $exists_already = true;
  42                      break;
  43                  }
  44              }
  45          }
  46  
  47          if(preg_match("/^[^a-z]/i", $_POST["string"]) || preg_match("/[^a-z0-9_]/i", $_POST["string"])){
  48              $error="Field names can only contain letters, numbers and _.  They must start with a letter.";
  49          } elseif(in_array($_POST['string'],$reserved_customfield_names)) {
  50              $error="This name is reserved for use in phorum itself. Please use a different name for your new custom profile-field.";
  51          } elseif($exists_already) {
  52              $error="A custom profile-field with that name exists. Please use a different name for your new custom profile-field.";
  53          } else {
  54  
  55              // Find the current maximum field id: num_fields is more an
  56              // index than the number of custom profile fields.
  57              $max_id = isset($PHORUM['PROFILE_FIELDS']['num_fields'])
  58                      ? $PHORUM['PROFILE_FIELDS']['num_fields'] : 0;
  59              foreach ($PHORUM['PROFILE_FIELDS'] as $id => $profile_field) {
  60                  if($id === 'num_fields') continue;
  61                  if ($max_id < $id) $max_id = $id;
  62              }
  63              $PHORUM['PROFILE_FIELDS']['num_fields'] = $max_id;
  64  
  65              if($_POST["curr"]!=="NEW"){ // editing an existing field
  66                  $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['name']=$_POST["string"];
  67                  $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['length']=$_POST['length'];
  68                  $PHORUM["PROFILE_FIELDS"][$_POST["curr"]]['html_disabled']=$_POST['html_disabled'];
  69              } else { // adding a new field
  70                  $PHORUM['PROFILE_FIELDS']["num_fields"]++;
  71                  $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]=array();
  72                  $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['name']=$_POST["string"];
  73                  $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['length']=$_POST['length'];
  74                  $PHORUM["PROFILE_FIELDS"][$PHORUM['PROFILE_FIELDS']["num_fields"]]['html_disabled']=$_POST['html_disabled'];
  75              }
  76  
  77              if(!phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]))){
  78                  $error="Database error while updating settings.";
  79              } else {
  80                  phorum_admin_okmsg("Profile Field Updated");
  81              }
  82  
  83          }
  84  
  85      }
  86  
  87      if(isset($_POST["curr"]) && isset($_POST["delete"]) && $_POST["confirm"]=="Yes"){
  88          $_POST["curr"] = (int)$_POST["curr"];
  89          unset($PHORUM["PROFILE_FIELDS"][$_POST["curr"]]);
  90          if(!phorum_db_update_settings(array("PROFILE_FIELDS"=>$PHORUM["PROFILE_FIELDS"]))){
  91              $error="Database error while updating settings.";
  92          } else {
  93              phorum_admin_okmsg("Profile Field Deleted");
  94          }
  95      }
  96  
  97      if(isset($_GET["curr"])){
  98          $curr = (int)$_GET["curr"];
  99      }
 100  
 101  
 102      if($curr!=="NEW"){
 103          $string=$PHORUM["PROFILE_FIELDS"][$curr]['name'];
 104          $length=$PHORUM["PROFILE_FIELDS"][$curr]['length'];
 105          $html_disabled=$PHORUM["PROFILE_FIELDS"][$curr]['html_disabled'];
 106          $title="Edit Profile Field";
 107          $submit="Update";
 108      } else {
 109          settype($string, "string");
 110          $title="Add A Profile Field";
 111          $submit="Add";
 112          $length=255;
 113          $html_disabled=1;
 114      }
 115  
 116      if($error){
 117          phorum_admin_error($error);
 118      }
 119  
 120      if(isset($_GET["curr"]) && $_GET["delete"]){ ?>
 121  
 122          <div class="PhorumInfoMessage">
 123              Are you sure you want to delete this entry?
 124              <form action="<?php echo $PHORUM["admin_http_path"] ?>" method="post">
 125                  <input type="hidden" name="module" value="<?php echo $module; ?>" />
 126                  <input type="hidden" name="curr" value="<?php echo (int)$_GET['curr']; ?>" />
 127                  <input type="hidden" name="delete" value="1" />
 128                  <input type="submit" name="confirm" value="Yes" />&nbsp;<input type="submit" name="confirm" value="No" />
 129              </form>
 130          </div>
 131  
 132          <?php
 133  
 134      } else {
 135  
 136  
 137          include_once  "./include/admin/PhorumInputForm.php";
 138  
 139          $frm = new PhorumInputForm ("", "post", $submit);
 140  
 141          $frm->hidden("module", "customprofile");
 142  
 143          $frm->hidden("curr", "$curr");
 144  
 145          $frm->addbreak($title);
 146  
 147          $frm->addrow("Field Name", $frm->text_box("string", $string, 50));
 148          $frm->addrow("Field Length (Max. 65000)", $frm->text_box("length", $length, 50));
 149          $frm->addrow("Disable HTML", $frm->checkbox("html_disabled",1,"Yes",$html_disabled));
 150  
 151          $frm->show();
 152  
 153          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.";
 154  
 155          if($curr=="NEW"){
 156  
 157              echo "<hr class=\"PhorumAdminHR\" />";
 158              if(isset($PHORUM['PROFILE_FIELDS']["num_fields"]))
 159                  unset($PHORUM['PROFILE_FIELDS']["num_fields"]);
 160  
 161              if(count($PHORUM["PROFILE_FIELDS"])){
 162  
 163                  echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" class=\"PhorumAdminTable\" width=\"100%\">\n";
 164                  echo "<tr>\n";
 165                  echo "    <td class=\"PhorumAdminTableHead\">Field</td>\n";
 166                  echo "    <td class=\"PhorumAdminTableHead\">Length</td>\n";
 167                  echo "    <td class=\"PhorumAdminTableHead\">HTML disabled</td>\n";
 168                  echo "    <td class=\"PhorumAdminTableHead\">&nbsp;</td>\n";
 169                  echo "</tr>\n";
 170  
 171                  foreach($PHORUM["PROFILE_FIELDS"] as $key => $item){
 172                      echo "<tr>\n";
 173                      echo "    <td class=\"PhorumAdminTableRow\">".$item['name']."</td>\n";
 174                      echo "    <td class=\"PhorumAdminTableRow\">".$item['length']."</td>\n";
 175                      echo "    <td class=\"PhorumAdminTableRow\">".($item['html_disabled']?"Yes":"No")."</td>\n";
 176                      echo "    <td class=\"PhorumAdminTableRow\"><a href=\"{$PHORUM["admin_http_path"]}?module=customprofile&curr=$key&?edit=1\">Edit</a>&nbsp;&#149;&nbsp;<a href=\"{$PHORUM["admin_http_path"]}?module=customprofile&curr=$key&delete=1\">Delete</a></td>\n";
 177                      echo "</tr>\n";
 178                  }
 179  
 180                  echo "</table>\n";
 181  
 182              } else {
 183  
 184                  echo "No custom fields currently allowed.";
 185  
 186              }
 187  
 188          }
 189      }
 190  ?>


Généré le : Thu Nov 29 12:22:27 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics