materio_user.pages.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <?php
  2. function materio_user_registerblock(){
  3. $return = array();
  4. $block = block_load('materio_user','user_createaccount');
  5. $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  6. drupal_json_output($return);
  7. }
  8. function materio_user_loginandregisterblock(){
  9. $return = array();
  10. $block = block_load('materio_user','user_register');
  11. $return['block'] = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
  12. drupal_json_output($return);
  13. }
  14. function materio_user_register_submit(){
  15. $return = array();
  16. $return['POST'] = $_POST;
  17. $form_state = array( "values"=>$_POST);
  18. drupal_form_submit($_POST['form_id'], $form_state);
  19. // $return['form_state'] = $form_state;
  20. $return['errors'] = form_get_errors();
  21. if($return['errors']){
  22. unset ($_SESSION['messages']['error']);
  23. }else{
  24. $messages = drupal_get_messages('status');
  25. // $return['messages'] = $messages;
  26. // drupal_set_message(t("Congratulations, you juste created your free materiO' account, welcome !"), 'status');
  27. foreach ($messages['status'] as $msg) {
  28. drupal_set_message($msg, 'status');
  29. }
  30. }
  31. // after registration user is automaticly logged in, thank's to login tobogan module
  32. drupal_json_output($return);
  33. }
  34. function materio_user_login_submit(){
  35. $return = array();
  36. $return['POST'] = $_POST;
  37. $form_state = array("values"=>$_POST);
  38. drupal_form_submit($_POST['form_id'], $form_state);
  39. $return['errors'] = form_get_errors();
  40. if($return['errors'])
  41. unset ($_SESSION['messages']['error']);
  42. // if user-login form succed we retreive the user uid on $form_state, then we can effectively loggin the user
  43. if($uid = $form_state['uid'])
  44. user_login_submit(array(), $form_state);
  45. drupal_json_output($return);
  46. }
  47. function materio_user_export(){
  48. $ret = "";
  49. // MEMBRE et etudiants
  50. $query = db_select('users', 'u');
  51. $query->join('users_roles', 'ur', 'u.uid=ur.uid');
  52. $query
  53. ->fields('u', array('mail', 'uid'))
  54. ->condition('u.status', '1')
  55. ->condition('ur.rid', array(6, 8, 10), "IN");
  56. $results = $query->execute()->fetchall();
  57. $vals = array();
  58. foreach ($results as $rec) {
  59. $vals[] = $rec->mail;
  60. }
  61. $num_rows = count($vals);
  62. $ret .= "<h1>Liste de tous les user adherents et étudiants ($num_rows)</h1>";
  63. $ret .= '<textarea cols="40" rows="30">'.implode($vals, '&#13;&#10;').'</textarea>';
  64. // MEMBRE sans les aaf
  65. $query = db_select('users', 'u');
  66. $query->join('users_roles', 'ur', 'u.uid=ur.uid');
  67. // $query->join('field_data_field_memo', 'mem', 'u.uid=mem.entity_id');
  68. $query
  69. ->fields('u', array('mail', 'uid'))
  70. ->condition('u.status', '1')
  71. ->condition('ur.rid', array(6, 8, 10), "IN");
  72. // ->condition('mem.field_memo_value', "%AAF%", "LIKE");
  73. $results = $query->execute()->fetchall();
  74. $vals = array();
  75. foreach ($results as $rec) {
  76. $aaf_query = db_select('field_data_field_memo', 'mem');
  77. $aaf_query
  78. ->fields('mem', array("field_memo_value"))
  79. ->isNotNull('field_memo_value')
  80. ->condition('mem.entity_id', $rec->uid);
  81. $aaf_results = $aaf_query->execute()->fetchall();
  82. $aaf = false;
  83. foreach ($aaf_results as $memo) {
  84. if(strpos($memo->field_memo_value,'AAF') !== false){
  85. $aaf = true;
  86. break;
  87. }
  88. }
  89. if(!$aaf)
  90. $vals[] = $rec->mail;
  91. }
  92. $num_rows = count($vals);
  93. $ret .= "<h1>Liste des user adhérents et étudiants (sans les aaf) ($num_rows)</h1>";
  94. $ret .= '<textarea cols="40" rows="30">'.implode($vals, '&#13;&#10;').'</textarea>';
  95. // MEMBRE AAF
  96. $query = db_select('users', 'u');
  97. $query->join('users_roles', 'ur', 'u.uid=ur.uid');
  98. // $query->join('field_data_field_memo', 'mem', 'u.uid=mem.entity_id');
  99. $query
  100. ->fields('u', array('mail', 'uid'))
  101. ->condition('u.status', '1')
  102. ->condition('ur.rid', array(6, 8, 10), "IN");
  103. // ->condition('mem.field_memo_value', "%AAF%", "LIKE");
  104. $results = $query->execute()->fetchall();
  105. $vals = array();
  106. foreach ($results as $rec) {
  107. $aaf_query = db_select('field_data_field_memo', 'mem');
  108. $aaf_query
  109. ->fields('mem', array("field_memo_value"))
  110. ->isNotNull('field_memo_value')
  111. ->condition('mem.entity_id', $rec->uid);
  112. $aaf_results = $aaf_query->execute()->fetchall();
  113. $aaf = false;
  114. foreach ($aaf_results as $memo) {
  115. if(strpos($memo->field_memo_value,'AAF') !== false){
  116. $aaf = true;
  117. break;
  118. }
  119. }
  120. if($aaf)
  121. $vals[] = $rec->mail;
  122. }
  123. $num_rows = count($vals);
  124. $ret .= "<h1>Liste des user adhérents AAF ($num_rows)</h1>";
  125. $ret .= '<textarea cols="40" rows="30">'.implode($vals, '&#13;&#10;').'</textarea>';
  126. // inscrit daily non membre
  127. $query = db_select('users', 'u');
  128. $query->join('users_roles', 'ur', 'u.uid=ur.uid');
  129. $query->join('simplenews_subscriber', 'ssr', 'u.uid=ssr.uid');
  130. $query->join('simplenews_subscription', 'ssn', 'ssr.snid=ssn.snid');
  131. $query
  132. ->fields('u', array('mail'))
  133. ->condition('u.status', '1')
  134. ->condition('ur.rid', array(3, 4, 6, 8, 10), "NOT IN")
  135. ->condition('ssn.tid', '6374')
  136. ->condition('ssn.status', '1');
  137. $results = $query->execute()->fetchall();
  138. $vals = array();
  139. foreach ($results as $rec) {
  140. $vals[] = $rec->mail;
  141. }
  142. $num_rows = count($vals);
  143. $ret .= "<h1>Liste des user non membre inscrits au daily ($num_rows)</h1>";
  144. $ret .= '<textarea cols="40" rows="30">'.implode($vals, '&#13;&#10;').'</textarea>';
  145. return $ret;
  146. }