public function getAvatar($uid = 0, $size = 256) { $avatar = D('avatar')->where(array('uid' => $uid, 'status' => 1, 'is_temp' => 0))->find(); if ($avatar) { if ($avatar['driver'] == 'local') { $avatar_path = "/Uploads/Avatar" . $avatar['path']; return $this->getImageUrlByPath($avatar_path, $size); } else { $new_img = $avatar['path']; $name = get_addon_class($avatar['driver']); if (class_exists($name)) { $class = new $name(); if (method_exists($class, 'thumb')) { $new_img = $class->thumb($avatar['path'], $size, $size); } } return $new_img; } } else { //如果没有头像,返回默认头像 if ($uid == session('temp_login_uid') || $uid == is_login()) { $role_id = session('temp_login_role_id') ? session('temp_login_role_id') : get_role_id(); } else { $role_id = query_user('show_role', $uid); } return $this->getImageUrlByRoleId($role_id, $size); } }
/** * 构造用户配置表 D('UserConfig')查询条件 * @param string $name 表中name字段的值(配置标识) * @param string $model 表中model字段的值(模块标识) * @param int $uid 用户uid * @param int $role_id 登录的角色id * @return array 查询条件 $map * @author 郑钟良<*****@*****.**> */ function getUserConfigMap($name = '', $model = '', $uid = 0, $role_id = 0) { $uid = $uid ? $uid : is_login(); $role_id = $role_id ? $role_id : get_role_id($uid); $map = array(); //构造查询条件 $map['uid'] = $uid; $map['name'] = $name; $map['role_id'] = $role_id; $map['model'] = $model; return $map; }
public function getAvatar($uid = 0, $size = 256) { $avatar = M('avatar')->where(array('uid' => $uid, 'status' => 1, 'is_temp' => 0))->getField('path'); if ($avatar) { if (is_sae()) { $avatar_path = $avatar; } else { if (!is_bool(strpos($avatar, 'http://'))) { return $avatar . '/thumbnail/' . $size . 'x' . $size . '!'; } else { $avatar_path = "/Uploads/Avatar{$avatar}"; } } return $this->getImageUrlByPath($avatar_path, $size); } else { //如果没有头像,返回默认头像 $role_id = session('temp_login_role_id') ? session('temp_login_role_id') : get_role_id(); return $this->getImageUrlByRoleId($role_id, $size); } }
private function getRoleFieldIds($uid = null) { $role_id = get_role_id($uid); $fields_list = S('Role_Expend_Info_' . $role_id); if (!$fields_list) { $map_role_config = getRoleConfigMap('expend_field', $role_id); $fields_list = D('RoleConfig')->where($map_role_config)->getField('value'); if ($fields_list) { $fields_list = explode(',', $fields_list); S('Role_Expend_Info_' . $role_id, $fields_list, 600); } } return $fields_list; }
public function edit_expandinfo() { $field_list = $this->getRoleFieldIds(); if ($field_list) { $map_field['id'] = array('in', $field_list); } else { $this->error(L('_ERROR_INFO_SAVE_NONE_') . L('_EXCLAMATION_')); } $map_field['status'] = 1; $field_setting_list = D('field_setting')->where($map_field)->order('sort asc')->select(); if (!$field_setting_list) { $this->error(L('_ERROR_INFO_MODIFY_NONE_') . L('_EXCLAMATION_')); } $data = null; foreach ($field_setting_list as $key => $val) { $data[$key]['uid'] = session('temp_login_uid') ? session('temp_login_uid') : is_login(); $data[$key]['field_id'] = $val['id']; switch ($val['form_type']) { case 'input': $val['value'] = op_t($_POST['expand_' . $val['id']]); if (!$val['value'] || $val['value'] == '') { if ($val['required'] == 1) { $this->error($val['field_name'] . L('_ERROR_CONTENT_CANNOT_EMPTY_') . L('_EXCLAMATION_')); } } else { $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } } $data[$key]['field_data'] = $val['value']; break; case 'radio': $val['value'] = op_t($_POST['expand_' . $val['id']]); $data[$key]['field_data'] = $val['value']; break; case 'checkbox': $val['value'] = $_POST['expand_' . $val['id']]; if (!is_array($val['value']) && $val['required'] == 1) { $this->error(L('_ERROR_AT_LEAST_ONE_') . L('_COLON_') . $val['field_name']); } $data[$key]['field_data'] = is_array($val['value']) ? implode('|', $val['value']) : ''; break; case 'select': $val['value'] = op_t($_POST['expand_' . $val['id']]); $data[$key]['field_data'] = $val['value']; break; case 'time': $val['value'] = op_t($_POST['expand_' . $val['id']]); $val['value'] = strtotime($val['value']); $data[$key]['field_data'] = $val['value']; break; case 'textarea': $val['value'] = op_t($_POST['expand_' . $val['id']]); if (!$val['value'] || $val['value'] == '') { if ($val['required'] == 1) { $this->error($val['field_name'] . L('_ERROR_CONTENT_CANNOT_EMPTY_') . L('_EXCLAMATION_')); } } else { $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } } $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } $data[$key]['field_data'] = $val['value']; break; } } $map['uid'] = session('temp_login_uid') ? session('temp_login_uid') : is_login(); $map['role_id'] = session('temp_login_role_id') ? session('temp_login_role_id') : get_role_id($map['uid']); $result['status'] = 1; foreach ($data as $dl) { $dl['role_id'] = $map['role_id']; $map['field_id'] = $dl['field_id']; $res = D('field')->where($map)->find(); if (!$res) { if ($dl['field_data'] != '' && $dl['field_data'] != null) { $dl['createTime'] = $dl['changeTime'] = time(); if (!D('field')->add($dl)) { $result['info'] = L('_ERROR_INFO_ADD_') . L('_EXCLAMATION_'); $result['status'] = 0; } } } else { $dl['changeTime'] = time(); if (!D('field')->where('id=' . $res['id'])->save($dl)) { $result['info'] = L('_ERROR_INFO_MODIFY_') . L('_EXCLAMATION_'); $result['status'] = 0; } } unset($map['field_id']); } return $result; }
public function edit_expandinfo() { $field_list = $this->getRoleFieldIds(); if ($field_list) { $map_field['id'] = array('in', $field_list); } else { $this->error('没有要保存的信息!'); } $map_field['status'] = 1; $field_setting_list = D('field_setting')->where($map_field)->order('sort asc')->select(); if (!$field_setting_list) { $this->error('没有要修改的信息!'); } $data = null; foreach ($field_setting_list as $key => $val) { $data[$key]['uid'] = session('temp_login_uid') ? session('temp_login_uid') : is_login(); $data[$key]['field_id'] = $val['id']; switch ($val['form_type']) { case 'input': $val['value'] = op_t($_POST['expand_' . $val['id']]); if (!$val['value'] || $val['value'] == '') { if ($val['required'] == 1) { $this->error($val['field_name'] . '内容不能为空!'); } } else { $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } } $data[$key]['field_data'] = $val['value']; break; case 'radio': $val['value'] = op_t($_POST['expand_' . $val['id']]); $data[$key]['field_data'] = $val['value']; break; case 'checkbox': $val['value'] = $_POST['expand_' . $val['id']]; if (!is_array($val['value']) && $val['required'] == 1) { $this->error('请至少选择一个:' . $val['field_name']); } $data[$key]['field_data'] = is_array($val['value']) ? implode('|', $val['value']) : ''; break; case 'select': $val['value'] = op_t($_POST['expand_' . $val['id']]); $data[$key]['field_data'] = $val['value']; break; case 'time': $val['value'] = op_t($_POST['expand_' . $val['id']]); $val['value'] = strtotime($val['value']); $data[$key]['field_data'] = $val['value']; break; case 'textarea': $val['value'] = op_t($_POST['expand_' . $val['id']]); if (!$val['value'] || $val['value'] == '') { if ($val['required'] == 1) { $this->error($val['field_name'] . '内容不能为空!'); } } else { $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } } $val['submit'] = $this->_checkInput($val); if ($val['submit'] != null && $val['submit']['succ'] == 0) { $this->error($val['submit']['msg']); } $data[$key]['field_data'] = $val['value']; break; } } $map['uid'] = session('temp_login_uid') ? session('temp_login_uid') : is_login(); $map['role_id'] = session('temp_login_role_id') ? session('temp_login_role_id') : get_role_id($map['uid']); $result['status'] = 1; foreach ($data as $dl) { $dl['role_id'] = $map['role_id']; $map['field_id'] = $dl['field_id']; $res = D('field')->where($map)->find(); if (!$res) { if ($dl['field_data'] != '' && $dl['field_data'] != null) { $dl['createTime'] = $dl['changeTime'] = time(); if (!D('field')->add($dl)) { $result['info'] = '信息添加时出错!'; $result['status'] = 0; } } } else { $dl['changeTime'] = time(); if (!D('field')->where('id=' . $res['id'])->save($dl)) { $result['info'] = '信息修改时出错!'; $result['status'] = 0; } } unset($map['field_id']); } return $result; }