[ Index ]

PHP Cross Reference of E107 v0.7.22 code documentation

title

Body

[close]

/ -> usersettings.php (source)

   1  <?php
   2  /*
   3  * e107 website system
   4  *
   5  * Copyright (C) 2008-2010 e107 Inc (e107.org)
   6  * Released under the terms and conditions of the
   7  * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
   8  *
   9  * User settings editing
  10  *
  11  * $URL: https://e107.svn.sourceforge.net/svnroot/e107/trunk/e107_0.7/usersettings.php $
  12  * $Id: usersettings.php 11541 2010-05-19 22:01:19Z secretr $
  13  *
  14  */
  15  
  16  require_once ("class2.php");
  17  require_once(e_HANDLER."ren_help.php");
  18  require_once(e_HANDLER."user_extended_class.php");
  19  $ue = new e107_user_extended;
  20  
  21  //define("US_DEBUG",TRUE);
  22  define("US_DEBUG",FALSE);
  23  
  24  
  25  if (!USER) {
  26      header("location:".e_BASE."index.php");
  27      exit;
  28  }
  29  
  30  if ((!ADMIN || !getperms('4')) && e_QUERY && e_QUERY != 'update' )
  31  {
  32      header("location:".e_BASE."usersettings.php");
  33      exit;
  34  }
  35  
  36  require_once(e_HANDLER."ren_help.php");
  37  
  38  if(is_readable(THEME."usersettings_template.php"))
  39  {
  40      include_once(THEME."usersettings_template.php");
  41  }
  42  else
  43  {
  44      include_once(e_THEME."templates/usersettings_template.php");
  45  }
  46  include_once(e_FILE."shortcode/batch/usersettings_shortcodes.php");
  47  
  48  require_once(e_HANDLER."calendar/calendar_class.php");
  49  $cal = new DHTML_Calendar(true);
  50  $sesschange = '';                        // Notice removal
  51  $photo_to_delete = '';
  52  $avatar_to_delete = '';
  53  
  54  $inp = USERID;
  55  $_uid = false;
  56  if(is_numeric(e_QUERY))
  57  {
  58      if(ADMIN)
  59      {
  60          $inp = (int)e_QUERY;
  61          $_uid = $inp;
  62          $info = get_user_data($inp);
  63          //Only site admin is able to change setting for other admins
  64          if(!is_array($info) || ($info['user_admin'] == 1 && (!defined('ADMINPERMS') || ADMINPERMS !== '0')))
  65          {
  66              header('location:'.e_BASE.'index.php');
  67            exit;
  68          }
  69      }
  70      else
  71      {
  72          //Non admin attempting to edit another user's ID
  73          header('location:'.e_BASE.'index.php');
  74        exit;
  75      }
  76  }
  77  
  78  require_once(HEADERF);
  79  
  80  // Given an array of user data, return a comma separated string which includes public, admin, member classes etc as appropriate.
  81  function addCommonClasses($udata)
  82  {
  83      $tmp = array();
  84      if ($udata['user_class'] != "") $tmp = explode(",", $udata['user_class']);
  85      $tmp[] = e_UC_MEMBER;
  86      $tmp[] = e_UC_READONLY;
  87      $tmp[] = e_UC_PUBLIC;
  88      if (($udata['user_admin'] == 1) || ADMIN)
  89      {
  90          $tmp[] = e_UC_ADMIN;
  91      }
  92      if ((strpos($udata['user_perms'],'0') === 0) || getperms('0'))
  93      {
  94          $tmp[] = e_UC_MAINADMIN;
  95      }
  96      return implode(",", $tmp);
  97  }
  98  
  99  
 100  // Save user settings (whether or not changed)
 101  //---------------------------------------------
 102  $error = "";
 103  
 104  if (isset($_POST['updatesettings']))
 105  {
 106      if(!varset($_POST['__referer']))
 107      {
 108          header('location:'.e_BASE.'index.php');
 109            exit;
 110      }
 111      
 112      if(!varsettrue($pref['auth_method']) || $pref['auth_method'] == '>e107')
 113      {
 114          $pref['auth_method'] = 'e107';
 115      }
 116  
 117      if($pref['auth_method'] != 'e107')
 118      {
 119          $_POST['password1'] = '';
 120          $_POST['password2'] = '';
 121      }
 122  
 123  /*
 124      if ($_uid && ADMIN)
 125      {    // Admin logged in and editing another user's settings - so editing a different ID
 126        $inp = $_uid;
 127        $remflag = TRUE;
 128      }
 129      else
 130      {    // Current user logged in - use their ID
 131        $inp = USERID;
 132      }
 133  */
 134  
 135  //    echo "inp = $inp <br />";
 136      $udata = get_user_data($inp);                // Get all the user data, including any extended fields
 137      $peer = ($inp == USERID ? false : true);
 138      $udata['user_classlist'] = addCommonClasses($udata);
 139  
 140  
 141      // Check external avatar
 142      $_POST['image'] = str_replace(array('\'', '"', '(', ')'), '', $_POST['image']);   // these are invalid anyway, so why allow them? (XSS Fix)
 143      if ($_POST['image'] && $size = getimagesize($_POST['image'])) {
 144          $avwidth = $size[0];
 145          $avheight = $size[1];
 146          $avmsg = "";
 147  
 148          $pref['im_width'] = ($pref['im_width']) ? $pref['im_width'] : 120;
 149          $pref['im_height'] = ($pref['im_height']) ? $pref['im_height'] : 100;
 150          if ($avwidth > $pref['im_width']) {
 151              $avmsg .= LAN_USET_1." ($avwidth)<br />".LAN_USET_2.": {$pref['im_width']}<br /><br />";
 152          }
 153          if ($avheight > $pref['im_height']) {
 154              $avmsg .= LAN_USET_3." ($avheight)<br />".LAN_USET_4.": {$pref['im_height']}";
 155          }
 156          if ($avmsg) {
 157              $_POST['image'] = "";
 158              $error = $avmsg;
 159          }
 160  
 161      }
 162  
 163      $signup_option_title = array(LAN_308, LAN_120, LAN_121, LAN_122, LAN_USET_6);
 164      $signup_option_names = array("realname", "signature", "image", "timezone", "class");
 165  
 166      foreach($signup_option_names as $key => $value)
 167      {  // Check required signup fields
 168          if ($pref['signup_option_'.$value] == 2 && !$_POST[$value] && !$_uid)
 169          {
 170              $error .= LAN_SIGNUP_6.$signup_option_title[$key].LAN_SIGNUP_7."\\n";
 171          }
 172      }
 173  
 174  
 175  // Login Name checks
 176      if (isset($_POST['loginname']))
 177      {  // Only check if its been edited %*|/|&nbsp;|\#|\=|\$%
 178          // another option would be /[^\w\pL\.]/u (non latin words)
 179          $temp_name = trim(preg_replace('#[^a-z0-9_\.]#i', "", strip_tags($_POST['loginname'])));
 180          if ($temp_name != $_POST['loginname'])
 181          {
 182              $error .= LAN_USET_13."\\n";
 183          }
 184          // Check if login name exceeds maximum allowed length
 185          if (strlen($temp_name) > varset($pref['loginname_maxlength'],30))
 186          {
 187              $error .= LAN_USET_14."\\n";
 188          }
 189          $_POST['loginname'] = $temp_name;
 190      }
 191  
 192  
 193  // Password checks
 194      $pwreset = "";
 195      if ($_POST['password1'] != $_POST['password2']) {
 196          $error .= LAN_105."\\n";
 197      }
 198      else
 199      {
 200          if(trim($_POST['password1']) != "")
 201          {
 202              $pwreset = "user_password = '".md5(trim($_POST['password1']))."', ";
 203          }
 204      }
 205  
 206      if(isset($pref['signup_disallow_text']))
 207      {
 208        $tmp = explode(",", $pref['signup_disallow_text']);
 209        foreach($tmp as $disallow)
 210        {
 211          if (($disallow != '') && strstr($_POST['username'], $disallow))
 212          {
 213            $error .= LAN_USET_11."\\n";
 214          }
 215        }
 216      }
 217  
 218      if (strlen(trim($_POST['password1'])) < $pref['signup_pass_len'] && trim($_POST['password1']) != "") {
 219          $error .= LAN_SIGNUP_4.$pref['signup_pass_len'].LAN_SIGNUP_5."\\n";
 220          $password1 = "";
 221          $password2 = "";
 222      }
 223  
 224  
 225  
 226  //--------------------------------------------
 227  //        Email address checks
 228  //--------------------------------------------
 229  // Split up an email address to check for banned domains.
 230  // Return false if invalid address
 231  function make_email_query($email, $fieldname = 'banlist_ip')
 232  {
 233    global $tp;
 234    $tmp = strtolower($tp -> toDB(trim(substr($email, strrpos($email, "@")+1))));
 235    if ($tmp == '') return FALSE;
 236    if (strpos($tmp,'.') === FALSE) return FALSE;
 237    $em = array_reverse(explode('.',$tmp));
 238    $line = '';
 239    $out = array($fieldname."='*@{$tmp}'");        // First element looks for domain as email address
 240    foreach ($em as $e)
 241    {
 242      $line = '.'.$e.$line;
 243      $out[] = $fieldname."='*{$line}'";
 244    }
 245    return implode(' OR ',$out);
 246  }
 247  
 248  
 249      // Always validate an email address if entered. If its blank, that's OK if checking disabled
 250      $_POST['email'] = $tp->toDB(trim(varset($_POST['email'],'')));
 251      $do_email_validate = (!varset($pref['disable_emailcheck'],FALSE)) || ($_POST['email'] !='');
 252      if ($do_email_validate)
 253      {
 254          if  (!check_email($_POST['email']))
 255          {
 256              $error .= LAN_106."\\n";
 257          }
 258  
 259          // Check Email address against banlist.
 260          $wc = make_email_query($_POST['email']);
 261          if ($wc) $wc = ' OR '.$wc;
 262  
 263          if (($wc === FALSE) || ($do_email_validate && $sql->db_Select("banlist", "*", "banlist_ip='".$_POST['email']."'".$wc)))
 264          {
 265              $error .= LAN_106."\\n";
 266          }
 267  
 268  
 269          // Check for duplicate of email address (always)
 270          if ($sql->db_Select("user", "user_name, user_email", "user_email='".$_POST['email']."' AND user_id !='".intval($inp)."' "))
 271          {
 272              $error .= LAN_408."\\n";
 273          }
 274      }
 275  
 276  
 277  
 278  
 279  // Display name checks
 280      if (isset($_POST['username']))
 281      {
 282        // Impose a minimum length on display name
 283        $username = trim(strip_tags($_POST['username']));
 284        if (strlen($username) < 2)
 285        {
 286          $error .= LAN_USET_12."\\n";
 287        }
 288        if (strlen($username) > varset($pref['displayname_maxlength'],15))
 289        {
 290          $error .= LAN_USET_15."\\n";
 291        }
 292  
 293      // Display Name exists.
 294        if ($sql->db_Count("user", "(*)", "WHERE `user_name`='".$username."' AND `user_id` != '".intval($inp)."' "))
 295        {
 296          $error .= LAN_USET_17;
 297        }
 298      }
 299  
 300  
 301  // Uploaded avatar and/or photo
 302      $user_sess = "";
 303      if ($file_userfile['error'] != 4)
 304      {
 305          require_once(e_HANDLER."upload_handler.php");
 306          require_once(e_HANDLER."resize_handler.php");
 307  
 308          if ($uploaded = file_upload(e_FILE."public/avatars/", "avatar=".$udata['user_id']))
 309          {
 310            foreach ($uploaded as $upload)
 311            {    // Needs the latest upload handler (with legacy and 'future' interfaces) to work
 312              if ($upload['name'] && ($upload['index'] == 'avatar') && $pref['avatar_upload'])
 313              {
 314                  // avatar uploaded - give it a reference which identifies it as server-stored
 315                  $_POST['image'] = "-upload-".$upload['name'];
 316                  if ($_POST['image'] != $udata['user_image'])
 317                  {
 318                    $avatar_to_delete = str_replace("-upload-", "", $udata['user_image']);
 319  //                  echo "Avatar change; deleting {$avatar_to_delete}<br />";
 320                  }
 321                  if (!resize_image(e_FILE."public/avatars/".$upload['name'], e_FILE."public/avatars/".$upload['name'], "avatar"))
 322                  {
 323                      unset($message);
 324                      $error .= RESIZE_NOT_SUPPORTED."\\n";
 325                      @unlink(e_FILE."public/avatars/".$upload['name']);
 326                      $_POST['image'] = '';
 327                  }
 328              }
 329  
 330              if ($upload['name'] && ($upload['index'] == 'photo') && $pref['photo_upload'] )
 331              {
 332                  // photograph uploaded
 333                  $user_sess = $upload['name'];
 334                  if (!resize_image(e_FILE."public/avatars/".$user_sess, e_FILE."public/avatars/".$user_sess, 180))
 335                  {
 336                      unset($message);
 337                      $error .= RESIZE_NOT_SUPPORTED."\\n";
 338                      @unlink(e_FILE."public/avatars/".$user_sess);
 339                      $user_sess = '';
 340                  }
 341              }
 342            }
 343          }
 344      }
 345  
 346  // See if user just wants to delete existing photo
 347      if (isset($_POST['user_delete_photo']))
 348      {
 349        $photo_to_delete = $udata['user_sess'];
 350        $sesschange = "user_sess = '', ";
 351  //      echo "Just delete old photo: {$photo_to_delete}<br />";
 352      }
 353      elseif ($user_sess != "")
 354      {    // Update DB with photo
 355        $sesschange = "user_sess = '".$tp->toDB($user_sess)."', ";
 356        if ($udata['user_sess'] == $tp->toDB($user_sess))
 357        {
 358          $sesschange = '';            // Same photo - do nothing
 359  //        echo "Photo not changed<br />";
 360        }
 361        else
 362        {
 363          $photo_to_delete = $udata['user_sess'];
 364  //        echo "New photo: {$user_sess} Delete old photo: {$photo_to_delete}<br />";
 365        }
 366      }
 367  
 368  
 369      // Validate Extended User Fields.
 370      $ue_fields = "";
 371      if($_POST['ue'])
 372      {
 373          if ($sql->db_Select('user_extended_struct', '*', 'order by user_extended_struct_type', 'order'))        // Get both field and category definitions
 374          {
 375              $skipCat = array();
 376              while($row = $sql->db_Fetch())
 377              {
 378                  if($row['user_extended_struct_type']) 
 379                  {    // Its a field
 380                      $extList["user_".$row['user_extended_struct_name']] = $row;
 381                  }
 382                  // else its a category
 383                  elseif(!check_class($row['user_extended_struct_applicable']) || !check_class($row['user_extended_struct_write'])) 
 384                  {
 385                      $skipCat[] = $row['user_extended_struct_id'];
 386                  }
 387              }
 388          }
 389  
 390          foreach ($extList as $key => $settings)
 391          {    // Only process field if its in a category relevant to this user, and this user should be able to change it
 392              if (!in_array($settings['user_extended_struct_parent'],$skipCat) && check_class($settings['user_extended_struct_applicable']) && check_class($settings['user_extended_struct_write']))
 393              {
 394                  $val = '';
 395                  if (isset($_POST['ue'][$key])) $val = $_POST['ue'][$key]; 
 396                  $err = $ue->user_extended_validate_entry($val,$settings);
 397                  if($err === TRUE && !$_uid)
 398                  {  // General error - usually empty field; could be unacceptable value, or regex fail and no error message defined
 399                      $error .= LAN_SIGNUP_6.($tp->toHtml($settings['user_extended_struct_text'],FALSE,'defs')).' '.LAN_SIGNUP_7."\\n";
 400                  }
 401                  elseif ($err)
 402                  {    // Specific error message returned - usually regex fail
 403                      $error .= $err."\\n";
 404                      $err = TRUE;
 405                  }
 406                  if(!$err)
 407                  {
 408                      $val = $tp->toDB($val);
 409                      $ue_fields .= ($ue_fields) ? ", " : "";
 410                      $ue_fields .= $key."='".$val."'";
 411                  }
 412              }
 413          }
 414  
 415          $ueHide = array();
 416          foreach (array_keys($_POST['hide']) as $key)
 417          {
 418              if (isset($extList[$key]))
 419              {
 420                  $ueHide[] = $tp->toDB($key);
 421              }
 422          }
 423      }
 424  
 425  
 426  // All validated here
 427  // ------------------
 428  
 429  // $inp - UID of user whose data is being changed (may not be the currently logged in user)
 430      if (!$error)
 431      {
 432        unset($_POST['password1']);
 433        unset($_POST['password2']);
 434  
 435  
 436        $_POST['user_id'] = intval($inp);
 437  
 438  
 439        $ret = $e_event->trigger("preuserset", $_POST);
 440  
 441        if(trim($_POST['user_xup']) != "")
 442        {
 443          if($sql->db_Select('user', 'user_xup', "user_id = '".intval($inp)."'"))
 444          {
 445            $row = $sql->db_Fetch();
 446            $update_xup = ($row['user_xup'] != $_POST['user_xup']) ? TRUE : FALSE;
 447          }
 448        }
 449  
 450        if ($ret == '')
 451        {
 452          $loginname = strip_tags($_POST['loginname']);
 453          if (!$loginname)
 454          {
 455            $loginname = $udata['user_loginname'];
 456          }
 457          else
 458          {
 459            if(!check_class($pref['displayname_class'], $udata['user_classlist'], $peer))
 460            {
 461              $new_username = "user_name = '{$loginname}', ";
 462              $username = $loginname;
 463            }
 464          }
 465  
 466  //            if (isset($_POST['username']) && check_class($pref['displayname_class']))
 467          if (isset($_POST['username']) && check_class($pref['displayname_class'], $udata['user_classlist'], $peer))
 468          {    // Allow change of display name if in right class
 469            $username = trim(strip_tags($_POST['username']));
 470            $username = $tp->toDB(substr($username, 0, $pref['displayname_maxlength']));
 471            $new_username = "user_name = '{$username}', ";
 472          }
 473  
 474  
 475          $_POST['signature'] = $tp->toDB($_POST['signature']);
 476          $_POST['realname'] = $tp->toDB($_POST['realname']);
 477  
 478          $new_customtitle = "";
 479          if(isset($_POST['customtitle']) && ($pref['forum_user_customtitle'] || ADMIN))
 480          {
 481              $new_customtitle = ", user_customtitle = '".$tp->toDB($_POST['customtitle'])."' ";
 482          }
 483  
 484  
 485          // Extended fields - handle any hidden fields
 486          if($ue_fields)
 487          {
 488              $hiddenFields = implode("^", $ueHide);
 489              if($hiddenFields != "")
 490              {
 491                  $hiddenFields = "^".$hiddenFields."^";
 492              }
 493              $ue_fields .= ", user_hidden_fields = '".$hiddenFields."'";
 494          }
 495  
 496  
 497          // We can update the basic user record now
 498          $sql->db_Update("user", "{$new_username} {$pwreset} {$sesschange} user_email='".$tp -> toDB($_POST['email'])."', user_signature='".$_POST['signature']."', user_image='".$tp -> toDB($_POST['image'])."', user_timezone='".$tp -> toDB($_POST['timezone'])."', user_hideemail='".intval($tp -> toDB($_POST['hideemail']))."', user_login='".$_POST['realname']."' {$new_customtitle}, user_xup='".$tp -> toDB($_POST['user_xup'])."' WHERE user_id='".intval($inp)."' ");
 499          if ($photo_to_delete)
 500          {    // Photo may be a flat file, or in the database
 501            delete_file($photo_to_delete);
 502          }
 503          if ($avatar_to_delete)
 504          {    // Avatar may be a flat file, or in the database
 505            delete_file($avatar_to_delete);
 506          }
 507  
 508  
 509          // If user has changed display name, update the record in the online table
 510          if(isset($username) && ($username != USERNAME) && !$_uid)
 511          {
 512            $sql->db_Update("online", "online_user_id = '".USERID.".".$username."' WHERE online_user_id = '".USERID.".".USERNAME."'");
 513          }
 514  
 515  
 516          // Only admins can update login name
 517          if(ADMIN && getperms("4"))
 518          {
 519            $sql -> db_Update("user", "user_loginname='".$tp -> toDB($loginname)."' WHERE user_id='".intval($inp)."' ");
 520          }
 521  
 522  
 523          // Save extended field values
 524          if($ue_fields)
 525          {
 526  // ***** Next line creates a record which presumably should be there anyway, so could generate an error
 527            $sql->db_Select_gen("INSERT INTO #user_extended (user_extended_id, user_hidden_fields) values ('".intval($inp)."', '')");
 528            $sql->db_Update("user_extended", $ue_fields." WHERE user_extended_id = '".intval($inp)."'");
 529          }
 530  
 531  
 532          // Update Userclass - only if its the user changing their own data (admins can do it another way)
 533          if (!$_uid && $sql->db_Select("userclass_classes", "userclass_id", "userclass_editclass IN (".USERCLASS_LIST.")"))
 534          {
 535            $ucList = $sql->db_getList();            // List of classes which this user can edit
 536            if (US_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Usersettings test","Read editable list. Current user classes: ".$udata['user_class'],FALSE,LOG_TO_ROLLING);
 537              $cur_classes = explode(",", $udata['user_class']);            // Current class membership
 538              $newclist = array_flip($cur_classes);                        // Array keys are now the class IDs
 539  
 540              // Update class list - we must take care to only change those classes a user can edit themselves
 541              foreach ($ucList as $c)
 542              {
 543                $cid = $c['userclass_id'];
 544                if(!in_array($cid, $_POST['class']))
 545                {
 546                  unset($newclist[$cid]);
 547                }
 548                else
 549                {
 550                  $newclist[$cid] = 1;
 551                }
 552              }
 553              $newclist = array_keys($newclist);
 554              $nid = implode(',', array_diff($newclist, array('')));
 555              if ($nid != $udata['user_class'])
 556              {
 557                if (US_DEBUG) $admin_log->e_log_event(10,debug_backtrace(),"DEBUG","Usersettings test","Write back classes; new list: ".$nid,FALSE,LOG_TO_ROLLING);
 558                $sql->db_Update("user", "user_class='".$nid."' WHERE user_id=".intval($inp));
 559              }
 560          }
 561  
 562  
 563          if($update_xup == TRUE)
 564          {
 565            require_once(e_HANDLER."login.php");
 566            userlogin::update_xup($inp, $_POST['user_xup']);
 567          }
 568  
 569          $e_event->trigger("postuserset", $_POST);
 570  
 571  
 572          if(e_QUERY == "update")
 573          {
 574            header("Location: index.php");
 575          }
 576          $message = "<div style='text-align:center'>".LAN_150."</div>";
 577          $caption = LAN_151;
 578        }
 579        else
 580        {    // Invalid data
 581          $message = "<div style='text-align:center'>".$ret."</div>";
 582          $caption = LAN_151;
 583        }
 584        unset($_POST);
 585      }
 586  }
 587  
 588  if ($error)
 589  {
 590      require_once(e_HANDLER."message_handler.php");
 591      message_handler("P_ALERT", $error);
 592      $adref = $_POST['adminreturn'];
 593  }
 594  
 595  // --- User data has been update here if appropriate ---
 596  
 597  if(isset($message))
 598  {
 599      $ns->tablerender($caption, $message);
 600  }
 601  
 602  // ---------------------
 603  
 604  
 605  $uuid = ($_uid) ? $_uid : USERID;
 606  
 607  $qry = "
 608  SELECT u.*, ue.* FROM #user AS u
 609  LEFT JOIN #user_extended AS ue ON ue.user_extended_id = u.user_id
 610  WHERE u.user_id='".intval($uuid)."'
 611  ";
 612  
 613  $sql->db_Select_gen($qry);
 614  $curVal=$sql->db_Fetch();
 615  $curVal['userclass_list'] = addCommonClasses($curVal);
 616  
 617  if($_POST && $error)
 618  {     // Fix for all the values being lost when an error occurred.
 619      foreach($_POST as $key => $val)
 620      {
 621          $curVal["user_".$key] = $tp->post_toForm($val);
 622      }
 623      foreach($_POST['ue'] as $key => $val)
 624      {
 625          $curVal[$key] = $tp->post_toForm($val);
 626      }
 627  }
 628  
 629  require_once(e_HANDLER."form_handler.php");
 630  $rs = new form;
 631  
 632  $text = (e_QUERY ? $rs->form_open("post", e_SELF."?".e_QUERY, "dataform", "", " enctype='multipart/form-data'") : $rs->form_open("post", e_SELF, "dataform", "", " enctype='multipart/form-data'"));
 633  
 634  if(e_QUERY == "update")
 635  {
 636      $text .= "<div class='fborder' style='text-align:center'><br />".str_replace("*","<span style='color:red'>*</span>",LAN_USET_9)."<br />".LAN_USET_10."<br /><br /></div>";
 637  }
 638  
 639  $text .= $tp->parseTemplate($USERSETTINGS_EDIT, TRUE, $usersettings_shortcodes);
 640  $text .= "<div>";
 641  
 642  $text .= "
 643      <input type='hidden' name='_uid' value='{$uuid}' />
 644      <input type='hidden' name='__referer' value='".POST_REFERER."' />
 645      </div>
 646      </form>
 647      ";
 648  
 649  $ns->tablerender(LAN_155, $text);
 650  
 651  deleteExpired(ADMIN);            // This will clean up the user and user_extended databases
 652  
 653  require_once(FOOTERF);
 654  
 655  
 656  
 657  // Delete 'expired' user records, clean up user_extended DB
 658  function deleteExpired($force = FALSE)
 659  {
 660      global $pref, $sql;
 661      $temp1 = 0;
 662      if (isset($pref['del_unv']) && $pref['del_unv'] && $pref['user_reg_veri'] != 2)
 663      {
 664          $threshold= intval(time() - ($pref['del_unv'] * 60));
 665          if (($temp1 = $sql->db_Delete('user', 'user_ban = 2 AND user_join < '.$threshold)) > 0) { $force = TRUE; }
 666      }
 667      if ($force)
 668      {    // Remove 'orphaned' extended user field records
 669          $sql->db_Select_gen("DELETE `#user_extended` FROM `#user_extended` LEFT JOIN `#user` ON `#user_extended`.`user_extended_id` = `#user`.`user_id`
 670                  WHERE `#user`.`user_id` IS NULL");
 671      }
 672      return $temp1;
 673  }
 674  
 675  
 676  //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
 677  
 678  function req($field) {
 679      global $pref;
 680      if ($field == 2)
 681      {
 682          $ret = "<span style='text-align:right;font-size:15px; color:red'> *</span>";
 683      }
 684      else
 685      {
 686          $ret = "";
 687      }
 688      return $ret;
 689  }
 690  //---------------------------------------------------------------------------------
 691  
 692  // Delete a file from the public directories. Return TRUE on success, FALSE on failure.
 693  // Also deletes from database if appropriate.
 694  function delete_file($fname, $dir = 'avatars/')
 695  {
 696    global $sql;
 697    if (!$fname) return FALSE;
 698  
 699    if (preg_match("#Binary (.*?)/#", $fname, $match))
 700    {
 701      return $sql -> db_Delete("rbinary", "binary_id='".$tp -> toDB($match[1])."'");
 702    }
 703    elseif (file_exists(e_FILE."public/".$dir.$fname))
 704    {
 705      unlink(e_FILE."public/".$dir.$fname);
 706      return TRUE;
 707    }
 708    return FALSE;
 709  }
 710  
 711  
 712  function headerjs() {
 713      global $cal;
 714      $script = "<script type=\"text/javascript\">
 715  		function addtext_us(sc){
 716          document.getElementById('dataform').image.value = sc;
 717          }
 718  
 719          </script>\n";
 720  
 721      $script .= $cal->load_files();
 722      return $script;
 723  }
 724  ?>


Generated: Tue Aug 3 00:19:13 2010
Open Source related documentation for developers.