Changeset 266


Ignore:
Timestamp:
Jul 3, 2007 8:41:36 AM (17 years ago)
Author:
quinn
Message:

Bugfixes found during strangecode site upgrade.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • tags/2.0.2/lib/Auth_SQL.inc.php

    r251 r266  
    577577
    578578    /**
    579      * This sets the 'blocked' field for a user in the db_table, and also
    580      * adds an optional reason
    581      *
    582      * @param  string   $reason      The reason for blocking the account.
     579     * Tests if the "blocked" flag is set for a user.
     580     *
     581     * @param  int      $user_id    User id to look for.
     582     * @return boolean              True if the user is blocked, false otherwise.
    583583     */
    584584    function isBlocked($user_id=null)
  • trunk/bin/module_maker/validation.cli.php

    r151 r266  
    184184        }
    185185        if ($max_length > 0 && $len_type == 'setenum') {
    186             $o[] = "\$fv->stringLength('$field', 0, $max_length, _(\"$title has an invalid selection.\"));";
     186            $o[] = "\$fv->stringLength('$field', 0, $max_length, sprintf(_(\"%s has an invalid selection.\"), _(\"$title\")));";
    187187        }
    188188        if ($max_length > 0 && $len_type == 'string') {
     
    241241        case 'date' :
    242242        case 'datetime' :
    243             // \$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$field\")));
    244             $o[] = "\$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$field\")));";
    245             $o[] = "\$fv->checkRegex('$field', '/^\d{4}-\d{2}-\d{2}$/', true, sprintf(_(\"%s must be in YYYY-MM-DD format.\"), _(\"$field\")));";
     243            // \$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$title\")));
     244            $o[] = "\$fv->validateStrDate('$field', sprintf(_(\"%s must be a valid date in YYYY-MM-DD format.\"), _(\"$title\")));";
     245            $o[] = "\$fv->checkRegex('$field', '/^\d{4}-\d{2}-\d{2}$/', true, sprintf(_(\"%s must be in YYYY-MM-DD format.\"), _(\"$title\")));";
    246246            break;
    247247
    248248        case 'timestamp' :
    249             $o[] = "\$fv->checkRegex('$field', '/^\d{14}$/', true, sprintf(_(\"%s must be a valid mysql timestamp in YYYYMMDDhhmmss format.\"), _(\"$field\")));";
     249            $o[] = "\$fv->checkRegex('$field', '/^\d{14}$/', true, sprintf(_(\"%s must be a valid mysql timestamp in YYYYMMDDhhmmss format.\"), _(\"$title\")));";
    250250            break;
    251251
    252252        case 'time' :
    253             $o[] = "\$fv->checkRegex('$field', '/^\d{1,3}:\d{2}:\d{2}$/', true, sprintf(_(\"%s must be a valid time in hh:mm:ss format.\"), _(\"$field\")));";
     253            $o[] = "\$fv->checkRegex('$field', '/^\d{1,3}:\d{2}:\d{2}$/', true, sprintf(_(\"%s must be a valid time in hh:mm:ss format.\"), _(\"$title\")));";
    254254            break;
    255255
    256256        case 'year' :
    257             $o[] = "\$fv->checkRegex('$field', '/^\d{4}$/', true, sprintf(_(\"%s must be a valid year in YYYY format.\"), _(\"$field\")));";
     257            $o[] = "\$fv->checkRegex('$field', '/^\d{4}$/', true, sprintf(_(\"%s must be a valid year in YYYY format.\"), _(\"$title\")));";
    258258            break;
    259259
  • trunk/docs/upgrade_v1-to-v2.mysql

    r261 r266  
    11## Update user_tbl.
    2 ## (If it exists.)
    3 # ALTER TABLE `user_tbl` ADD modified_by_user_id smallint(11) default NULL AFTER added_by_user_id;
    4 # ALTER TABLE `user_tbl` MODIFY added_datetime datetime NOT NULL default '0000-00-00 00:00:00' AFTER modified_by_user_id;
    5 # ALTER TABLE `user_tbl` ADD modified_datetime datetime NOT NULL default '0000-00-00 00:00:00' AFTER added_datetime;
     2## (If it exists!)
     3ALTER TABLE `user_tbl` ADD modified_by_user_id smallint(11) default NULL AFTER added_by_user_id;
     4ALTER TABLE `user_tbl` MODIFY added_datetime datetime NOT NULL default '0000-00-00 00:00:00' AFTER modified_by_user_id;
     5ALTER TABLE `user_tbl` ADD modified_datetime datetime NOT NULL default '0000-00-00 00:00:00' AFTER added_datetime;
    66
    77## Update admin_tbl.
    8 ALTER TABLE `admin_tbl` ADD login_abuse_exempt enum('true') default NULL AFTER priv;
     8## NOTE: This first one might need customizing.
     9ALTER TABLE `admin_tbl` CHANGE priv user_type enum('root','admin','editor') default NULL;
     10
     11ALTER TABLE `admin_tbl` ADD login_abuse_exempt enum('true') default NULL AFTER user_type;
    912ALTER TABLE `admin_tbl` ADD blocked enum('true') default NULL AFTER login_abuse_exempt;
    1013ALTER TABLE `admin_tbl` ADD blocked_reason varchar(255) NOT NULL default '' AFTER blocked;
     
    2225## Rename added_by_admin_id -> added_by_user_id in all tables.
    2326## Changing these will require source code modifications.
    24 ALTER TABLE `client_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
    25 ALTER TABLE `config_event_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
    26 ALTER TABLE `invoice_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
    27 ALTER TABLE `payment_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
    28 ALTER TABLE `site_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
     27## This is just an EXAMPLE!
     28# ALTER TABLE `client_tbl` CHANGE added_by_admin_id added_by_user_id smallint(11) default NULL;
  • trunk/lib/Auth_SQL.inc.php

    r259 r266  
    638638
    639639    /**
     640     * Tests if the "blocked" flag is set for a user.
     641     *
     642     * @param  int      $user_id    User id to look for.
     643     * @return boolean              True if the user is blocked, false otherwise.
     644     */
     645    function isBlocked($user_id=null)
     646    {
     647        $db =& DB::getInstance();
     648
     649        $this->initDB();
     650
     651        if ($this->getParam('blocking')) {
     652            // Get user_id if specified.
     653            $user_id = isset($user_id) ? $user_id : $this->getVal('user_id');
     654            $qid = $db->query("
     655                SELECT 1
     656                FROM " . $this->_params['db_table'] . "
     657                WHERE blocked = 'true'
     658                AND " . $this->_params['db_primary_key'] . " = '" . $db->escapeString($user_id) . "'
     659            ");
     660            return mysql_num_rows($qid) === 1;
     661        }
     662    }
     663
     664    /**
    640665     * Unblocks a user in the db_table, and clears any blocked_reason.
    641666     */
     
    902927    /**
    903928     * If the current user has access to the specified $security_zone, return true.
    904      * If the optional $priv is supplied, test that against the zone.
     929     * If the optional $user_type is supplied, test that against the zone.
     930     *
     931     * NOTE: "user_type" used to be called "priv" in some older implementations.
    905932     *
    906933     * @param  constant $security_zone   string of comma delimited priviliges for the zone
    907      * @param  string   $priv            a privilege that might be found in a zone
     934     * @param  string   $user_type       a privilege that might be found in a zone
    908935     * @return bool     true if user is a member of security zone, false otherwise
    909936     */
    910     function inClearanceZone($security_zone, $priv='')
     937    function inClearanceZone($security_zone, $user_type='')
    911938    {
    912939        return true;
    913940        $zone_members = preg_split('/,\s*/', $security_zone);
    914         $priv = empty($priv) ? $this->get('priv') : $priv;
     941        $user_type = empty($user_type) ? $this->get('user_type') : $user_type;
    915942
    916943        // If the current user's privilege level is NOT in that array or if the
    917944        // user has no privilege, return false. Otherwise the user is clear.
    918         if (!in_array($priv, $zone_members) || empty($priv)) {
     945        if (!in_array($user_type, $zone_members) || empty($user_type)) {
    919946            return false;
    920947        } else {
     
    926953     * This function tests a list of arguments $security_zone against the priv that the current user has.
    927954     * If the user doesn't have one of the supplied privs, die.
     955     *
     956     * NOTE: "user_type" used to be called "priv" in some older implementations.
    928957     *
    929958     * @param  constant $security_zone   string of comma delimited priviliges for the zone
     
    938967        /* If the current user's privilege level is NOT in that array or if the
    939968         * user has no privilege, DIE with a message. */
    940         if (!in_array($this->get('priv'), $zone_members) || !$this->get('priv')) {
     969        if (!in_array($this->get('user_type'), $zone_members) || !$this->get('user_type')) {
    941970            $message = empty($message) ? _("You have insufficient privileges to view that page.") : $message;
    942971            $app->raiseMsg($message, MSG_NOTICE, __FILE__, __LINE__);
  • trunk/lib/FormValidator.inc.php

    r241 r266  
    4040class FormValidator extends Validator {
    4141
     42    // Class parameters.
     43    var $_params = array(
     44        'error' => ' sc-msg-error ',
     45        'warning' => ' sc-msg-warning ',
     46        'notice' => ' sc-msg-notice ',
     47        'success' => ' sc-msg-success ',
     48    );
     49
    4250    // Array filling with error messages.
    4351    var $errors = array();
     52   
     53    /**
     54     * Set (or overwrite existing) parameters by passing an array of new parameters.
     55     *
     56     * @access public
     57     * @param  array    $params     Array of parameters (key => val pairs).
     58     */
     59    function setParam($params)
     60    {
     61        $app =& App::getInstance();
     62   
     63        if (isset($params) && is_array($params)) {
     64            // Merge new parameters with old overriding only those passed.
     65            $this->_params = array_merge($this->_params, $params);
     66        } else {
     67            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     68        }
     69    }
     70
     71    /**
     72     * Return the value of a parameter, if it exists.
     73     *
     74     * @access public
     75     * @param string $param        Which parameter to return.
     76     * @return mixed               Configured parameter value.
     77     */
     78    function getParam($param)
     79    {
     80        $app =& App::getInstance();
     81   
     82        if (isset($this->_params[$param])) {
     83            return $this->_params[$param];
     84        } else {
     85            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     86            return null;
     87        }
     88    }
    4489   
    4590    /**
     
    164209                case MSG_ERR:
    165210                default:
    166                     echo ' sc-msg-error ';
     211                    echo $this->getParam('error');
    167212                    break;
    168213
    169214                case MSG_WARNING:
    170                     echo ' sc-msg-warning ';
     215                    echo $this->getParam('warning');
    171216                    break;
    172217
     218                case MSG_NOTICE:
     219                    echo $this->getParam('notice');
     220                    break;
     221
    173222                case MSG_SUCCESS:
    174                     echo ' sc-msg-success ';
    175                     break;
    176 
    177                 case MSG_NOTICE:
    178                     echo ' sc-msg-notice ';
     223                    echo $this->getParam('success');
    179224                    break;
    180225                }
  • trunk/lib/Validator.inc.php

    r247 r266  
    208208        $timestamp = strtotime($val);
    209209        // Return values change between php4 and php5.
    210         if ($timestamp === -1 || $timestamp === false) {
     210        if ('' != trim($val) && ($timestamp === -1 || $timestamp === false)) {
    211211            return false;
    212212        } else {
  • trunk/services/admins.php

    r202 r266  
    8686    // Initialize variables for the form template.
    8787    $frm =& addRecordForm();
    88     $nav->add(_("Add Admin"));
     88    $nav->add(_("Add Administrator"));
    8989    $main_template = 'admin_form.ihtml';
    9090    break;
     
    9393    // Initialize variables for the form template.
    9494    $frm =& editRecordForm(getFormData('admin_id'));
    95     $nav->add(_("Edit Admin"));
     95    $nav->add(_("Edit Administrator"));
    9696    $main_template = 'admin_form.ihtml';
    9797    break;
     
    120120        $frm =& addRecordForm();
    121121        $frm = array_merge($frm, getFormData());
    122         $nav->add(_("Add Admin"));
     122        $nav->add(_("Add Administrator"));
    123123        $main_template = 'admin_form.ihtml';
    124124    } else {
     
    156156        $frm =& editRecordForm(getFormData('admin_id'));
    157157        $frm = array_merge($frm, getFormData());
    158         $nav->add(_("Edit Admin"));
     158        $nav->add(_("Edit Administrator"));
    159159        $main_template = 'admin_form.ihtml';
    160160    } else {
     
    254254        'new_op' => 'insert',
    255255        'submit_buttons' => array(
    256             'submit' => _("Add Admin"),
     256            'submit' => _("Add Administrator"),
    257257            'repeat' => _("Add & repeat"),
    258258            'cancel' => _("Cancel"),
     
    408408    $version->create('admin_tbl', 'admin_id', $last_insert_id, $frm['username']);
    409409
    410     $app->raiseMsg(sprintf(_("The Admin <em>%s</em> has been added."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
     410    $app->raiseMsg(sprintf(_("The Administrator <em>%s</em> has been added."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
    411411
    412412    return $last_insert_id;
     
    452452    $version->create('admin_tbl', 'admin_id', $frm['admin_id'], $frm['username']);
    453453
    454     $app->raiseMsg(sprintf(_("The Admin <em>%s</em> has been updated."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
     454    $app->raiseMsg(sprintf(_("The Administrator <em>%s</em> has been updated."), $frm['username']), MSG_SUCCESS, __FILE__, __LINE__);
    455455
    456456    // Unlock record.
     
    523523    // First try to return from the cache.
    524524    if ($cache->exists('list')) {
    525         return $cache->get('list');
     525        $list = $cache->get('list');
     526        return $list;
    526527    }
    527528   
Note: See TracChangeset for help on using the changeset viewer.