Todo   F
last analyzed

Complexity

Total Complexity 55

Size/Duplication

Total Lines 837
Duplicated Lines 6.09 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 66.27%

Importance

Changes 0
Metric Value
dl 51
loc 837
ccs 230
cts 347
cp 0.6627
rs 2.1621
c 0
b 0
f 0
wmc 55
lcom 2
cbo 0

29 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get_user_from_id() 0 10 1
A crypt_pass() 0 4 1
B add_reg() 0 43 1
A get_category_list() 13 13 1
A get_group_list() 0 4 1
B add_category() 0 38 4
B add_group() 0 28 2
A get_category_select() 12 12 2
A get_priority_select() 0 14 3
A get_group_select() 12 12 2
B validate_pass() 0 34 5
A update_pass() 0 7 1
A redirect_303() 0 10 2
A set_timezone() 0 8 1
A get_priorities() 0 9 1
A get_groups() 14 14 1
A get_user_account_by_id() 0 18 1
A get_user_group() 0 18 1
B get_friend_list() 0 33 1
A get_friends_in_group() 0 11 1
B update_group() 0 27 2
B del_group() 0 28 2
A del_cat() 0 19 2
A get_group_name_by_id() 0 11 1
C kanji_num() 0 68 8
A get_category() 0 12 1
A get_friend_requests() 0 18 2
B verify_user() 0 35 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Todo often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Todo, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * Public Library Todo
4
 *
5
 * Library for general tasks in Todo application
6
 * @package Todo
7
 */
