Changeset 890

Show
Ignore:
Timestamp:
01/30/07 13:21:04 (2 years ago)
Author:
ben
Message:

When there's a problem with a required field not being included, the profile reloads with all submitted values intact (previously it would reset to blank). This is to prevent the user from doing damage to his or herself, the screen, other people, or, ultimately, us.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/profile/edit.php

    r880 r890  
    3131protect(1); 
    3232 
    33 global $page_owner, $metatags, $CFG; 
     33global $page_owner, $metatags, $CFG, $data; 
     34 
     35if (isset($_SESSION['profile:preload'])) { 
     36    $data['profile:preload'] = $_SESSION['profile:preload']; 
     37    unset($_SESSION['profile:preload']); 
     38
     39if (isset($_SESSION['profile:preload:access'])) { 
     40    $data['profile:preload:access'] = $_SESSION['profile:preload:access']; 
     41    unset($_SESSION['profile:preload:access']); 
     42
    3443         
    3544$title = run("profile:display:name", $page_owner) . " :: ". __gettext("Edit profile") .""; 
     
    9099                        $flabel = !empty($field[0]) ? $field[0] : ''; 
    91100                        $frequired = false; 
     101                        $fcat = __gettext("Main"); 
    92102                    // Otherwise map things the new way! 
    93103                    } else { 
     
    95105                        $flabel = $datatype->name; 
    96106                        $frequired = $datatype->required; 
     107                        if (empty($datatype->category)) { 
     108                            $fcat = __gettext("Main"); 
     109                        } else { 
     110                            $fcat = $datatype->category; 
     111                        } 
    97112                    } 
    98113                    if ($fname == $field && $frequired == true) { 
    99                         $requiredmissing[] = $flabel
     114                        $requiredmissing[] = sprintf(__gettext("%s (in category %s)"),$flabel,$fcat)
    100115                    } 
    101116                } 
     
    132147        } else { 
    133148             
     149            $savedata = array(); 
     150             
     151            foreach($insertvalues as $insertvalue) { 
     152                $savedata['profile:preload'][$insertvalue->name] = $insertvalue->value; 
     153                $savedata['profile:preload:access'][$insertvalue->name] = $insertvalue->access; 
     154            } 
    134155            foreach($requiredmissing as $key=> $missinglabel) { 
    135156                $message = ""; 
     
    139160                $message .= $missinglabel; 
    140161            } 
     162             
    141163            $messages[] = sprintf(__gettext("You need to fill in the following required fields: %s"),$message); 
    142164             
    143165            $updatedok = false; 
     166            $_SESSION['profile:preload'] = $savedata['profile:preload']; 
     167            $_SESSION['profile:preload:access'] = $savedata['profile:preload:access']; 
    144168        } 
    145169    } 
  • devel/profile/profile.class.php

    r883 r890  
    237237        } 
    238238             
    239         if (!isset($data['profile:preload'][$flabel])) { 
     239        if (!isset($data['profile:preload'][$fname])) { 
    240240            if (!$value = get_record('profile_data','name',$fname,'owner',$page_owner)) { 
    241241                $value = ""; 
     
    246246            $value = ""; 
    247247            $value->value = $data['profile:preload'][$fname]; 
    248             $value->access = $CFG->default_access; 
     248            if (!isset($data['profile:preload:access'][$fname])) { 
     249                $value->access = $CFG->default_access; 
     250            } else { 
     251                $value->access = $data['profile:preload:access'][$fname]; 
     252            } 
    249253             
    250254        }