materio_user.module 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_user_permission() {
  6. return array(
  7. 'view own user profile' => array(
  8. 'title' => t('view own user profile'),
  9. 'description' => t('view own user profile'),
  10. ),
  11. );
  12. }
  13. /**
  14. * Implements hook_menu_alter().
  15. */
  16. function materio_user_menu_alter(&$items) {
  17. $items['user/%user']['access callback'] = 'user_access';
  18. $items['user/%user']['access arguments'] = array('view own user profile');
  19. }
  20. /**
  21. * Implements hook_block_info().
  22. */
  23. function materio_user_block_info() {
  24. $blocks['user_register'] = array(
  25. 'info' => t('Register block'),
  26. 'cache' => DRUPAL_NO_CACHE
  27. );
  28. $blocks['old_database_link'] = array(
  29. 'info' => t('Old data base link'),
  30. 'cache' => DRUPAL_NO_CACHE
  31. );
  32. $blocks['front_link'] = array(
  33. 'info' => t('Front page link'),
  34. 'cache' => DRUPAL_NO_CACHE
  35. );
  36. return $blocks;
  37. }
  38. /**
  39. * Implements hook_block_view().
  40. */
  41. function materio_user_block_view($delta = '') {
  42. global $user, $language;
  43. $block = array();
  44. switch ($delta) {
  45. case 'user_register':
  46. if(isset($user->roles[1])){
  47. $block['subject'] = t('Create your materiO\' account');//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
  48. $block['content'] = drupal_render(drupal_get_form('user_register_form'));
  49. $block['content'] .= '<h3>'. t('or login if you already have an account') . '</h3>';
  50. $block['content'] .= drupal_render(drupal_get_form('user_login'));
  51. }
  52. break;
  53. case 'old_database_link':
  54. if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
  55. // dsm($user, 'user');
  56. $block['subject'] = '';
  57. $path = 'http://base.materio.com';
  58. if($language->language == 'fr')
  59. $path .= '/index_fr.html';
  60. $block['content'] = l(t('Old database'), $path);
  61. }
  62. break;
  63. case 'front_link':
  64. $block['subject'] = '';
  65. $block['content'] = l('<i class="icon-home"></i>'.t('home'), '<front>', array('html'=>true));
  66. break;
  67. }
  68. return $block;
  69. }
  70. /**
  71. * Implements hook_form_alter().
  72. */
  73. function materio_user_form_alter(&$form, &$form_state, $form_id) {
  74. // dsm($form_id);
  75. if( $form_id == "user_register_form" && !user_access('administer users') ){
  76. // dsm($form);
  77. $form['account']['pass']['#type'] = 'password';
  78. $form['account']['pass']['#title'] = t('Password');
  79. $form['actions']['#type'] = "container";
  80. $form['actions']['submit']['#value'] = t('Join');
  81. $form['termsofservices'] = array(
  82. '#type' => 'checkbox',
  83. '#title' => t('I accept') .' '. l(t('the materiO terms of services'), 'node/11183'),
  84. '#required' => true,
  85. );
  86. $form['#submit'][] = "materio_user_user_register_form_submit";
  87. }
  88. if($form_id == "user_login" ){
  89. // dsm($form);
  90. $form['actions']['#type'] = "container";
  91. // $form['actions']['submit']['#value'] = t('Join');
  92. if( $_GET['q'] == 'node/11187' ){
  93. $form['#submit'][] = "materio_user_user_login_form_submit";
  94. }
  95. }
  96. if( $form_id == "webform_client_form_11186" ){
  97. // dsm($form, '$form');
  98. $form['#validate'][] = "materio_user_webform_client_111186_validate";
  99. }
  100. }
  101. function materio_user_user_register_form_submit($form, &$form_state){
  102. // dsm($form, 'form');
  103. // dsm($form_state, 'form_state');
  104. // dsm($_REQUEST, '$_REQUEST');
  105. // dsm($_GET, '$_GET');
  106. unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
  107. $form_state['redirect'] = array(
  108. 'node/11187',
  109. array(
  110. 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
  111. )
  112. );
  113. // $frontlink = l('continue with basic', '<front>');
  114. // // drupal_get_messages('status');
  115. // drupal_set_message(t('Welcome, you just join materiO\'! now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink)));
  116. }
  117. function materio_user_user_login_form_submit($form, &$form_state){
  118. unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
  119. $form_state['redirect'] = array(
  120. 'node/11187',
  121. array(
  122. 'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
  123. )
  124. );
  125. }
  126. function materio_user_webform_client_111186_validate($form, &$form_state){
  127. // dsm($form, 'form');
  128. // dsm($form_state, 'form_state');
  129. $values = $form_state['values']['submitted'];
  130. if ($values['membership_options'] == 3) {
  131. foreach ($values['collaborators'] as $coll_key => $coll) {
  132. foreach ($coll as $field_key => $field_value) {
  133. if($field_value == ''){
  134. $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
  135. $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
  136. // dsm($field_name, 'field_name');
  137. form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
  138. }
  139. }
  140. }
  141. }
  142. }
  143. /**
  144. * Implements hook_help().
  145. */
  146. function materio_user_help($path, $arg) {
  147. // dsm($path, 'path');
  148. // dsm($arg, 'arg');
  149. switch ($path) {
  150. case 'node/%':
  151. if($arg[1] == 11187 ){
  152. global $user;
  153. // dsm($user, 'user');
  154. if(isset($user->roles[1])){ // anonyme
  155. $message = t('Please create an account and join materio, then we\'ll provide you the membership form.');
  156. $content = '<p>' . $message . '</p>';
  157. return $content;
  158. }else if(isset($user->roles[2])){ // authentificated user (not utilisateur)
  159. $content = '<h2>' . t('Welcome, you just joined materiO\' !') . '</h2>';
  160. $frontlink = l('continue with basic', '<front>');
  161. $message = t('Now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink));
  162. $content .= '<p>' . $message . '</p>';
  163. return $content;
  164. }
  165. }
  166. }
  167. }
  168. /**
  169. * Implements hook_block_view_alter().
  170. */
  171. function materio_user_block_view_alter(&$data, $block) {
  172. if( $block->module == "user" && $block->delta == 'login' && isset($data['subject']) ){
  173. // dsm($block, 'block');
  174. // dsm($data, 'data');
  175. $data['subject'] = '<i class="icon-user"></i>' . $data['subject'];
  176. }
  177. }