public function update($uid, $data)
 {
     if (!is_uid($uid)) {
         return '非法UID';
     }
     $uid = (int) $uid;
     $msg = $this->_validate_userinfo($data);
     if ($msg !== TRUE) {
         return $msg;
     }
     $this->load->database();
     // 可更新项
     $arr = array('username', 'email', 'phone', 'password', 'salt', 'wechat', 'nickname', 'remark');
     $no_change = true;
     foreach ($arr as $field) {
         if (isset($data[$field])) {
             $this->db->set($field, $data[$field]);
             $no_change = false;
         }
     }
     if ($no_change) {
         $this->db->reset_query();
         return true;
     }
     $this->db->set('update_time', date_long());
     $this->db->where('uid', $uid);
     $this->db->limit(1);
     $this->db->update('admin_user');
 }
Exemple #2
0
function bottom_up_propagation_list($toFind, $db, $X = array(), $Hlist = array(), $toFindInfo = array())
{
    #this function will build a list where the keys are the parent ids and the values are the ids to which the permission propagates to
    global $timer;
    if (empty($toFindInfo) && $toFind != letter($toFind)) {
        $toFindInfo = s3info($GLOBALS['s3codes'][letter($toFind)], substr($toFind, 1, strlen($toFind)), $db);
        if (letter($toFind) == 'S') {
            ##Find also info on the rule because that is where object_id will be found
            $ruleInfo = s3info('rule', $toFindInfo['rule_id'], $db);
            $borrowed = array('subject', 'subject_id', 'verb', 'verb_id', 'object', 'object_id');
            foreach ($borrowed as $tmp) {
                $toFindInfo[$tmp] = $ruleInfo[$tmp];
            }
        }
        if (letter($toFind) == 'I') {
            $toFindInfo['collection_id'] = $toFindInfo['resource_class_id'];
            $toFindInfo['item_id'] = $toFindInfo['resource_id'];
        }
    }
    $coreLetter = letter($toFind);
    $idvalue = ereg_replace('^' . $coreLetter, '', $toFind);
    if (is_file($Hlist)) {
        $Hlist = unserialize(file_get_contents($Hlist));
    }
    #build propagation list screen s3db for the corresponding core element and builds the interaction list from the query result
    $element = $GLOBALS['s3codes'][$coreLetter];
    $table = $GLOBALS['s3tables'][$GLOBALS['s3codes'][$coreLetter]];
    $specific_id = $GLOBALS['COREletterInv'][$coreLetter];
    $table_id = $table . '_id';
    $mother_ids = $GLOBALS['inherit'][$specific_id];
    if (letter($toFind) == 'S' && $toFindInfo['object_id'] == '') {
        $mother_ids = array('rule_id', 'item_id');
    }
    if (letter($toFind) == 'R' && $toFindInfo['object_id'] == '') {
        $mother_ids = array('project_id', 'subject_id', 'verb_id');
    }
    if (!empty($mother_ids)) {
        $table_mother_ids = translate_id_to_tables($mother_ids, $element);
    } else {
        $table_mother_ids = array();
    }
    $sql = "select * from s3db_" . $table;
    $connector = " where";
    if ($idvalue) {
        $sql .= " " . $connector . " " . $table_id . " = '" . $idvalue . "'";
        $connector = " and";
    }
    if ($coreLetter == 'I') {
        $sql .= " " . $connector . " iid='1'";
    }
    if ($coreLetter == 'C') {
        $sql .= " " . $connector . " iid='0'";
    }
    $db->query($sql, __FILE__, __LINE__);
    while ($db->next_record()) {
        $id_value = $db->f($table_id);
        $newHlist = array();
        #newHlist is just a way to distinguish those ids whose parent have aleady been found and those that haven't. It should always be smaller or equal sized to Hlist because it only contains data discovered in the present iteration
        #organize Hlist by parent->children
        if (!empty($mother_ids)) {
            $sw_letter = '';
            foreach ($table_mother_ids as $i => $mother) {
                $sw_letter = $GLOBALS['COREletter'][$mother_ids[$i]];
                $sw_value = $db->f($mother);
                if ($mother == 'value') {
                    if (is_uid($sw_value)) {
                        $sw_letter = 'I';
                    }
                }
                if ($sw_letter != '' && $sw_value) {
                    $sw = $sw_letter . $sw_value;
                    $uid = $coreLetter . $id_value;
                    if (!is_array($Hlist[$sw])) {
                        $Hlist[$sw] = array();
                    }
                    if (!is_array($newHlist[$sw])) {
                        $newHlist[$sw] = array();
                    }
                    if (!in_array($uid, $Hlist[$sw])) {
                        array_push($Hlist[$sw], $uid);
                        array_push($newHlist[$sw], $uid);
                    }
                }
            }
        }
    }
    if ($timer) {
        $timer->setMarker('owner id found');
    }
    #There is another way to get to any id. The ones we have just found are the direct inheritance. Now we need to find those that were created on the permissions table - that is, the shared ones
    if ($toFind != $coreLetter) {
        $where_str = "uid='" . $toFind . "'";
    } else {
        $where_str = "uid " . $GLOBALS['regexp'] . " '^" . $toFind . "'";
    }
    $pSql = "select uid,shared_with from s3db_permission where " . $where_str . " and id not in (" . ereg_replace('\\*', $table_id, $sql) . ")";
    $db->query($pSql);
    while ($db->next_record()) {
        $sw = $db->f('shared_with');
        $uid = $db->f('uid');
        $possible_parents = $GLOBALS['inherit_code'][letter($uid)];
        if (in_array(letter($sw), $possible_parents)) {
            if (!is_array($Hlist[$sw])) {
                $Hlist[$sw] = array();
                $newHlist[$sw] = array();
            }
            if (!in_array($uid, $Hlist[$sw])) {
                array_push($Hlist[$sw], $uid);
                array_push($newHlist[$sw], $uid);
            }
        }
    }
    if ($timer) {
        $timer->setMarker('shared id found');
    }
    #now lets get all from parent category. If the range of Hlist keys is small, then it makes sense to only query those; otherwise, a query on all parent makes more sense.
    #save the var in disk
    $Hlist_file = $GLOBALS['uploads'] . 'Hlist' . rand(100, 200);
    @file_put_contents($Hlist_file, serialize($Hlist));
    @chmod($Hlist_file, 0777);
    if (count($newHlist) > 100) {
        #this is where newHlist is important: we avoind going through items in the list that we went through already
        if (!empty($mother_ids)) {
            foreach ($mother_ids as $mother_id) {
                $toFindM = letter($mother_id);
                $Hlist = top_down_propagation_list($toFindM, array($mother_id), $db, $Hlist_file, $toFindInfo);
            }
        }
    } else {
        if (!empty($newHlist) && !empty($mother_ids)) {
            foreach ($newHlist as $parent_id => $kids) {
                #$Hlist = bottom_up_propagation_list($parent_id, $db,$X,$Hlist_file);
                $tmpList = bottom_up_propagation_list($parent_id, $db, $X, $Hlist);
                $Hlist = array_merge($Hlist, $tmpList);
            }
        }
    }
    return $Hlist;
}