added user icon upload
This commit is contained in:
		| @ -368,7 +368,7 @@ class File extends Controller | |||||||
|  |  | ||||||
| 								if ($this->files->create ($login['id'], $file) === FALSE) | 								if ($this->files->create ($login['id'], $file) === FALSE) | ||||||
| 								{ | 								{ | ||||||
| 									unlink (CODEPOT_FILE_DIR . "/{$file->encname}"); | 									@unlink (CODEPOT_FILE_DIR . "/{$file->encname}"); | ||||||
| 									$data['message'] = 'DATABASE ERROR'; | 									$data['message'] = 'DATABASE ERROR'; | ||||||
| 									$data['file'] = $file; | 									$data['file'] = $file; | ||||||
| 									$this->load->view ($this->VIEW_EDIT, $data); | 									$this->load->view ($this->VIEW_EDIT, $data); | ||||||
|  | |||||||
| @ -157,13 +157,56 @@ class User extends Controller | |||||||
| 		$data['login'] = $login; | 		$data['login'] = $login; | ||||||
| 		$data['message'] = ''; | 		$data['message'] = ''; | ||||||
|  |  | ||||||
|  | 		$icon_fname = FALSE; | ||||||
|  | 		$uploaded_fname = FALSE; | ||||||
|  |  | ||||||
| 		if($this->input->post('settings')) | 		if($this->input->post('settings')) | ||||||
| 		{ | 		{ | ||||||
|  | 			if (array_key_exists ('icon_img_file_name', $_FILES)) | ||||||
|  | 			{ | ||||||
|  | 				$fname = $_FILES['icon_img_file_name']['name']; | ||||||
|  |  | ||||||
|  | 				if (strpos ($fname, ':') !== FALSE) | ||||||
|  | 				{ | ||||||
|  | 					$data['message'] = $this->lang->line ('FILE_MSG_NAME_NO_COLON'); | ||||||
|  | 					$data['file'] = $file; | ||||||
|  | 					$this->load->view ($this->VIEW_EDIT, $data); | ||||||
|  | 					return; | ||||||
|  | 				} | ||||||
|  |  | ||||||
|  | 				// delete all \" instances ...  | ||||||
|  | 				$_FILES['icon_img_file_name']['type'] =  | ||||||
|  | 					str_replace('\"', '', $_FILES['icon_img_file_name']['type']); | ||||||
|  | 				// delete all \\ instances ...   | ||||||
|  | 				$_FILES['icon_img_file_name']['type'] =  | ||||||
|  | 					str_replace('\\', '', $_FILES['icon_img_file_name']['type']); | ||||||
|  |  | ||||||
|  | 				$config['allowed_types'] = 'png'; | ||||||
|  | 				$config['upload_path'] = CODEPOT_USERICON_DIR; | ||||||
|  | 				$config['max_size'] = CODEPOT_MAX_UPLOAD_SIZE; | ||||||
|  | 				$config['max_width'] = 100; // TODO: make it configurable. | ||||||
|  | 				$config['max_height'] = 100; | ||||||
|  | 				$config['encrypt_name'] = TRUE; | ||||||
|  |  | ||||||
|  | 				$this->load->library ('upload'); | ||||||
|  | 				$this->upload->initialize ($config); | ||||||
|  | 		 | ||||||
|  | 				if ($this->upload->do_upload ('icon_img_file_name')) | ||||||
|  | 				{ | ||||||
|  | 					$upload = $this->upload->data (); | ||||||
|  | 					$uploaded_fname = $upload['file_name']; | ||||||
|  | 					$icon_fname = $login['id'] . '.png'; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  |  | ||||||
| 			$settings->code_hide_line_num = $this->input->post('code_hide_line_num'); | 			$settings->code_hide_line_num = $this->input->post('code_hide_line_num'); | ||||||
| 			$settings->code_hide_details = $this->input->post('code_hide_details'); | 			$settings->code_hide_details = $this->input->post('code_hide_details'); | ||||||
|  | 			$settings->icon_name = $icon_fname; | ||||||
|  | 			$settings->uploaded_icon_name = $uploaded_fname; | ||||||
|  |  | ||||||
| 			if ($this->users->storeSettings ($login['id'], $settings) === FALSE) | 			if ($this->users->storeSettings ($login['id'], $settings) === FALSE) | ||||||
| 			{ | 			{ | ||||||
|  | 				@unlink (CODEPOT_USERICON_DIR . '/' . $uploaded_fname); | ||||||
| 				$data['message'] = 'DATABASE ERROR'; | 				$data['message'] = 'DATABASE ERROR'; | ||||||
| 				$data['settings'] = $settings; | 				$data['settings'] = $settings; | ||||||
| 				$this->load->view ($this->VIEW_SETTINGS, $data); | 				$this->load->view ($this->VIEW_SETTINGS, $data); | ||||||
| @ -185,6 +228,7 @@ class User extends Controller | |||||||
| 				if ($settings === FALSE) $data['message'] = 'DATABASE ERROR'; | 				if ($settings === FALSE) $data['message'] = 'DATABASE ERROR'; | ||||||
| 				$settings->code_hide_line_num = ' '; | 				$settings->code_hide_line_num = ' '; | ||||||
| 				$settings->code_hide_details = ' '; | 				$settings->code_hide_details = ' '; | ||||||
|  | 				$settings->icon_name = ''; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			$data['settings'] = $settings; | 			$data['settings'] = $settings; | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ $lang['Head revision'] = 'Head revision'; | |||||||
| $lang['Hide details'] = 'Hide details'; | $lang['Hide details'] = 'Hide details'; | ||||||
| $lang['History'] = 'History'; | $lang['History'] = 'History'; | ||||||
| $lang['Home'] = 'Home'; | $lang['Home'] = 'Home'; | ||||||
|  | $lang['Icon'] = 'Icon'; | ||||||
| $lang['ID'] = 'ID'; | $lang['ID'] = 'ID'; | ||||||
| $lang['Issue'] = 'Issue'; | $lang['Issue'] = 'Issue'; | ||||||
| $lang['Issues'] = 'Issues'; | $lang['Issues'] = 'Issues'; | ||||||
|  | |||||||
| @ -32,6 +32,7 @@ $lang['Full Difference'] = 'FullDiff'; | |||||||
| $lang['Head revision'] = 'Kepala revisi'; | $lang['Head revision'] = 'Kepala revisi'; | ||||||
| $lang['History'] = 'Sejarah'; | $lang['History'] = 'Sejarah'; | ||||||
| $lang['Home'] = 'Beranda'; | $lang['Home'] = 'Beranda'; | ||||||
|  | $lang['Icon'] = 'Icon'; | ||||||
| $lang['ID'] = 'ID'; | $lang['ID'] = 'ID'; | ||||||
| $lang['Issue'] = 'Issue'; | $lang['Issue'] = 'Issue'; | ||||||
| $lang['Issues'] = 'Issue'; | $lang['Issues'] = 'Issue'; | ||||||
|  | |||||||
| @ -35,6 +35,7 @@ $lang['Head revision'] = '최신리비전'; | |||||||
| $lang['Hide details'] = '상세내역숨김'; | $lang['Hide details'] = '상세내역숨김'; | ||||||
| $lang['History'] = '변경기록'; | $lang['History'] = '변경기록'; | ||||||
| $lang['Home'] = '홈'; | $lang['Home'] = '홈'; | ||||||
|  | $lang['Icon'] = '아이콘'; | ||||||
| $lang['ID'] = '아이디'; | $lang['ID'] = '아이디'; | ||||||
| $lang['Issue'] = '이슈'; | $lang['Issue'] = '이슈'; | ||||||
| $lang['Issues'] = '이슈'; | $lang['Issues'] = '이슈'; | ||||||
|  | |||||||
| @ -35,6 +35,8 @@ class UserModel extends Model | |||||||
|  |  | ||||||
| 	function storeSettings ($userid, $settings) | 	function storeSettings ($userid, $settings) | ||||||
| 	{ | 	{ | ||||||
|  | 		$icon_name_set = strlen($settings->icon_name) > 0; | ||||||
|  |  | ||||||
| 		$this->db->trans_begin (); | 		$this->db->trans_begin (); | ||||||
|  |  | ||||||
| 		$this->db->where ('userid', $userid); | 		$this->db->where ('userid', $userid); | ||||||
| @ -52,6 +54,7 @@ class UserModel extends Model | |||||||
| 			$this->db->set ('userid', $userid); | 			$this->db->set ('userid', $userid); | ||||||
| 			$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | 			$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | ||||||
| 			$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | 			$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | ||||||
|  | 			if ($icon_name_set) $this->db->set ('icon_name', (string)$settings->icon_name); | ||||||
| 			$this->db->insert ('user_settings'); | 			$this->db->insert ('user_settings'); | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| @ -59,6 +62,7 @@ class UserModel extends Model | |||||||
| 			$this->db->where ('userid', $userid); | 			$this->db->where ('userid', $userid); | ||||||
| 			$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | 			$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | ||||||
| 			$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | 			$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | ||||||
|  | 			if ($icon_name_set) $this->db->set ('icon_name', (string)$settings->icon_name); | ||||||
| 			$this->db->update ('user_settings'); | 			$this->db->update ('user_settings'); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @ -68,6 +72,16 @@ class UserModel extends Model | |||||||
| 			return FALSE; | 			return FALSE; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if ($icon_name_set) | ||||||
|  | 		{ | ||||||
|  | 			if (@rename (CODEPOT_USERICON_DIR . '/' . $settings->uploaded_icon_name, | ||||||
|  | 			             CODEPOT_USERICON_DIR . '/' . $settings->icon_name) === FALSE) | ||||||
|  | 			{ | ||||||
|  | 				$this->db->trans_rollback (); | ||||||
|  | 				return FALSE; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  |  | ||||||
| 		$this->db->trans_commit (); | 		$this->db->trans_commit (); | ||||||
| 		return TRUE; | 		return TRUE; | ||||||
|  |  | ||||||
| @ -77,6 +91,7 @@ class UserModel extends Model | |||||||
| 		$this->db->where ('userid', $userid); | 		$this->db->where ('userid', $userid); | ||||||
| 		$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | 		$this->db->set ('code_hide_line_num', (string)$settings->code_hide_line_num); | ||||||
| 		$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | 		$this->db->set ('code_hide_details', (string)$settings->code_hide_details); | ||||||
|  | 		if (strlen($settings->icon_name) > 0) $this->db->set ('icon_name', (string)$settings->icon_name); | ||||||
| 		$this->db->update ('user_settings'); | 		$this->db->update ('user_settings'); | ||||||
|  |  | ||||||
| 		if ($this->db->trans_status() === FALSE) | 		if ($this->db->trans_status() === FALSE) | ||||||
|  | |||||||
| @ -61,7 +61,7 @@ $this->load->view ( | |||||||
|  |  | ||||||
| <div id="user_settings_mainarea_result"> | <div id="user_settings_mainarea_result"> | ||||||
|  |  | ||||||
| <?=form_open('user/settings/')?> | <?=form_open_multipart('user/settings/')?> | ||||||
|  |  | ||||||
| 	<?=form_fieldset($this->lang->line('Code'))?> | 	<?=form_fieldset($this->lang->line('Code'))?> | ||||||
|  |  | ||||||
| @ -74,6 +74,15 @@ $this->load->view ( | |||||||
| 			'Y', $settings->code_hide_details == 'Y') | 			'Y', $settings->code_hide_details == 'Y') | ||||||
| 		?> | 		?> | ||||||
| 		<?= $this->lang->line('USER_MSG_HIDE_DETAILS')?> | 		<?= $this->lang->line('USER_MSG_HIDE_DETAILS')?> | ||||||
|  |  | ||||||
|  | 		<div class='form_input_field'> | ||||||
|  | 			<?=form_label($this->lang->line('Icon').': ', 'icon_img_file_name')?> | ||||||
|  | 			<?php | ||||||
|  | 				$extra = 'maxlength="255" size="40"'; | ||||||
|  | 				print form_upload('icon_img_file_name', set_value('icon_img_file_name', ''), $extra); | ||||||
|  | 			?> | ||||||
|  | 			<?=form_error('icon_img_file_name');?> | ||||||
|  | 		</div> | ||||||
| 	 | 	 | ||||||
| 	<?=form_fieldset_close()?> | 	<?=form_fieldset_close()?> | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user