Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. public function user() {
  2.  
  3. $this->init();
  4.  
  5. $this->load->model('user');
  6.  
  7. $user_rows = $this->user->get_user_rows();
  8. if ($user_rows === false) {
  9. $this->json_error($this->user->message);
  10. return;
  11. }
  12.  
  13. $this->data['user_rows'] = $user_rows;
  14.  
  15. $this->load->view('admin', $this->data);
  16. }
  17.  
  18. public function create_user() {
  19. $this->init();
  20.  
  21. $this->load->view('add_user', $this->data);
  22. }
  23.  
  24. public function create_user_submit() {
  25. $this->init();
  26.  
  27. $this->load->model('user');
  28. $this->load->model('user_profile');
  29.  
  30. $post = array(
  31. 'name' => rawurldecode($_POST['name']),
  32. 'ic' => rawurldecode($_POST['ic']),
  33. 'email' => rawurldecode($_POST['email']),
  34. 'tele' => rawurldecode($_POST['telephone']),
  35. 'tittle' => rawurldecode($_POST['tittle']),
  36. 'username' => rawurldecode($_POST['username']),
  37. 'password' => rawurldecode($_POST['password'])
  38.  
  39. );
  40.  
  41.  
  42.  
  43. $data = $this->user->trans_user_profile($username, $password, $user_create, $pro_id,$pro_name,$pro_ic,$pro_email,$pro_mobile,$pro_tittle,$pro_create);
  44.  
  45. $new_user = $this->user->create_user($post['username'], $post['password'], $this->login['user_name']);
  46. if($new_user === false){
  47. $this->json_error($this->user->message);
  48. return;
  49. }
  50.  
  51.  
  52. $this->json_ok();
  53. }
  54.  
  55. public function trans_user_profile($username, $password, $user_create, $pro_id,$pro_name,$pro_ic,$pro_email,$pro_mobile,$pro_tittle,$pro_create) {
  56. $this->load->model('user_profile');
  57.  
  58. $this->db->trans_start();
  59.  
  60. $create_user = $this->create_user($username, $password, $user_create, $pro_id);
  61. if ($create_user === false) {
  62. $this->message = $this->db->_error_message();
  63. }
  64.  
  65. $create_user_profile = $this->user_profile->create_user_profile($pro_name, $pro_ic, $pro_email, $pro_mobile, $pro_tittle, $pro_create);
  66. if ($create_user_profile === false) {
  67. $this->message = $this->db->_error_message();
  68. }
  69.  
  70. $this->db->trans_complete();
  71.  
  72. if ($this->db->trans_status() === false){
  73. return false;
  74. }
  75.  
  76. return true;
  77. }
  78.  
  79. public function create_user($username, $password, $user_create, $pro_id) {
  80. $this->load->database();
  81.  
  82. $user = $this->get_user_name_row_case_insensitive($username);
  83.  
  84. if(sizeof($user) > 0) {
  85. $this->message = $this->error('username_exists');
  86. return false;
  87. }
  88.  
  89. $seeds = substr(uniqid(), 0,8);
  90.  
  91. $gpassword = base64_encode(md5($password."_".$seeds, true));
  92.  
  93. $sql = "insert into user(user_name, user_password, user_seed, user_pro_id, user_created_by, user_created_date)
  94. values(?,?,?,?,?, current_timestap)";
  95.  
  96. $query = $this->db->query($sql,array(
  97. $username,
  98. $gpassword,
  99. $seeds,
  100. $pro_id,
  101. json_encode(array($gpassword)),
  102. $user_create
  103.  
  104. ));
  105.  
  106. if($query === false) {
  107. $this->message = $this->db->_error_message();
  108. return false;
  109. }
  110. alert('123');
  111.  
  112. $member_id = mysql_insert_id();
  113.  
  114. return true;
  115. }
  116.  
  117. public function create_user_profile($pro_name, $pro_ic, $pro_email, $pro_mobile, $pro_tittle, $pro_create,) {
  118. $this->load->database();
  119.  
  120. $name = $this->get_profile_name_row_case_insensitive($profile_name);
  121. $ic = $this->get_profile_ic_row_case_insensitive($profile_ic);
  122. $email = $this->get_profile_email_row_case_insensitive($profile_email);
  123. if(sizeof($name) > 0) {
  124. $this->message = $this->error('username_exists');
  125. return false;
  126. }
  127.  
  128. if(sizeof($ic) > 0) {
  129. $this->message = $this->error('IC_exists');
  130. return false;
  131. }
  132.  
  133. if(sizeof($email) > 0) {
  134. $this->message = $this->error('email_exists');
  135. return false;
  136. }
  137.  
  138. $sql = "insert into profile(pro_name, pro_ic, pro_email, pro_tel_mobile, pro_job_tittle, pro_created_by, pro_created_by)
  139. values(?,?,?,?,?,?, current_timestap)";
  140.  
  141. $query = $this->db->query($sql,array(
  142. $pro_name,
  143. $pro_ic,
  144. $pro_email,
  145. $pro_mobile,
  146. $pro_tittle,
  147. $pro_create
  148.  
  149. ));
  150.  
  151. if($query === false) {
  152. $this->message = $this->db->_error_message();
  153. return false;
  154. }
  155.  
  156.  
  157. $pro_id = $this->db->insert_id();
  158.  
  159. return true;
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement