Advertisement
Guest User

Untitled

a guest
Nov 18th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. <?php
  2. App::uses('AppModel', 'Model');
  3. /**
  4. * Adherant Model
  5. *
  6. * @property User $User
  7. * @property Tarif $Tarif
  8. */
  9. class Adherant extends AppModel {
  10.  
  11. /**
  12. * Validation rules
  13. *
  14. * @var array
  15. */
  16. public $validate = array(
  17. 'nom' => array(
  18. 'notempty' => array(
  19. 'rule' => array('notempty'),
  20. //'message' => 'Your custom message here',
  21. //'allowEmpty' => false,
  22. //'required' => false,
  23. //'last' => false, // Stop validation after this rule
  24. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  25. ),
  26. ),
  27. 'prenom' => array(
  28. 'notempty' => array(
  29. 'rule' => array('notempty'),
  30. //'message' => 'Your custom message here',
  31. //'allowEmpty' => false,
  32. //'required' => false,
  33. //'last' => false, // Stop validation after this rule
  34. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  35. ),
  36. ),
  37. 'cartepaiment' => array(
  38. 'numeric' => array(
  39. 'rule' => array('numeric'),
  40. //'message' => 'Your custom message here',
  41. //'allowEmpty' => false,
  42. //'required' => false,
  43. //'last' => false, // Stop validation after this rule
  44. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  45. ),
  46. ),
  47. 'user_id' => array(
  48. 'numeric' => array(
  49. 'rule' => array('numeric'),
  50. //'message' => 'Your custom message here',
  51. //'allowEmpty' => false,
  52. //'required' => false,
  53. //'last' => false, // Stop validation after this rule
  54. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  55. ),
  56. ),
  57. 'cin' => array(
  58. 'numeric' => array(
  59. 'rule' => array('numeric'),
  60. //'message' => 'Your custom message here',
  61. //'allowEmpty' => false,
  62. //'required' => false,
  63. //'last' => false, // Stop validation after this rule
  64. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  65. ),
  66. ),
  67. 'tarif_id' => array(
  68. 'numeric' => array(
  69. 'rule' => array('numeric'),
  70. //'message' => 'Your custom message here',
  71. //'allowEmpty' => false,
  72. //'required' => false,
  73. //'last' => false, // Stop validation after this rule
  74. //'on' => 'create', // Limit validation to 'create' or 'update' operations
  75. ),
  76. ),
  77. );
  78.  
  79. //The Associations below have been created with all possible keys, those that are not needed can be removed
  80.  
  81. /* *
  82. * belongsTo associations
  83. *
  84. * @var array
  85. */
  86. public $belongsTo = array(
  87. 'User' => array(
  88. 'className' => 'User',
  89. 'foreignKey' => 'user_id',
  90. 'conditions' => '',
  91. 'fields' => '',
  92. 'order' => ''
  93. ),
  94. 'Tarif' => array(
  95. 'className' => 'Tarif',
  96. 'foreignKey' => 'tarif_id',
  97. 'conditions' => '',
  98. 'fields' => '',
  99. 'order' => ''
  100. )
  101. );
  102.  
  103. $this->loadModel('User');
  104. $this->loadModel('Tarif');
  105. //$tarif_id=this->Session->read('tarif_id');
  106.  
  107. $this->Session->write('Person.addAdh',"");
  108. if ($this->request->is('post')) {
  109.  
  110.  
  111. $this->Adherant->create();
  112. $login=$this->request->data['login'];
  113. $pass=$this->request->data['motpass'];
  114. $count=$this->User- >find('count',array('conditions'=>array('User.login'=>$login)));
  115. if($count==1){
  116. $this->redirect(array('action' => 'add'));
  117. $this->Session->write('Person.addAdh',"adherant existe déjà (user)");
  118.  
  119. }else{
  120. $count1=$this->Adherant- >find('count',array('conditions'=>array('Adherant.cin'=>$this->request- >data['cin'])));
  121. if($count1==0){
  122. $this->User->save(
  123. array(
  124. 'login' => $login,
  125. 'motpass' => $pass,
  126.  
  127. )
  128. );
  129. $first=$this->User- >find('first',array('conditions'=>array('User.login'=>$login)));
  130. $user=$first['User']['id'];
  131. if ($this->Adherant->saveAll($this->request->data, array('deep' => true)))
  132. {
  133.  
  134.  
  135. $this->Session->setFlash( __('The ADHERANT has been saved'), 'success');
  136. return $this->redirect(array('action' => 'index'));
  137. }
  138. }else{
  139. $this->redirect(array('action' => 'add'));
  140. $this->Session->write('Person.addAdh',"adherant existe déjà(cin)");
  141. }
  142.  
  143. }}
  144.  
  145.  
  146.  
  147. $users = $this->Adherant->User->find('list');
  148.  
  149. $tarifs = $this->Adherant->Tarif- >find('list',array('fields'=>array('Tarif.id','Tarif.designation')));
  150. $this->set(compact('users','tarifs'));
  151.  
  152.  
  153.  
  154.  
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement