materio_user.module 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. return $blocks;
  33. }
  34. /**
  35. * Implements hook_block_view().
  36. */
  37. function materio_user_block_view($delta = '') {
  38. global $user, $language;
  39. $block = array();
  40. switch ($delta) {
  41. case 'user_register':
  42. if(isset($user->roles[1])){
  43. $block['subject'] = t('Create your materiO\' account');//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
  44. $block['content'] = drupal_render(drupal_get_form('user_register_form'));
  45. }
  46. break;
  47. case 'old_database_link':
  48. if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
  49. // dsm($user, 'user');
  50. $block['subject'] = '';
  51. $path = 'http://base.materio.com';
  52. if($language->language == 'fr')
  53. $path .= '/index_fr.html';
  54. $block['content'] = l(t('Old database'), $path);
  55. }
  56. break;
  57. }
  58. return $block;
  59. }
  60. /**
  61. * Implements hook_form_alter().
  62. */
  63. function materio_user_form_alter(&$form, &$form_state, $form_id) {
  64. // dsm($form_id);
  65. if($form_id == "user_register_form" ){
  66. // dsm($form);
  67. $form['account']['pass']['#type'] = 'password';
  68. $form['account']['pass']['#title'] = t('Password');
  69. $form['actions']['#type'] = "container";
  70. $form['actions']['submit']['#value'] = t('Join');
  71. $form['termsofservices'] = array(
  72. '#type' => 'checkbox',
  73. '#title' => t('I accept') .' '. l('the materiO terms of services', 'node/11183'),
  74. '#required' => true,
  75. );
  76. $form['#submit'][] = "materio_user_user_register_form_submit";
  77. }
  78. }
  79. function materio_user_user_register_form_submit($form, &$form_state){
  80. // dsm($form, 'form');
  81. // dsm($form_state, 'form_state');
  82. // dsm($_REQUEST, '$_REQUEST');
  83. // dsm($_GET, '$_GET');
  84. unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
  85. $form_state['redirect'] = array(
  86. 'node/11187',
  87. array(
  88. 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
  89. )
  90. );
  91. // $frontlink = l('continue with basic', '<front>');
  92. // // drupal_get_messages('status');
  93. // 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)));
  94. }
  95. /**
  96. * Implements hook_help().
  97. */
  98. function materio_user_help($path, $arg) {
  99. // dsm($path, 'path');
  100. // dsm($arg, 'arg');
  101. switch ($path) {
  102. case 'node/%':
  103. if($arg[1] == 11187 ){
  104. global $user;
  105. // dsm($user, 'user');
  106. if(isset($user->roles[1])){ // anonyme
  107. $message = t('Please create an account and join materio, then we\'ll provide you the membership form.');
  108. $content = '<p>' . $message . '</p>';
  109. return $content;
  110. }else if(isset($user->roles[2])){ // authentificated user (not utilisateur)
  111. $content = '<h2>' . t('Welcome, you just joined materiO\' !') . '</h2>';
  112. $frontlink = l('continue with basic', '<front>');
  113. $message = t('Now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink));
  114. $content .= '<p>' . $message . '</p>';
  115. return $content;
  116. }
  117. }
  118. }
  119. }