372 lines
12 KiB
Plaintext
Executable File
372 lines
12 KiB
Plaintext
Executable File
<?php
|
|
|
|
|
|
/**
|
|
* Implements hook_init().
|
|
*/
|
|
function materio_user_init() {
|
|
drupal_add_js(drupal_get_path('module', 'materio_user').'/js/materio_user.min.js');
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function materio_user_permission() {
|
|
return array(
|
|
'view own user profile' => array(
|
|
'title' => t('view own user profile'),
|
|
'description' => t('view own user profile'),
|
|
),
|
|
);
|
|
}
|
|
|
|
function materio_user_menu(){
|
|
$items = array();
|
|
|
|
$base = array(
|
|
'type' => MENU_CALLBACK,
|
|
'file' => 'materio_user.pages.inc',
|
|
);
|
|
|
|
$items['materio_user/registerblock'] = $base+array(
|
|
'title' => 'Materio base user ajax',
|
|
'page callback' => 'materio_user_registerblock',
|
|
// 'page arguments' => array(),
|
|
'access callback' => TRUE,
|
|
);
|
|
|
|
$items['materio_user/loginandregisterblock'] = $base+array(
|
|
'title' => 'Materio base user ajax',
|
|
'page callback' => 'materio_user_loginandregisterblock',
|
|
// 'page arguments' => array(),
|
|
'access callback' => TRUE,
|
|
);
|
|
|
|
$items['materio_user/register/submit'] = $base+array(
|
|
'title' => 'Materio base user ajax',
|
|
'page callback' => 'materio_user_register_submit',
|
|
// 'page arguments' => array(),
|
|
'access callback' => TRUE,
|
|
);
|
|
|
|
$items['materio_user/login/submit'] = $base+array(
|
|
'title' => 'Materio base user ajax',
|
|
'page callback' => 'materio_user_login_submit',
|
|
// 'page arguments' => array(),
|
|
'access callback' => TRUE,
|
|
);
|
|
|
|
return $items;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_menu_alter().
|
|
*/
|
|
function materio_user_menu_alter(&$items) {
|
|
$items['user/%user']['access callback'] = 'user_access';
|
|
$items['user/%user']['access arguments'] = array('view own user profile');
|
|
}
|
|
|
|
/**
|
|
* Implements hook_block_info().
|
|
*/
|
|
function materio_user_block_info() {
|
|
$blocks['user_createaccount'] = array(
|
|
'info' => t('Create an account block'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
$blocks['user_register'] = array(
|
|
'info' => t('Register block'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
$blocks['old_database_link'] = array(
|
|
'info' => t('Old data base link'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
$blocks['front_link'] = array(
|
|
'info' => t('Front page link'),
|
|
'cache' => DRUPAL_NO_CACHE
|
|
);
|
|
|
|
return $blocks;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_block_view().
|
|
*/
|
|
function materio_user_block_view($delta = '') {
|
|
global $user, $language;
|
|
$block = array();
|
|
switch ($delta) {
|
|
case 'user_createaccount':
|
|
if(isset($user->roles[1])){
|
|
$block['subject'] = '';
|
|
if (drupal_is_front_page()) {
|
|
$block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
|
|
$block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
|
|
}else{
|
|
$block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
|
|
$block['content'] .= drupal_render(drupal_get_form('user_register_form'));
|
|
}
|
|
}
|
|
break;
|
|
case 'user_register':
|
|
if(isset($user->roles[1])){
|
|
$block['subject'] = '';//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
|
|
$block['content'] = '<h3>'. t('Login') . '</h3>';
|
|
$ulog_form = drupal_get_form('user_login');
|
|
$block['content'] .= drupal_render($ulog_form);
|
|
if (drupal_is_front_page()) {
|
|
$block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
|
|
$block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
|
|
}else{
|
|
$block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
|
|
$block['content'] .= drupal_render(drupal_get_form('user_register_form'));
|
|
}
|
|
// $block['content'] .= l(t('Pricing'), 'node/11187', array('attributes' => array('class' => 'pricing'),));
|
|
}
|
|
break;
|
|
case 'old_database_link':
|
|
if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
|
|
// dsm($user, 'user');
|
|
$block['subject'] = '';
|
|
|
|
$path = 'http://base.materio.com';
|
|
|
|
if($language->language == 'fr')
|
|
$path .= '/index_fr.html';
|
|
|
|
$block['content'] = l(t('Old database'), $path);
|
|
}
|
|
break;
|
|
case 'front_link':
|
|
$block['subject'] = '';
|
|
$block['content'] = l('<i class="icon-home"></i><span class="text">'.t('home').'</span>', '<front>', array('html'=>true));
|
|
break;
|
|
}
|
|
return $block;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_form_alter().
|
|
*/
|
|
function materio_user_form_alter(&$form, &$form_state, $form_id) {
|
|
// dsm($form_id);
|
|
if( $form_id == "user_register_form" && !user_access('administer users') ){
|
|
// dsm($form);
|
|
$form['account']['pass']['#type'] = 'password';
|
|
$form['account']['pass']['#title'] = t('Password');
|
|
|
|
$form['actions']['#type'] = "container";
|
|
$form['actions']['submit']['#value'] = t('Join');
|
|
|
|
// $form['termsofservices'] = array(
|
|
// '#type' => 'checkbox',
|
|
// '#title' => t('I accept') .' '. l(t('the materiO terms of services'), 'node/11183'),
|
|
// '#required' => true,
|
|
// );
|
|
|
|
// $form['#submit'][] = "materio_user_user_register_form_submit";
|
|
|
|
}
|
|
if($form_id == "user_login" ){
|
|
// dsm($form);
|
|
|
|
$form['actions']['#type'] = "container";
|
|
// $form['actions']['submit']['#value'] = t('Join');
|
|
|
|
// if( $_GET['q'] == 'node/11187' ){
|
|
// $form['#submit'][] = "materio_user_user_login_form_submit";
|
|
// }
|
|
|
|
}
|
|
|
|
// if( $form_id == "webform_client_form_11186" ){
|
|
// dsm($form, '$form');
|
|
// $form['#validate'][] = "materio_user_webform_client_111186_validate";
|
|
// $form['#submit'][] = "materio_user_webform_client_111186_submit";
|
|
// }
|
|
|
|
|
|
// if( $form_id == "user_profile_form" ){
|
|
// //dsm($form, '$form');
|
|
// $form['account']['pass']['#type'] = "new_password_confirm";
|
|
// }
|
|
}
|
|
|
|
// function materio_user_user_register_form_submit($form, &$form_state){
|
|
// dsm($form, 'form');
|
|
// dsm($form_state, 'form_state');
|
|
// dsm($_REQUEST, '$_REQUEST');
|
|
// dsm($_GET, '$_GET');
|
|
|
|
// unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
|
|
|
// $form_state['redirect'] = array(
|
|
// 'node/11187',
|
|
// array(
|
|
// 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
|
|
// )
|
|
// );
|
|
|
|
// $frontlink = l('continue with basic', '<front>');
|
|
// // drupal_get_messages('status');
|
|
// 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)));
|
|
// }
|
|
|
|
// function materio_user_user_login_form_submit($form, &$form_state){
|
|
// unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
|
|
|
|
// $form_state['redirect'] = array(
|
|
// 'node/11187',
|
|
// array(
|
|
// 'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
|
|
// )
|
|
// );
|
|
// }
|
|
|
|
function materio_user_webform_client_111186_validate($form, &$form_state){
|
|
// dsm($form, 'form');
|
|
// dsm($form_state, 'form_state');
|
|
$values = $form_state['values']['submitted'];
|
|
if ($values['column_left']['membership_options'] == 3) {
|
|
foreach ($values['collaborators'] as $coll_key => $coll) {
|
|
foreach ($coll as $field_key => $field_value) {
|
|
if($field_value == ''){
|
|
$human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
|
|
$field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
|
|
// dsm($field_name, 'field_name');
|
|
|
|
// TODO : tester si les email ne sont pas deja inscrit sur le site
|
|
|
|
|
|
form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
// function materio_user_webform_client_111186_submit($form, &$form_state){
|
|
// dsm($form, 'form');
|
|
// dsm($form_state, 'form_state');
|
|
// $values = $form_state['values']['submitted_tree'];
|
|
// if ($values['membership_options'] == 3) {
|
|
// $i = 1;
|
|
// foreach ($values['collaborators'] as $coll_key => $coll) {
|
|
// // foreach ($coll as $field_key => $field_value) {
|
|
// // if($field_value == ''){
|
|
// // $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
|
|
// // $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
|
|
// // // dsm($field_name, 'field_name');
|
|
|
|
// // form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
|
|
// // }
|
|
// // }
|
|
// $userinfo = array(
|
|
// 'mail' => $coll['e_mail_collab_'.$i],
|
|
// 'name' => user_password(),
|
|
// 'pass' => user_password(), // Generate password
|
|
// // 'init' => $data['components']['username']['value'],
|
|
// 'status' => 0,
|
|
// 'access' => REQUEST_TIME,
|
|
// 'memo' => 'from webform',
|
|
// );
|
|
// $account = drupal_anonymous_user();
|
|
// $account->is_new = TRUE;
|
|
// user_save($account, $userinfo);
|
|
// // module_invoke_all('user_insert', $edit, $account);
|
|
// $i++;
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
// enregistrer le type d'adonnement chez les user
|
|
|
|
// }
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function materio_user_help($path, $arg) {
|
|
// dsm($path, 'path');
|
|
// dsm($arg, 'arg');
|
|
switch ($path) {
|
|
case 'node/%':
|
|
if($arg[1] == 11187 ){
|
|
global $user;
|
|
// dsm($user, 'user');
|
|
|
|
if(isset($user->roles[1])){ // anonyme
|
|
$message = t('Please create first a free account and join materio or log in with your existing account,<br />then we\'ll provide you our membership form.', array());
|
|
$content = '<p>' . $message . '</p>';
|
|
return $content;
|
|
}else if(isset($user->roles[2])){ // authentificated user (not utilisateur)
|
|
$content = '<h2>' . t('Welcome, you just joined materiO\' !') . '</h2>';
|
|
$frontlink = l(t('continue with basic'), '<front>');
|
|
$message = t('Now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink));
|
|
$content .= '<p>' . $message . '</p>';
|
|
return $content;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Implements hook_block_view_alter().
|
|
*/
|
|
function materio_user_block_view_alter(&$data, $block) {
|
|
if( $block->module == "user" && $block->delta == 'login' && isset($data['subject']) ){
|
|
// dsm($block, 'block');
|
|
// dsm($data, 'data');
|
|
$data['subject'] = '<i class="icon-user"></i>' . '<span class="login">' . $data['subject'] . '</span>';
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Define constants
|
|
*/
|
|
define('MATERIO_USER_CONFIRMED_USER_ROLE', 'Utilisateur'); // add role name here
|
|
|
|
/**
|
|
* Implement hook_user
|
|
*/
|
|
function _materio_user_user_update(&$edit, $account, $category){
|
|
// dsm($edit, 'edit');
|
|
// dsm($account, 'account');
|
|
// dsm($category, 'category');
|
|
|
|
// This is only fired when a user confirms their email address, logintoboggan style
|
|
if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {
|
|
$confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);
|
|
$roles = $account->roles + array($confirmed_rid => MATERIO_USER_CONFIRMED_USER_ROLE);
|
|
|
|
// we have to do this to stop an infinite loop, and also to allow lower weighted modules to possibly do something here
|
|
$user = $account;
|
|
unset($user->logintoboggan_email_validated);
|
|
|
|
user_save($user, array('roles' => $roles));
|
|
|
|
drupal_go_to('user/'.$user->uid.'/edit');
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Returns a role ID based on role name
|
|
*
|
|
* @param $name
|
|
* name of role to return
|
|
* @return
|
|
* (int) Role ID
|
|
*/
|
|
function materio_user_get_role_by_name($name) {
|
|
return array_search($name, user_roles());
|
|
}
|
|
|