PageRenderTime 32ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/app/modules/customer/controllers/AccountController.php

https://github.com/hukumonline/admin
PHP | 238 lines | 134 code | 35 blank | 69 comment | 14 complexity | 06e4d793591a87cf7712f0da52c4ea4b MD5 | raw file
  1. <?php
  2. /**
  3. * Description of AccountController
  4. *
  5. * @author nihki <nihki@madaniyah.com>
  6. */
  7. class Customer_AccountController extends Zend_Controller_Action
  8. {
  9. function preDispatch()
  10. {
  11. $this->_helper->layout->setLayout('layout-customer-account');
  12. }
  13. function registerAction()
  14. {
  15. if ($this->getRequest()->getPost())
  16. {
  17. $value = $this->getRequest()->getPost();
  18. $this->view->value = $value;
  19. /*
  20. list($ret, $body) = Pandamp_Lib_Remote::serverCmd('register', $value);
  21. switch ($ret)
  22. {
  23. case 200:
  24. $this->view->message = "User&nbsp;:&nbsp;<abbr>".$value['username']."</abbr> data has been successfully saved.";
  25. break;
  26. default:
  27. $this->view->error_message = "failure";
  28. }
  29. */
  30. $data = $this->transformRegister($value);
  31. $modelUser = new App_Model_Db_Table_User();
  32. $id = $modelUser->insert($data);
  33. $this->updateKopel();
  34. /**
  35. * SELECT id, parent_id, value, name, lft, rgt
  36. * eg. $aReturn = $acl->getGroupData(15)
  37. * print_r($aReturn);
  38. * output: Array ( [0] => 15 [1] => 10 [2] => Super Administrator [3] => super_admin [4] => 10 [5] => 11 )
  39. */
  40. $acl = Pandamp_Acl::manager();
  41. //$aReturn = $acl->getGroupData($value['aro_groups']);
  42. $aReturn = App_Model_Show_AroGroup::show()->getUserGroup($value['aro_groups']);
  43. //echo '<pre>';
  44. //print_r($aReturn);
  45. //echo '</pre>';
  46. //$acl->addUser($value['username'],$aReturn[3]);
  47. $acl->addUserToGroup($value['username'], $aReturn['name']);
  48. $formater = new Pandamp_Core_Hol_User();
  49. // Do you want Email Confirmation send?
  50. if (isset($value['ec']) == 1)
  51. {
  52. //echo 'y';
  53. $payment = ($value['payment'])? $value['payment'] : 0;
  54. $promotionCode = ($value['promotioncode'])? $value['promotioncode'] : '';
  55. switch ($value['aro_groups'])
  56. {
  57. /**
  58. * @modifiedDate: December 07, 2012
  59. * @modifiedDate-2: January 29, 2013
  60. */
  61. case 14: // individual
  62. $mailcontent = $formater->getMailContent('konfirmasi-email-individual');
  63. //$disc = $formater->checkPromoValidation('Disc',$value['aro_groups'],$promotionCode,$payment);
  64. //$total = $formater->checkPromoValidation('Total',$value['aro_groups'],$promotionCode,$payment);
  65. $total = $formater->checkPromoValidation('Total',$value['aro_groups'],$payment);
  66. $disc = $formater->checkPromoValidation('Disc',$value['aro_groups'],$payment);
  67. //$m = $formater->_writeConfirmIndividualEmail($mailcontent,$value['fullname'],$value['username'],$value['password'],$payment,$disc,$total,base64_encode($id),$value['email']);
  68. $m = $formater->_writeConfirmIndividualEmail($mailcontent,$value['aro_groups'],$value['fullname'],$value['username'],$value['password'],$payment,$disc,$total,base64_encode($id),$value['email']);
  69. break;
  70. case 15: // corporate/basic
  71. case 16: // standard
  72. case 18: // professional
  73. $mailcontent = $formater->getMailContent('konfirmasi-email-korporasi');
  74. //$disc = $formater->checkPromoValidation('Disc',$value['aro_groups'],$promotionCode,$payment);
  75. //$total = $formater->checkPromoValidation('Total',$value['aro_groups'],$promotionCode,$payment);
  76. $total = $formater->checkPromoValidation('Total',$value['aro_groups'],$payment);
  77. $disc = $formater->checkPromoValidation('Disc',$value['aro_groups'],$payment);
  78. //$m = $formater->_writeConfirmCorporateEmail($mailcontent,$value['fullname'],$value['company'],$payment,$disc,$total,$value['username'],base64_encode($id),$value['email']);
  79. $m = $formater->_writeConfirmCorporateEmail($mailcontent,$value['aro_groups'],$value['fullname'],$value['company'],$payment,$disc,$total,$value['username'],base64_encode($id),$value['email']);
  80. break;
  81. default:
  82. $mailcontent = $formater->getMailContent('konfirmasi email gratis');
  83. $m = $formater->_writeConfirmFreeEmail($mailcontent,$value['fullname'],$value['username'],$value['password'],base64_encode($id),$value['email'],$aReturn['name']);
  84. break;
  85. }
  86. $this->view->message = $m;
  87. }
  88. else
  89. {
  90. //echo 't';
  91. }
  92. }
  93. }
  94. function transformRegister($value)
  95. {
  96. if (empty($value['username'])) {
  97. throw new Zend_Exception("Username empty!");
  98. }
  99. $obj = new Pandamp_Crypt_Password();
  100. $month = ($value['month'])? $value['month'] : '00';
  101. $day = ($value['day'])? $value['day'] : '00';
  102. $year = ($value['year'])? $value['year'] : '0000';
  103. $newArticle = (isset($value['newArticle']))? $value['newArticle'] : '';
  104. $newRegulation = (isset($value['newRegulation']))? $value['newRegulation'] : '';
  105. $newWRegulation = (isset($value['newWeeklyRegulation']))? $value['newWeeklyRegulation'] : '';
  106. $isContact = (isset($value['iscontact']))? $value['iscontact'] : '';
  107. if ($value['gender'] == 1)
  108. {
  109. $gender = 'L';
  110. }
  111. else if($value['gender'] == 2)
  112. {
  113. $gender = 'P';
  114. }
  115. else
  116. {
  117. $gender = 'N';
  118. }
  119. $data = array(
  120. 'kopel' => $this->generateKopel()
  121. ,'username' => $value['username']
  122. ,'password' => $obj->encryptPassword($value['password'])
  123. ,'fullName' => ($value['fullname'])? $value['fullname'] : ''
  124. ,'birthday' => $year.'-'.$month.'-'.$day
  125. ,'phone' => ($value['phone'])? $value['phone'] : ''
  126. ,'fax' => ($value['fax'])? $value['fax'] : ''
  127. ,'gender' => $gender
  128. ,'email' => $value['email']
  129. ,'company' => ($value['company'])? $value['company'] : ''
  130. ,'address' => ($value['address'])? $value['address'] : ''
  131. ,'city' => ($value['city'])? $value['city'] : ''
  132. ,'state' => ($value['province'])? $value['province'] : ''
  133. ,'countryId' => ($value['countryId'])? $value['countryId'] : ''
  134. ,'zip' => ($value['zip'])? $value['zip'] : ''
  135. ,'indexCol' => 0
  136. ,'newArticle' => ($newArticle == 1)? 'Y' : 'N'
  137. ,'weeklyList' => ($newWRegulation == 1)? 'Y' : 'N'
  138. ,'monthlyList' => ($newRegulation == 1)? 'Y' : 'N'
  139. ,'packageId' => $value['aro_groups']
  140. ,'promotionId' => ($value['promotioncode'])? $value['promotioncode'] : ''
  141. ,'educationId' => ($value['education'])? $value['education'] : 0
  142. ,'expenseId' => ($value['expense'])? $value['expense'] : 0
  143. ,'paymentId' => ($value['payment'])? $value['payment'] : 0
  144. ,'trialInDays' => ($value['trial'])? $value['trial'] : 0
  145. ,'businessTypeId' => ($value['businessType'])? $value['businessType'] : 0
  146. ,'periodeId' => 1
  147. ,'createdDate' => date('Y-m-d H:i:s')
  148. ,'createdBy' => $value['createdBy']
  149. ,'isContact' => ($isContact == 1)? 'Y' : 'N'
  150. ,'notes' => $value['notes']
  151. );
  152. return $data;
  153. }
  154. protected function generateKopel()
  155. {
  156. $rowset = App_Model_Show_Number::show()->getNumber();
  157. $num = $rowset['user'];
  158. //$totdigit = 6;
  159. $num = strval($num);
  160. $jumdigit = strlen($num);
  161. //$kopel = str_repeat("0",$totdigit-$jumdigit).$num;
  162. $kopel = str_pad($num, $jumdigit, '0', STR_PAD_LEFT);
  163. return $kopel;
  164. }
  165. protected function updateKopel()
  166. {
  167. /*
  168. $modelNumber = new App_Model_Db_Table_Number();
  169. $rowset = $modelNumber->fetchRow();
  170. $rowset->user = $rowset->user += 1;
  171. $rowset->save();
  172. */
  173. try {
  174. $modelNumber = new App_Model_Db_Table_Number();
  175. $modelNumber->update(array('user'=>new Zend_Db_Expr('user + 1')), 'num=1');
  176. }
  177. catch (Exception $e)
  178. {
  179. throw new Zend_Exception($e->getMessage());
  180. }
  181. }
  182. /*
  183. function checkusernameAction()
  184. {
  185. $this->_helper->viewRenderer->setNoRender(TRUE);
  186. $username = $this->_getParam('username');
  187. $tbluser = new App_Model_Db_Table_User();
  188. $where = $tbluser->getAdapter()->quoteInto("username=?",$username);
  189. $rowset = $tbluser->fetchRow($where);
  190. if(count($rowset)>0)
  191. $valid = 'false';
  192. else
  193. $valid = 'true';
  194. echo $valid;
  195. die();
  196. }
  197. *
  198. */
  199. }