8
class Todo {
9
10
	private $user, $pass, $uid; //For user registration
11
12
	/**
13
	 * @var MY_Controller
14
	 */
15
	protected $CI;
16
17
	/**
18
	 * Constructor
19
	 */
20 2
	public function __construct()
21
	{
22 2
		$this->CI =& get_instance();
23 2
	}
24
25
	// --------------------------------------------------------------------------
26
27
	/**
28
	 * Get User From Id
29
	 *
30
	 * Retrieve a user's username from their userid
31
	 * @param int $user_id
32
	 * @return string
33
	 */
34 10
	public function get_user_from_id($user_id)
35
	{
36 10
		$this->CI->db->select('id, username')
37 10
				->from('todo_user')
38 10
				->where('id', (int) $user_id);
39
40 10
		$res = $this->CI->db->get();
41 10
		$row = $res->row();
42 10
		return $row->username;
43
	}
44
45
	// --------------------------------------------------------------------------
46
47
	/**
48
	 * Crypt Pass
49
	 *
50
	 * Hashes passwords
51
	 * @param string $password
52
	 * @return string
53
	 */
54 1
	public function crypt_pass($password)
55
	{
56 1
		return password_hash($password, PASSWORD_BCRYPT);
57
	}
58
59
	// --------------------------------------------------------------------------
60
61
	/**
62
	 * Add Reg
63
	 *
64
	 * Submits a new user to the database
65
	 * @return integer
66
	 */
67
	public function add_reg()
68
	{
69
		$user = $this->CI->input->post('user', TRUE);
70
		$pass = $this->crypt_pass($this->CI->input->post('pass', TRUE));
71
		$email = $this->CI->input->post('email', TRUE);
72
73
		$this->CI->db->set('username', $user)
74
				->set('password', $pass)
75
				->set('email', $email);
76
		$this->CI->db->insert('user');
77
78
		//Get affected rows
79
		$affected_rows = $this->CI->db->affected_rows();
80
81
		//Get the userid of the latest user
82
		$res = $this->CI->db->select('MAX(id) as id')
83
				->from('user')
84
				->get();
85
86
		$row = $res->row();
87
		$this->uid = $row->id;
88
89
		//Add a group with the same name as the user
90
		$this->CI->db->set('name', $user)
91
			->insert('group');
92
93
		//Get the groupid of the latest group
94
		$res2 = $this->CI->db->select('MAX(id) as id')
95
				->from('group')
96
				->get();
97
98
		$row = $res2->row();
99
		$g_id = $row->id;
100
101
		//Set that user as the admin of that group
102
		$this->CI->db->set('group_id', $g_id)
103
			->set('user_id', $this->uid)
104
			->set('is_admin', 1)
105
			->insert('group_users_link');
106
107
		//Return affected rows
108
		return $affected_rows;
109
	}
110
111
	// --------------------------------------------------------------------------
112
113
	/**
114
	 * Get Categories
115
	 *
116
	 * Retrieves list of category types from the database
117
	 * @return array
118
	 */
119 3 View Code Duplication
	public function get_category_list()
120
	{
121 3
		$user_group_id  = $this->get_user_group();
122 3
		$cat = $this->CI->db->select('id,title,description,group_id')
123 3
			->from('category')
124 3
			->where('group_id', $user_group_id)
125 3
			->or_where('group_id', 0)
126 3
			->order_by('group_id', 'desc')
127 3
			->order_by('title', 'asc')
128 3
			->get();
129
130 3
		return $cat->result_array();
131
	}
132
133
	// --------------------------------------------------------------------------
134
135
	/**
136
	 * Get Group List
137
	 *
138
	 * An alias for the private get_groups method
139
	 * @param int
140
	 * @return array
141
	 */
142 2
	public function get_group_list($user_id)
143
	{
144 2
		return $this->get_groups($user_id);
145
	}
146
147
	// --------------------------------------------------------------------------
148
149
	/**
150
	 * Add Category
151
	 *
152
	 * Submits a new category to the database
153
	 * @return bool
154
	 */
155
	public function add_category()
156
	{
157
		if($this->CI->input->post('title') == FALSE || $this->CI->input->post('desc') == FALSE)
158
		{
159
			show_error('You must put a title and description!');
160
			return false;
161
		}
162
163
		$title = $this->CI->input->post('title', TRUE);
164
		$desc = $this->CI->input->post('desc', TRUE);
165
166
		//Check for the current category
167
		$this->CI->db->select('title')
168
			->from('category')
169
			->where('title', $title);
170
171
		$res = $this->CI->db->get();
172
173
		if($res->num_rows() == 0)
174
		{
175
			//Get the current user's primary group
176
			$group_id = $this->get_user_group();
177
178
			$this->CI->db->set('title', $title)
179
				->set('description', $desc)
180
				->set('group_id', $group_id);
181
182
			//Insert the new record
183
			$this->CI->db->insert('category');
184
			$this->CI->session->flashdata('message', 'Successfully added new category.');
185
			return true;
186
		}
187
		else
188
		{
189
			show_error('This category already exists!');
190
			return false;
191
		}
192
	}
193
194
	// --------------------------------------------------------------------------
195
196
	/**
197
	 * Add Group
198
	 *
199
	 * Submits a new group to the database
200
	 * @return bool
201
	 */
202
	public function add_group()
203
	{
204
		if($this->CI->input->post('name') == FALSE)
205
		{
206
			show_error('You must have a name for your new group!');
207
			return false;
208
		}
209
210
		$name = $this->CI->input->post('name');
211
212
		//Add group
213
		$this->CI->db->set("name", $name)->insert('group');
214
215
		//Get the groupid of the latest group
216
		$res = $this->CI->db->select('MAX(id) as id')
217
				->from('group')
218
				->get();
219
220
		$row = $res->row();
221
		$g_id = $row->id;
222
223
		//Set that user as the admin of that group
224
		$this->CI->db->set('group_id', $g_id)
225
			->set('user_id', $this->CI->session->userdata('uid'))
226
			->set('is_admin', 1)
227
			->insert('group_users_link');
228
229
	}
230
231
	// --------------------------------------------------------------------------
232
233
	/**
234
	 * Get Category Select
235
	 *
236
	 * Generates select options for categories when adding a new task
237
	 * @return string
238
	 */
239 2 View Code Duplication
	public function get_category_select()
240
	{
241 2
		$select_array = $this->get_category_list();
242 2
		$html = '';
243
244 2
		foreach($select_array as $r)
245
		{
246 2
			$html .= T4.'<option value="'.$r['id'].'">' . $r['title'] . '</option>'. "\n";
247 2
		}
248
249 2
		return $html;
250
	}
251
252
	// --------------------------------------------------------------------------
253
254
	/**
255
	 * Get Priority Select
256
	 *
257
	 * Generates select options for priorities when adding a new task
258
	 * @return string
259
	 */
260 1
	public function get_priority_select()
261
	{
262 1
		$select_array = $this->get_priorities();
263 1
		$html = '';
264
265 1
		foreach($select_array as $r)
266
		{
267 1
			$html .= T4.'<option value="'.$r['id'].'" ';
268 1
			$html .= ($r['id'] == 5) ? 'selected="selected">': '>';
269 1
			$html .= $r['value'] . '</option>'. "\n";
270 1
		}
271
272 1
		return $html;
273
	}
274
275
	// --------------------------------------------------------------------------
276
277
	/**
278
	 * Get Group Select
279
	 *
280
	 * Generates select options for groups when adding a friend
281
	 * @param int $user_id
282
	 * @return string
283
	 */
284 2 View Code Duplication
	public function get_group_select($user_id)
285
	{
286 2
		$select_array = $this->get_groups($user_id);
287 2
		$html = '';
288
289 2
		foreach($select_array as $r)
290
		{
291 1
			$html .= T4.'<option value="'.$r['id'].'">' . $r['name'] . '</option>'. "\n";
292 2
		}
293
294 2
		return $html;
295
	}
296
297
	// --------------------------------------------------------------------------
298
299
	/**
300
	 * Validate Pass
301
	 *
302
	 * Validate Password Change
303
	 * @return mixed
304
	 */
305 3
	public function validate_pass()
306
	{
307 3
		$err = array();
308 3
		$user = (int) $this->CI->session->userdata('uid');
309 3
		$pass = $this->CI->input->post('pass');
310 3
		$pass1 = $this->CI->input->post('pass1');
311 3
		$old_pass = $this->CI->input->post('old_pass');
312
313 3
		if($pass != $pass1)
314 3
			$err[] = "Passwords do not match.";
315
316
		//Check for current password in the database
317 3
		$user_check = $this->CI->db->select('password')
318 3
				->from('user')
319 3
				->where('id', $user)
320 3
				->get();
321
322 3
		$row = $user_check->row();
323
324 3
		if ( ! password_verify($old_pass, $row->password))
325 3
		{
326 1
			$err[] = "Wrong password";
327 1
		}
328
329 3
		$res = (empty($err)) ? true : $err;
330
331 3
		if($res == TRUE)
332 3
		{
333 3
			$this->user = $user;
334 3
			$this->pass = $pass;
335 3
		}
336
337 3
		return $res;
338
	}
339
340
	// --------------------------------------------------------------------------
341
342
	/**
343
	 * Update Pass
344
	 *
345
	 * Updates user's password in the database
346
	 */
347
	public function update_pass()
348
	{
349
		$pass = $this->crypt_pass($this->pass);
350
		$this->CI->db->set('password', $pass)
351
			->where('id', $this->user)
352
			->update('user');
353
	}
354
355
	// --------------------------------------------------------------------------
356
357
	/**
358
	 * Redirect 303
359
	 *
360
	 * Shortcut function for 303 redirect
361
	 * @param string $url
362
	 */
363 2
	public function redirect_303($url)
364
	{
365 2
		if (stripos($url, 'http') === FALSE)
366 2
		{
367 1
			$url = site_url($url);
368 1
		}
369
370 2
		$this->CI->output->set_header("HTTP/1.1 303 See Other");
371 2
		$this->CI->output->set_header("Location:" . $url);
372 2
	}
373
374
	// --------------------------------------------------------------------------
375
376
	/**
377
	 * Set Timezone
378
	 *
379
	 * Sets the timezone based on the user's settings
380
	 * @param int $uid
381
	 * @param string $timezone
382
	 * @return bool
383
	 */
384
	public function set_timezone($uid, $timezone)
385
	{
386
		$this->CI->db->set('timezone', $timezone)
387
			->where('id', $uid)
388
			->update('user');
389
390
		return ($this->CI->db->affected_rows == 1);
391
	}
392
393
	// --------------------------------------------------------------------------
394
395
	/**
396
	 * Get Priorities
397
	 *
398
	 * Retreives list of priority types from the database
399
	 * @return array
400
	 */
401 2
	public function get_priorities()
402
	{
403 2
		$pri = $this->CI->db->select('id,value')
404 2
					->from('priority')
405 2
					->order_by('id', 'asc')
406 2
					->get();
407
408 2
		return $pri->result_array();
409
	}
410
411
	// --------------------------------------------------------------------------
412
413
	/**
414
	 * Get Groups
415
	 *
416
	 * Retrieves user's groups from db
417
	 * @param int $user_id
418
	 * @return array
419
	 */
420 4 View Code Duplication
	private function get_groups($user_id)
421
	{
422 4
		$username = $this->get_user_from_id($user_id);
423 4
		$groups = $this->CI->db->select("group.id, name")
424 4
			->from('group')
425 4
			->join('group_users_link', 'group.id = group_users_link.group_id', 'inner')
426 4
			->where('user_id', $user_id)
427 4
			->where('name !=', $username)
428 4
			->where('is_admin', 1)
429 4
			->order_by('name')
430 4
			->get();
431
432 4
		return $groups->result_array();
433
	}
434
435
	// --------------------------------------------------------------------------
436
437
	/**
438
	 * Get User Account By Id
439
	 *
440
	 * Retrieves user's account info from db
441
	 * @param int $user_id
442
	 * @return array
443
	 */
444 3
	public function get_user_account_by_id($user_id)
445
	{
446 3
		$user_account = array();
447
448
		//Get the user
449 3
		$user_query = $this->CI->db->from('user')
450 3
			->where('id', (int) $user_id)
451 3
			->get();
452
453 3
		$user = $user_query->row();
454
455 3
		$user_account['timezone'] = $user->timezone;
456 3
		$user_account['user'] = $user->username;
457 3
		$user_account['email'] = $user->email;
458 3
		$user_account['num_format'] = $user->num_format;
459
460 3
		return $user_account;
461
	}
462
463
	// --------------------------------------------------------------------------
464
465
	/**
466
	 * Get User Group
467
	 *
468
	 * Gets the current user's primary group
469
	 * @return int
470
	 */
471 5
	public function get_user_group()
472
	{
473 5
		$user_id = $this->CI->session->userdata('uid');
474
475
		//Get the username
476 5
		$uname = $this->get_user_from_id($user_id);
477
478 5
		$group_query = $this->CI->db->select('group.id as group_id')
479 5
			->from('group')
480 5
			->where('name', $uname)
481 5
			->limit(1)
482 5
			->get();
483
484 5
		$group = $group_query->row();
485 5
		$group_id = $group->group_id;
486
487 5
		return $group_id;
488
	}
489
490
	// --------------------------------------------------------------------------
491
492
	/**
493
	 * Get Friend List
494
	 *
495
	 * Gets the friends of the current user
496
	 * @return array
497
	 */
498 3
	public function get_friend_list()
499
	{
500 3
		$user_id = $this->CI->session->userdata('uid');
501
502
		//Get the current user's username
503 3
		$uname = $this->CI->db->select('username')
504 3
			->from('user')
505 3
			->where('id', $user_id)
506 3
			->get();
507
508 3
		$user_n = $uname->row();
509
510 3
		$username = $user_n->username;
511
512
		//Get the list of friends
513 3
		$friends = $this->CI->db
514 3
			->select('user_friend_id,user_friend_link.user_id as uid,user.username')
515 3
			->from('todo_user_friend_link')
516 3
			->join('user', 'user.id=user_friend_link.user_friend_id OR todo_user.id=todo_user_friend_link.user_id', 'inner')
517 3
			->where('confirmed', FRIEND_CONFIRMED)
518 3
			->where('username !=', $username)
519
520 3
			->group_start()
521 3
			->where_in('todo_user_friend_link.user_id', $user_id)
522 3
			->or_where_in('todo_user_friend_link.user_friend_id', $user_id)
523 3
			->group_end()
524
525 3
			->order_by('username', 'asc')
526 3
			->get();
527
528 3
		return $friends->result_array();
529
530
	}
531
532
	// --------------------------------------------------------------------------
533
534
	/**
535
	 * Get Friends in Group
536
	 *
537
	 * Returns members of a group
538
	 * @param int $group_id
539
	 * @return array
540
	 */
541 1
	public function get_friends_in_group($group_id)
542
	{
543 1
		$friends = $this->CI->db
544 1
					->select('user_id')
545 1
					->from('group_users_link')
546 1
					->where('group_id', $group_id)
547 1
					->order_by('user_id')
548 1
					->get();
549
550 1
		return $friends->result_array();
551
	}
552
553
	// --------------------------------------------------------------------------
554
555
	/**
556
	 * Update group
557
	 *
558
	 * Updates a group's membership
559
	 */
560
	public function update_group()
561
	{
562
		$friends = $this->CI->input->post('friends');
563
		$group_name = $this->CI->input->post('group_name');
564
		$group_id = (int)$this->CI->uri->segment('3');
565
566
		//Drop members in group except the creator
567
		$this->CI->db->where('group_id', $group_id)
568
			->where('is_admin', 0)
569
			->delete('group_users_link');
570
571
		//Update the group name
572
		$this->CI->db->set('name', $group_name)
573
			->where('id', $group_id)
574
			->update('group');
575
576
		foreach ($friends as $friend)
577
		{
578
			//Insert new friends
579
			$this->CI->db->set('group_id', $group_id)
580
				->set('user_id', (int) $friend)
581
				->set('is_admin', 0)
582
				->insert('group_users_link');
583
		}
584
585
		return 1;
586
	}
587
588
	// --------------------------------------------------------------------------
589
590
	/**
591
	 * Del group
592
	 *
593
	 * Deletes a friend group
594
	 * @param int $group_id
595
	 * @return int
596
	 */
597
	public function del_group($group_id)
598
	{
599
		//Check if the current user is group admin
600
		$is_admin = $this->CI->db->from('group_users_link')
601
						->where('group_id', $group_id)
602
						->where('is_admin', 1)
603
						->get();
604
605
		//The user is admin
606
		if($is_admin->num_rows() > 0)
607
		{
608
			//Delete the related records
609
			$this->CI->db->where('group_id', $group_id)
610
					->delete('group_users_link');
611
			$this->CI->db->where('group_id', $group_id)
612
					->delete('group_task_link');
613
614
			//Delete the group
615
			$this->CI->db->where('id', $group_id)
616
					->delete('group');
617
618
			return 1;
619
		}
620
		else
621
		{
622
			return -1;
623
		}
624
	}
625
626
	// --------------------------------------------------------------------------
627
628
	/**
629
	 * Del Cat
630
	 *
631
	 * Deletes a task category
632
	 * @param int $cat_id
633
	 * @return int
634
	 */
635
	public function del_cat($cat_id)
636
	{
637
		//Get the user group id
638
		$gid = $this->get_user_group();
639
640
		//Delete the category that matches the cat_id and gid
641
		$this->CI->db->where('group_id', $gid)
642
			->where('id', $cat_id)
643
			->delete('category');
644
645
		if($this->CI->db->affected_rows() > 0)
646
		{
647
			return $this->CI->db->affected_rows();
648
		}
649
		else
650
		{
651
			return -1;
652
		}
653
	}
654
655
	// --------------------------------------------------------------------------
656
657
	/**
658
	 * Get group name by id
659
	 *
660
	 * Gets a group name from the group id
661
	 * @param int $group_id
662
	 * @return string
663
	 */
664 2
	public function get_group_name_by_id($group_id)
665
	{
666 2
		$query = $this->CI->db->select('name')
667 2
			->from('group')
668 2
			->where('id', (int) $group_id)
669 2
			->get();
670
671 2
		$qrow = $query->row();
672
673 2
		return $qrow->name;
674
	}
675
676
677
	// --------------------------------------------------------------------------
678
679
	/**
680
	 * Kanji Num
681
	 *
682
	 * Converts arabic to chinese number
683
	 * @param int $orig_number
684
	 * @return string
685
	 */
686 11
	public function kanji_num($orig_number)
687
	{
688 11
		$kanji_num = '';
689 11
		$number = (int) $orig_number;
690
691
		// Return early on a zero
692 11
		if ($number === 0) return ZERO;
693
694
		// Map variables to their values and characters
695
		$meta_map = [
696 9
			100000000 => HUNDRED_MILLION,
697 9
			10000 => TEN_THOUSAND,
698 9
			1000 => THOUSAND,
699 9
			100 => HUNDRED,
700
			10 => TEN
701 9
		];
702
703
		// Map values to their kanji equivalent
704
		$char_map = [
705 9
			1 => ONE,
706 9
			2 => TWO,
707 9
			3 => THREE,
708 9
			4 => FOUR,
709 9
			5 => FIVE,
710 9
			6 => SIX,
711 9
			7 => SEVEN,
712 9
			8 => EIGHT,
713 9
			9 => NINE,
714 9
		];
715
716
		// Go through each place value
717
		// to get the kanji equivalent of
718 9
		foreach($meta_map as $value => $char)
719
		{
720 9
			if ($number < $value) continue;
721
722
			// Calculate the place value variable
723 8
			$place_value = floor($number / $value);
724
725
			// Get the remainder for the next place value;
726 8
			$number = $number - ($place_value * $value);
727
728
			// Recurse if the number is between 11,000
729
			// and 100,000,000 to get the proper prefix,
730
			// which can be up to 9,999
731 8
			if ($orig_number > 10000 && $place_value > 9)
732 8
			{
733 4
				$kanji_num .= $this->kanji_num($place_value);
734 4
				$place_value = 1;
735 4
			}
736
737
			// Add place value character and
738
			// place value to the output string,
739
			// skipping zero and one. A zero value
740
			// hides the place value character, and one
741
			// value is implied if there is no value
742
			// prefixing the place value character
743 8
			$kanji_num .= ($place_value > 1)
744 8
				? $char_map[$place_value] . $char
745 8
				: $char;
746 9
		}
747
748
		// Add the smallest place value last, as a
749
		// one value is significant here
750 9
		$kanji_num .= ($number > 0) ? $char_map[$number] : '';
751
752 9
		return $kanji_num;
753
	}
754
755
	// --------------------------------------------------------------------------
756
757
	/**
758
	 * Get Category
759
	 *
760
	 * Returns a category from id
761
	 * @param int $cat_id
762
	 * @return array
763
	 */
764 3
	public function get_category($cat_id)
765
	{
766 3
		$cats = $this->CI->db->select('title, description')
767 3
			->from('category')
768 3
			->where('id', $cat_id)
769 3
			->limit('1')
770 3
			->get();
771
772 3
		$cat = $cats->row_array();
773
774 3
		return $cat;
775
	}
776
777
	// --------------------------------------------------------------------------
778
779
	/**
780
	 * Get Friend Requests
781
	 *
782
	 * Retrieves number of friend requests for the current user
783
	 * @return int
784
	 */
785 1
	public function get_friend_requests()
786
	{
787 1
		static $requests = NULL;
788
789 1
		if (is_null($requests))
790 1
		{
791
			//Get friend requests for the current user
792 1
			$requests = $this->CI->db->select('user_id')
793 1
				->distinct()
794 1
				->from('user_friend_link')
795 1
				->where('user_friend_id', $this->CI->session->userdata('uid'))
796 1
				->where('confirmed', -1)
797 1
				->get()
798 1
				->num_rows();
799 1
		}
800
801 1
		return $requests;
802
	}
803
804
	/**
805
	 * Authenticate the user
806
	 *
807
	 * @return string
808
	 */
809 3
	public function verify_user()
810
	{
811 3
		$user = $this->CI->input->post('user');
812 3
		$pass = $this->CI->input->post('pass');
813
814
		//Check for the user in the database
815 3
		$uid_check = $this->CI->db->select('id, username, email, password, timezone, num_format')
816 3
			->from('user')
817 3
			->group_start()
818 3
			->where('email', $user)
819 3
			->or_where('username', $user)
820 3
			->group_end()
821 3
			->get();
822
823 3
		$row = $uid_check->row();
824
825 3
		if (password_verify($pass, $row->password))
826 3
		{
827 2
			$this->CI->session->set_userdata('uid', $row->id);
828 2
			$this->CI->session->set_userdata('num_format', $row->num_format);
829 2
			$this->CI->session->set_userdata('username', $row->username);
830
			//Set Timezone
831 2
			$zone = $row->timezone;
832 2
			$tz_set = date_default_timezone_set($zone);
833
834 2
			if($tz_set == FALSE) display_error('Could not set timezone');
835
836
			//Redirect to task list
837 2
			return TRUE;
838
		}
839
		else
840
		{
841 1
			return  "Invalid username or password";
842
		}
843
	}
844
}
845
// End of libraries/Todo.php