Skip to content

Instantly share code, notes, and snippets.

@tarto-dev
Created March 14, 2014 14:03
Show Gist options
  • Save tarto-dev/9548247 to your computer and use it in GitHub Desktop.
Save tarto-dev/9548247 to your computer and use it in GitHub Desktop.
copris
<?php
function copris_demande_menu(){
$items['copris/demande'] = array(
'title' => t('Gestion des demandes'),
'description' => t('Gerez vos demandes'),
'page callback' => 'copris_demande_get_list',
'type' => MENU_NORMAL_ITEM,
'access arguments' => array('Access demande'),
);
$items['copris/demande/get/commentaires'] = array(
'title' => t('Recuperation des commentaires de la node'),
'description' => t('Recuperation des commentaires de la node'),
' page callback' => 'copris_demande_get_comments',
'type' => MENU_CALLBACK,
'access arguments' => array('Access content user'),
);
$items['openMail/demande'] = array(
'title' => t('Incremente le nombre de mail ouvert'),
'description' => t('Incremente le nombre de mail ouvert'),
'page callback' => '_incremente_mail_ouvert',
'type' => MENU_CALLBACK,
'access arguments' => array(true),
);
return $items;
}
function copris_demande_get_comments() {
die('plouf');
$nid = FALSE;
$json['comments'] = array();
$json['status'] = 400;
$json['message'] = 'Erreur de recuperation des donnees. Soit vous n\'avez pas accès à la node, soit il n\'y à pas de commentaires';
if(!empty($_POST['nid'])) {
$nid = $_POST['nid'];
}
if($nid) {
$node = node_load($nid);
$json['comments'] = comment_get_thread($node, '', 100);
$json['status'] = 200;
$json['message'] = 'success';
}
die('penis');
return drupal_json_output($json);
}
function copris_demande_form_alter(&$form, &$form_state, $form_id){
global $user;
// print '<pre>'; print_r($form); print '</pre>';
if($form_id == 'demande_node_form'){
drupal_set_title(t('Merci de renseigner les informations de votre demande'));
hide($form['field_etat_demande']);
hide($form['field_clos_demande']);
hide($form['field_id_lot']);
hide($form['field_id_bat_demande']);
hide($form['field_lot_demande']);
$copros = copris_get_copros($user->uid, false, false);
if(isset($form['#node']->field_id_bat_demande['und'][0]['value']) && !isset($form_state['values']['batiments'])){
$currentBatiment = $form['#node']->field_id_bat_demande['und'][0]['value'];
$rep = db_query("SELECT im.field_id_im_value FROM {field_data_field_id_im} im WHERE im.entity_id = :nid", array('nid' => $currentBatiment))->fetchAll();
$currentImmeuble = $rep[0]->field_id_im_value;
$rep2 = db_query("SELECT copro.field_id_copro_im_value FROM {field_data_field_id_copro_im} copro WHERE copro.entity_id = :nid", array('nid' => $currentImmeuble))->fetchAll();
$currentCopro = $rep2[0]->field_id_copro_im_value;
} else {
$currentImmeuble = isset($form_state['values']['immeubles']) ? $form_state['values']['immeubles'] : 0;
$currentCopro = isset($form_state['values']['titles']) ? $form_state['values']['titles'] : key($copros);
$currentBatiment = isset($form_state['values']['batiments']) ? $form_state['values']['batiments'] : 0;
}
//if(isset $currentDemande)
//$currentDemande = $form['#node']->vid;
$filePath = 'private://Demandes/';
$batfilePath = $filePath.'copro'.$currentCopro.'/immeuble'.$currentImmeuble.'/batiment'.$currentBatiment.'/demande';//.$currentDemande; // on cree le chemin vers le bon dossier
if(file_prepare_directory(&$batfilePath, $options = FILE_MODIFY_PERMISSIONS)){ // si ce dossier n'existe pas on le cree
$filePath = $batfilePath; // on modifie la valeur de $filePath
}
$form['lieu'] = array(
'#type' => 'fieldset',
'#title' => 'Lieu',
);
$form['lieu']['titles']= array(
'#type' => 'select',
'#title' => t('Nom de la copropri&eacute;t&eacute;'),
'#multiple' => FALSE,
'#default_value' => $currentCopro,
'#options' => $copros,
'#description' => t('S&eacute;lectionnez la copropri&eacute;t&eacute; de cet utilisateur'),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'copris_get_immeuble_by_copro',
'wrapper' => 'immeuble-list',
'event' => 'change',
),
);
$form['lieu']['immeubles']= array(
'#prefix' => '<div id="immeuble-list">',
'#suffix' => '</div>',
'#type' => 'select',
'#title' => t('Nom de l\'immeuble'),
'#multiple' => FALSE,
'#default_value' => $currentImmeuble,
'#options' => copris_get_immeubles($currentCopro, true, false),
'#description' => t('S&eacute;lectionnez l\'immeuble de cet utilisateur'),
'#required' => TRUE,
'#ajax' => array(
'callback' => 'copris_get_bat_by_immeuble_user',
'wrapper' => 'batiments-list',
'event' => 'change',
),
);
$form['lieu']['batiments']= array(
'#prefix' => '<div id="batiments-list">',
'#suffix' => '</div>',
'#type' => 'select',
'#title' => t('Nom du batiment'),
'#multiple' => FALSE,
'#default_value' => $currentBatiment,
'#options' => copris_get_batiment($currentImmeuble),
'#description' => t('S&eacute;lectionnez le batiment de cet utilisateur'),
'#required' => TRUE,
);
$form['lieu']['lot']= array(
'#type' => 'textfield',
'#title' => t('Lot'),
'#description' => t('S&eacute;lectionnez le lot pour la demande'),
'#required' => FALSE,
'#autocomplete_path' => 'copris/autocompleteLot',
'#default_value' => isset($form['#node']->field_lot_demande['und'][0]['value']) ? $form['#node']->field_lot_demande['und'][0]['value'] : '',
);
$form['fichier']['field_fichier_demande']['und'][0]['#upload_location']= $filePath;
// Création des champs selon l'état de la demande
// Attention ceci n'est valable qu'en mode création pour un administrateur de copro !!
if(user_access('Validate demande') && isset($form['#node']->field_etat_demande['und'][0]['value'])){
if($form['#node']->field_etat_demande['und'][0]['value'] == 'Valid&eacute;e'){
$form['valide'] = array(
'#type' => 'fieldset',
'#title' => 'Demande valid&eacute;e',
);
$form['valide']['date_prevue'] = $form['field_date_prevue'];
$form['valide']['intervenant'] = $form['field_intervenant'];
$form['valide']['mail_intervenant'] = $form['field_mail_intervenant'];
} elseif($form['#node']->field_etat_demande['und'][0]['value'] == 'Refus&eacute;e'){
$form['refuse'] = array(
'#type' => 'fieldset',
'#title' => 'Demande refus&eacute;e',
);
$form['refuse']['motif'] = $form['field_motif_refus'];
}
}
unset($form['field_date_prevue']['und']);
hide($form['field_intervenant']);
hide($form['field_motif_refus']);
hide($form['field_mail_intervenant']);
$form['actions']['submit']['#submit'][0] = 'copris_demande_submit';
$form['#validate'][] = 'copris_demande_validate';
}
if($form_id=='node_delete_confirm' && $form['#node']->type == 'demande'){
$form['#submit'][0] = 'copris_demande_delete';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment