Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define('MYSITE_MODULE_NAME', basename(__FILE__, '.module'));
- define('ALL_RECORDS_NODE_NID', 36);
- define('WORKFLOW_STATE_NEW_REQUEST', 2);
- define('WORKFLOW_STATE_CHECKING_ELIGIBILITY', 3);
- define('WORKFLOW_STATE_SUITABLE', 4);
- define('WORKFLOW_STATE_SENT_TO_CLUB_MOBILITE', 5);
- define('WORKFLOW_STATE_SENT_TO_GARAGE', 6);
- define('WORKFLOW_STATE_CANCELLED', 7);
- /**
- * Implementation of hook_views_query_alter
- * @param type $view
- * @param type $query
- */
- function omitsis_mobiliz_views_query_alter(&$view, &$query) {
- if ($view->name == 'check_eligibilite') {
- $node = menu_get_object();
- // kpr($node);
- $prenom = $node->field_record_prenom['und'][0]['safe_value'];
- $title = $node->title;
- $birth = $node->field_record_birth['und'][0]['value'];
- $email = $node->field_record_email['und'][0]['email'];
- //kpr($view);
- $view->query->where[1]['conditions'][2]['value'] = $prenom;
- $view->query->where[1]['conditions'][3]['value'] = $title;
- //$query->add_where(1,'field_data_field_record_email.field_record_email_email',$email,'=');
- $query->add_where(1,'field_data_field_record_birth.field_record_birth_value',$birth,'=');
- } elseif ($view->name == 'garage') {
- switch($view->current_display) {
- //Filter two digits
- case 'panel_pane_1':
- foreach($query->where[1]['conditions'] as $idx => $condition) {
- if ($condition['field'] == 'profile_users__field_data_field_garage_address.field_garage_address_postal_code') {
- $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
- $query->where[1]['conditions'][$idx]['value'] = $value.'%';
- }
- }
- break;
- case 'page_2':
- foreach($query->where[1]['conditions'] as $idx => $condition) {
- if($condition['field'] == 'profile_users__field_data_field_garage_address.field_garage_address_postal_code') {
- $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
- $query->where[1]['conditions'][$idx]['value'] = $value.'%';
- }
- }
- break;
- }
- } elseif ($view->name == 'prescribers' && $view->current_display == 'page') {
- foreach($query->where[1]['conditions'] as $idx => $condition) {
- if ($condition['field'] == 'field_data_field_prescriber_address.field_prescriber_address_postal_code') {
- $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
- $query->where[1]['conditions'][$idx]['value'] = $value.'%';
- }
- }
- }
- }
- function omitsis_mobiliz_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == 'views_form_records_panel_pane_3') {
- $form['field_supervisor_assign'][0]['actions']['edit']['#value'] = 'Désigner superviseur';
- }
- if ($form_id == 'views_form_records_panel_pane_5') {
- $form['field_record_presciber_user'][0]['actions']['edit']['#value']= 'Désigner agent prescripteur';
- }
- //Translating labels
- $form['sid']['#options']['All'] = "Choisissez l'option";
- $form['field_garage_type_tid']['#options']['All']= "Choisissez l'option";
- $form['field_request_type_tid']['#options']['All'] = "Choisissez l'option";
- $form['field_record_address']['und'][0]['street_block']['thoroughfare']['#title'] = 'Adresse';
- $form['field_record_address']['und'][0]['locality_block']['locality']['#title'] = 'Commune';
- $form['field_record_address']['und'][0]['locality_block']['postal_code']['#title'] = 'Code Postal';
- $form['field_record_commentaires']['und']['add_more']['#value'] = 'Ajouter un commentaire';
- //Modify edit profile
- if ($form_id == 'user_profile_form') {
- global $user;
- $userid = user_load($user->uid);
- $uid = user_load($user->uid);
- if (!in_array('4',array_keys($user->roles)) && in_array('4',array_keys($form['#user']->roles))) {
- $form['edit_g'] = array(
- '#markup' => '<div class="buttons-garage">
- <div class="garage-user"><a href="/user/'.$form['#user']->uid.'/edit/">Gestionar le compte</a></div>
- <div class="garage-profil"><a href="/user/'.$form['#user']->uid.'/edit/garage">Profil du garage</a> </div>
- </div>',
- '#weight' => -1,
- );
- }
- if (!in_array('4',array_keys($form['#user']->roles)) && ((in_array('7',array_keys($user->roles))) || (in_array('9',array_keys($user->roles))) || (in_array('3',array_keys($user->roles))))){
- $markup = '<div class="own-organisation"><div id="content">';
- $markup .= '<h3>Organisation</h3>';
- $markup .= views_embed_view('organisation_s_user', 'my_org');
- $markup .= '</div></div>';
- $form['own_organisation'] = array(
- '#markup' => $markup,
- '#weight' => 98,
- );
- $form['actions']['#weight'] = 97;
- $form['my_records'] = array(
- '#markup' => '<div class="my-demands"><h3>Demandes assignées à mon organisation</h3>'.views_embed_view('records', 'panel_pane_6').'</div>',
- '#weight' => 99
- );
- }
- //SUPERVISOR
- if (in_array('8',array_keys($user->roles))) {
- unset($form['field_organisation_partenaire']);
- $form['locale']['language']['#access'] = FALSE;
- }
- //FINANCIAL
- if (in_array('10',array_keys($user->roles))) {
- unset($form['field_organisation_partenaire']);
- $form['field_name_field_record_docs']['#access'] = FALSE;
- $form['locale']['language']['#access'] = FALSE;
- }
- //Prescriber
- if (in_array('7',array_keys($user->roles)) || in_array('9',array_keys($user->roles))) {
- $form['field_organisation_partenaire']['#access'] = FALSE;
- $form['field_name_field_record_docs']['#access'] = FALSE;
- $form['locale']['language']['#access'] = FALSE;
- if ($form['#user']->uid != $user->uid) {
- $form['actions']['#access'] = FALSE;
- }
- if ($form['#user']->field_organisation_partenaire['und'][0]['target_id'] != $userid->field_organisation_partenaire['und'][0]['target_id']) {
- drupal_goto('/toutes-les-demandes');
- }
- }
- //Prescriber Responsable
- if (in_array('9',array_keys($user->roles))) {
- $form['field_name_field_record_docs']['#access'] = FALSE;
- if ($form['#user']->field_organisation_partenaire['und'][0]['target_id'] == $userid->field_organisation_partenaire['und'][0]['target_id']) {
- $form['actions']['#access'] = TRUE;
- }
- }
- //GARAGE
- if (in_array('4',array_keys($user->roles))) {
- unset($form['field_organisation_partenaire']);
- $form['field_name_field_record_docs']['#access'] = FALSE;
- $form['locale']['language']['#access'] = FALSE;
- $types = profile2_get_types();
- if (!empty($types)){
- foreach ($types as $type) {
- $profile = profile2_load_by_user($form['#user'], $type->type);
- if (!empty($profile)) {
- $form_state['profiles'][$profile->type] = $profile;
- profile2_attach_form($form, $form_state);
- }
- }
- }
- }
- if ($form_id == 'user_profile_form') {
- unset($form['picture']);
- }
- $form['actions']['#prefix'] = '<div class="extra_div">';
- $form['actions']['#suffix'] = '</div>';
- }
- // Garage register form
- if ($form_id == 'webform_client_form_31') {
- // Create user and profile garage information for webform submit
- $form['#validate'][] = 'omitsis_garage_validate';
- $form['actions']['submit']['#submit'][] = 'omitsis_garage_save';
- }
- // Prescriber register form
- if ($form_id == 'webform_client_form_33') {
- $form['submitted']['mission_de_votre_structure']['#attributes'] = array('placeholder' => 'Quelle est votre mission globale? Quels services proposez-vous? Combien de personnes accompagnez-vous par an? Êtes-vous rattaché à une structure de tête (régionale ou nationale) ?');
- // Create organisation and prescriber user for webform submit
- $form['actions']['submit']['#submit'][] = 'omitsis_prescriber_save';
- }
- }
- function omitsis_garage_validate($form, &$form_state) {
- if(!empty($form_state['values']['submitted']['nom_du_garage'])) {
- $user = user_load_by_name($form_state['values']['submitted']['nom_du_garage']);
- if($user) {
- form_set_error('nom_du_garage', t('Nom du garage @name already exist.', array('@name' => $form_state['values']['submitted']['nom_du_garage'])));
- }
- }
- }
- function omitsis_garage_save($form, &$form_state) {
- $password = ($form_state['values']['submitted']['cp']) ? $form_state['values']['submitted']['nom_du_garage'].$form_state['values']['submitted']['cp']: $form_state['values']['submitted']['nom_du_garage'].'2345';
- $new_user = array(
- 'name' => $form_state['values']['submitted']['nom_du_garage'],
- 'pass' => $password, // note: do not md5 the password
- 'mail' => $form_state['values']['submitted']['email'],
- 'status' => 0,
- 'init' => $form_state['values']['submitted']['email'],
- 'roles' => array(
- DRUPAL_AUTHENTICATED_RID => 'authenticated user',
- 4 => 'garage',
- ),
- );
- // The first parameter is sent blank so a new user is created.
- $user = user_save('', $new_user);
- // Where 'main' is your profile2 type machine name.
- $profile = profile2_create(array('type' => 'garage', 'uid' => $user->uid));
- if (!empty($form_state['values']['submitted']['direction_regionale_de_rattachement'])) {
- $profile->field_garage_regional_directorat[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['direction_regionale_de_rattachement'];
- }
- if (!empty($form_state['values']['submitted']['telephon'])) {
- $profile->field_garage_telephone[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['telephon'];
- }
- if (!empty($form_state['values']['submitted']['adresse'])) {
- $profile->field_garage_address[LANGUAGE_NONE][0] = array(
- "country" => "FR",
- "thoroughfare" => $form_state['values']['submitted']['adresse'],
- "locality" => $form_state['values']['submitted']['localite'],
- "postal_code" => $form_state['values']['submitted']['cp'],
- );
- }
- if (!empty($form_state['values']['submitted']['personne_a_contacter'])) {
- $profile->field_gargae_contact_person[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['personne_a_contacter'];
- }
- // Save the profile2 to the user account.
- profile2_save($profile);
- drupal_goto('/thank-you');
- }
- function omitsis_prescriber_save($form, &$form_state) {
- // add node properties
- $newNode = new stdClass();
- $newNode->type = 'organisation_partenaire';
- $newNode->title = $form_state['values']['submitted']['nom_de_lorganisation_partenaire'];
- node_object_prepare($newNode); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
- $newNode->language = LANGUAGE_NONE;
- $newNode->uid = 1;
- $newNode->status = 0;
- $newNode->comment = 0;
- $newNode->promote = 0;
- if ($form_state['values']['submitted']['vos_publics']) {
- $vos = $form_state['values']['submitted']['vos_publics'];
- foreach ($vos as $tids => $tid) {
- if ($tid != 0) {
- $newNode->field_prescriber_personal_sit[$newNode->language][]['tid'] = $tid;
- }
- }
- }
- if($form_state['values']['submitted']['mission_de_votre_structure']) {
- $newNode->field_prescriber_description[$newNode->language][0]['value'] = $form_state['values']['submitted']['mission_de_votre_structure'];
- }
- if(!empty($form_state['values']['submitted']['heure_de_contact_souhaite'])) {
- $newNode->field_prescriber_accept[$newNode->language][0]['value'] = $form_state['values']['submitted']['heure_de_contact_souhaite'][1];
- }
- $newNode = node_submit($newNode); // Prepare node for saving
- node_save($newNode);
- $password = $form_state['values']['submitted']['prenom'] . $form_state['values']['submitted']['nom'] . '2345';
- $new_user = array(
- 'name' => $form_state['values']['submitted']['prenom'] . $form_state['values']['submitted']['nom'],
- 'pass' => $password, // note: do not md5 the password
- 'mail' => $form_state['values']['submitted']['e_mail'],
- 'status' => 0,
- 'init' => $form_state['values']['submitted']['e_mail'],
- 'roles' => array(
- DRUPAL_AUTHENTICATED_RID => 'authenticated user',
- 9 => 'prescriber boss',
- ),
- 'field_user_name' => array(
- LANGUAGE_NONE => array(
- 0 => array(
- 'value' => $form_state['values']['submitted']['prenom']
- ),
- ),
- ),
- 'field_user_surname' => array(
- LANGUAGE_NONE => array(
- 0 => array(
- 'value' => $form_state['values']['submitted']['nom']
- ),
- ),
- ),
- 'field_telephone' => array(
- LANGUAGE_NONE => array(
- 0 => array(
- 'value' => $form_state['values']['submitted']['telephon']
- ),
- ),
- ),
- 'field_organisation_partenaire' => array(
- LANGUAGE_NONE => array(
- 0 => array(
- 'target_id' => $newNode->nid
- ),
- ),
- ),
- );
- // The first parameter is sent blank so a new user is created.
- $user = user_save('', $new_user);
- drupal_goto('/thank-you');
- }
- function omitsis_mobiliz_form_record_node_form_alter(&$form, &$form_state, $form_id){
- global $user;
- $form['field_request_type']['und']['#options']['_none'] = 'Choisissez un service';
- $form['field_record_mail_survey']['#access'] = FALSE;
- // New record
- if(empty($form['nid']['#value'])){
- //Add new record button
- $form['actions']['submit']['#value'] = 'Sauvegarder saisie';
- $form['field_request_type']['und']['#options']['_none'] = 'Choisissez une offre';
- $args = arg();
- // remove fields from front page add new record
- if($args[1] != 'add' && $args[2] != 'record') {
- $form['actions']['submit']['#value'] = "ENVOYER MA DEMANDE DE CONTACT" ; //Canvi nom botó
- $form['#after_build'][] = '_mobiliz_after_build';
- $hidden_fields_node_add_front = array(
- 'field_brand_vo', 'field_brand','field_elegibilite','field_other_docs','field_commentaire_eligibilite','field_record_workflow', 'field_record_mail_survey','field_record_garage_selected', 'field_record_rejected', 'field_record_commentaires', 'field_record_docs',
- 'field_record_assigned', 'field_record_birth', 'field_record_tel_mobile', 'field_record_geolocation',
- 'field_l_situation_emploie','field_l_document','field_record_presciber_user','field_l_date_acceptation','field_record_l_solution_mobilite','field_record_address', '#group_children', 'additional_settings', 'revision_information', 'options', 'author', 'field_record_assigned_finantial','field_record_personal_situation','field_supervisor_assign','field_record_type','field_record_l_situation','field_nom_de_l_organisme_finance','field_l_situation_personnelle','field_l_creation_entreprise','field_montant_du_premier_loyer_m','field_montant_des_options_suppl_','field_montant_total','field_montant_financ_par_micro_c','field_reste_payer_le_jour_de_la_','field_montant_de_l_er_la_fin_du_','field_record_address','field_field_record_address2','field_record_code_postal','field_l_description_sit_pers','field_l_siret_entreprise');
- foreach($hidden_fields_node_add_front as $field){
- unset($form[$field]);
- }
- }
- //if prescriber add new record, autoassign for their entity
- global $user;
- $uid = user_load($user->uid);
- if ((in_array('7',array_keys($user->roles))) || (in_array('9',array_keys($user->roles))) || (in_array('3',array_keys($user->roles)))){
- $organisation = $uid->field_organisation_partenaire['und'][0]['target_id'];
- $form['field_record_assigned']['und']['#default_value'] = $organisation;
- }
- // remove fields related to record type from new record form
- $hidden_fields_new_record = array(
- 'field_record_r_plate', 'field_record_r_vehicle_age', 'field_record_r_brand', 'field_record_r_model', 'field_record_r_total_mileage', 'field_record_r_problems',
- 'field_record_u_brand', 'field_record_u_model', 'field_record_u_car_body', 'field_record_u_motorization', 'field_record_u_maximum_mileage', 'field_record_u_maximum_budget',
- 'field_record_l_situation', 'field_record_l_particular_cars', 'field_record_l_professional_cars', 'field_record_l_amount_funding', 'field_record_l_adie',
- 'field_record_substates_'.WORKFLOW_STATE_CANCELLED);
- foreach($hidden_fields_new_record as $field){
- unset($form[$field]);
- }
- if (empty($form['field_record_closing_explanation']['und'][0]['value']['#default_value'])) {
- unset($form['field_record_closing_explanation']);
- }
- // copy the code postal value from address field to new fields of addres and cp (encrypt issues)
- $form['#submit'][] = '_mobiliz_postal_code_save';
- $form['actions']['submit']['#submit'][] = '_mobiliz_postal_code_save';
- if (!in_array('3',array_keys($user->roles))) {
- unset($form['field_supervisor_assign']);
- }
- }
- // Editing an existing record
- if(!empty($form['nid']['#value'])) {
- $form['actions']['submit']['#value'] = 'Sauvegarder saisie';
- $nid = $form['nid']['#value'];
- $node = $form['#node'];
- $form['actions']['inner'] = array(
- '#type' => 'container'
- );
- if (!_mobiliz_user_is_admin()) {
- global $user;
- $user_fields = user_load($user->uid);
- $assigned = _mobiliz_get_field($node, 'field_record_assigned', 'target_id');
- $garage_assigned = _mobiliz_get_field($node, 'field_record_garage_selected', 'target_id');
- $organisation = $user_fields->field_organisation_partenaire['und'][0]['target_id'];
- //PRESCRIBERS
- if (in_array('7',array_keys($user->roles)) || in_array('9',array_keys($user->roles))) {
- $form['field_record_docs']['#access'] = FALSE;
- if ($assigned != $organisation) {
- // access denied si el prescriptor no tiene asignado el record (partiendo de la reference)
- //drupal_access_denied();
- drupal_goto('toutes-les-demandes');
- } else {
- // disable delete button if not admin
- $form['actions']['delete']['#access'] = FALSE;
- $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
- }
- }
- //GARAGE
- else if (in_array('4',array_keys($user->roles))){
- $form['field_record_docs']['#access'] = FALSE;
- if ($garage_assigned != $user->uid) {
- // access denied si el prescriptor no tiene asignado el record (partiendo de la reference)
- drupal_goto('toutes-les-demandes');
- } else {
- // disable delete button if not admin
- $form['actions']['delete']['#access'] = FALSE;
- $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
- }
- }
- // FINANCIAL
- else if (in_array('10',array_keys($user->roles))){
- $form['field_record_docs']['#access'] = FALSE;
- $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
- $form['field_record_closing_explanation']['#access'] = FALSE;
- }
- }
- // unset N/A options for non-mandatory fields
- unset($form['field_elegibilite']['und']['#options']['_none']);
- unset($form['field_record_u_car_body'][LANGUAGE_NONE]['#options']['_none']);
- unset($form['field_record_l_situation'][LANGUAGE_NONE]['#options']['_none']);
- unset($form['field_record_l_particular_cars'][LANGUAGE_NONE]['#options']['_none']);
- unset($form['field_record_l_professional_cars'][LANGUAGE_NONE]['#options']['_none']);
- unset($form['field_l_situation_emploie'][LANGUAGE_NONE]['#options']['_none']);
- unset($form['field_record_term_confirmation']);
- unset($form['field_l_creation_entreprise'][LANGUAGE_NONE]['#options']['_none']);
- // redirect to node edit
- $form['#submit'][] = '_mobiliz_postal_code_save';
- $form['actions']['submit']['#submit'][] = '_mobiliz_postal_code_save';
- //$form['#submit'][] = '_mobiliz_record_submit';
- $form['actions']['submit']['#submit'][] = '_mobiliz_record_submit';
- // hide record type selector to prevent changes
- // but add a normal div to keep a trace of what type of record this is
- // and create a container for the form (for the sake of design)
- //$form['field_record_type']['#access'] = FALSE;
- //$type = _mobiliz_get_field($node, 'field_request_type', 'value');
- $form['selected_record'] = array(
- '#markup' => _mobiliz_render_block('views', 'records-single'),
- '#weight' => 2
- );
- $form['18_months']= array(
- '#markup' => views_embed_view('check_eligibilite', 'block_1'),
- '#weight' => 1,
- ); //-> si la data que retorna es 18 mesos (maxim) abans que la actual -> no cal verificar, else -> verificar
- $type = $form['field_request_type']['und']['#default_value'][0];
- if (empty($type)) $type = 33;
- $form['record_container'] = array(
- '#type' => 'container',
- '#weight' => 0,
- '#tree' => true,
- '#attributes' => array('class' => array('type-' . $type)),
- );
- $form['record_container']['field_record_type_selected'] = array(
- '#markup' => '<div class="record-type record-type-' . $type . ' element-invisible">' . $type . '</div>'
- );
- if (in_array('3',array_keys($user->roles)) || in_array('8',array_keys($user->roles)) || in_array('11',array_keys($user->roles))) {
- $form['record_container']['doc_info'] = array(
- //'#markup' => '<div class="doc-info">'. t('Add documentacion info').'</div>'
- );
- }
- if (in_array('3',array_keys($user->roles)) || in_array('11',array_keys($user->roles))) {
- /* Survey button */
- $form['surve_link'] = array(
- '#markup' => l(t('Access to Survey'), url('entretien-reparation-questionnaire?nid=40'.$nid), array('attributes' => array('class' => array('survey-button')))),
- );
- }
- $form['record_container']['identification'] = array(
- '#markup' => '<div class="identification-infodep">'. t("Merci d'indiquer les informations du bénéficiaire").'</div>'
- );
- /*$form['actions']['inner']['taches'] = array(
- '#markup' => '<div class="taches-realiz">'. t("Tà ches à réaliser").'</div>'
- );*/
- $geo = _mobiliz_get_latlng($nid);
- $type = $form['#node']->field_request_type['und'][0]['tid'];
- $personal_situation = $form['#node']->field_record_personal_situation;
- $brand = $form['#node']->field_brand['und'][0]['tid'];
- //kpr($brand);
- /**
- * Record info
- */
- if (in_array('3',array_keys($user->roles)) || in_array('8',array_keys($user->roles)) || in_array('11',array_keys($user->roles)) || (in_array('3',array_keys($user->roles)))) {
- /* if geo is location of france country only. reset $geo */
- if ($geo['lat'] == '46.227638' && $geo['lng'] == '2.213749') {
- unset($geo);
- }
- /**
- *
- * ASSIGN TO
- *
- */
- // show another empty ajax view and solved problem with multiple views ajax on form
- $markup = views_embed_view('ajax_null', 'block');
- $markup .= '<div id="prescribers-geo">';
- if (!empty($form['#node']->field_record_assigned)) {
- $markup .= _mobiliz_get_nearby_view($geo, 'assignable_prescribers', 'prescriber_nearby_selected', $form['#node']->field_record_assigned[LANGUAGE_NONE][0]['target_id']);
- //$markup .= views_embed_view('assignable_prescribers', 'prescriber_nearby_selected', $form['#node']->field_record_assigned[LANGUAGE_NONE][0]['target_id']);
- }
- if (!$geo) {
- $markup .= '<div class="view-id-assignable_users view-display-id-prescriber_nearby">' . t('Veuillez introduire l\'adresse du bénéficiaire afin de pouvoir sélectionner les prescripteurs plus proches.') . '</div>';
- // Get Ps-> save node and redirect to this tab
- $form['get-ps'] = array(
- '#type' => 'submit',
- '#value' => t('Obtenir liste des prescripteurs'),
- '#access' => TRUE,
- '#submit' => array('submit_button_1_submit'),
- '#weight' => -10,
- );
- } else {
- $markup .= '';
- $markup .= _mobiliz_get_nearby_view($geo,'assignable_prescribers', 'prescriber_nearby', array(), $personal_situation, $type);
- }
- $markup .= '</div>';
- $form['assign_to_views'] = array(
- '#markup' => $markup
- );
- }
- // Show
- if (!(in_array('8',array_keys($user->roles)) || in_array('3',array_keys($user->roles)) || in_array('11',array_keys($user->roles)))) {
- foreach($form['#group_children'] as $key => $value) {
- if ($value == 'group_record_assigned_prescriber') {
- unset($form['#group_children'][$key]);
- }
- }
- //$form['field_request_type']['#access'] = FALSE;
- unset($form['field_supervisor_assign']);
- unset($form['#fieldgroups']['group_record_assigned_prescriber']);
- // unset($form['field_record_docs']);
- foreach($form['#group_children'] as $key => $value) {
- if ($value == 'group_administration') {
- unset($form['#group_children'][$key]);
- }
- }
- unset($form['#fieldgroups']['group_administration']);
- }
- //SUPERVISOR
- if (in_array('8',array_keys($user->roles))) {
- foreach($form['#group_children'] as $key => $value) {
- if ($value == 'group_administration') {
- unset($form['#group_children'][$key]);
- }
- unset($form['field_supervisor_assign']);
- }
- if (isset($form['field_record_assigned']['und']['#default_value'][0])) {
- $form['actions']['#access'] = FALSE;
- }
- }
- //IF GARAGE DISABLE BUTTONS
- if (in_array('4',array_keys($user->roles))) {
- $form['actions']['#access'] = FALSE;
- foreach($form['#group_children'] as $key => $value) {
- if ($value == 'group_record_garage_info') {
- unset($form['#group_children'][$key]);
- }
- }
- }
- if (in_array('10',array_keys($user->roles))) {
- }
- if (!in_array('3',array_keys($user->roles)) && in_array('3',array_keys($user->roles)) && isset($form['field_record_assigned']['und']['#default_value'][0])) {
- $form['actions']['#access'] = FALSE;
- }
- $form['#groups']['group_record_garage_info']->children[] = 'garage_selection_views';
- $form['#group_children'][] = 'garage_selection_views';
- $form['#fieldgroups']['group_record_assigned_prescriber']->type = 'hidden';
- /**
- *
- * GARAGE SELECT
- *
- */
- if (!in_array('4',array_keys($user->roles))) {
- $markup = '<div id="garage-geo">';
- if (!$geo) {
- $markup .= '<div class="view-id-garage view-display-id-garage_nearby">' . t('No address information available. Check that the user address is set in the information tab.') . '</div>';
- // Get garage -> save node and redirect to this tab
- $form['get-grs'] = array(
- '#type' => 'submit',
- '#value' => t('Obtenir liste des garajes'),
- '#access' => TRUE,
- '#submit' => array('submit_button_2_submit'),
- '#weight' => -10,
- );
- } else {
- $markup .= '<div id="hidden-geo" style="display:none;"><div id="geo-lng">'. $geo['lng'] .'</div><div id="geo-lat">'.$geo['lat'].'</div></div>';
- $markup .= '<div id="garage-description">' . t('Voici les garages les plus proches attribués àcette demande en fonction du code postal du bénéficiaire. Vous pouvez le modifier si nécessaire') . '</div>';
- if (!empty($form['#node']->field_record_garage_selected)) {
- foreach ($form['#node']->field_record_garage_selected[LANGUAGE_NONE] as $key => $value) {
- $garages_nids[] = $value['target_id'];
- }
- if ($node->field_request_type['und'][0]['tid'] != 35 && $node->field_request_type['und'][0]['tid'] != 102) {
- $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_selected', implode('+', $garages_nids));
- }
- elseif ($node->field_request_type['und'][0]['tid'] == 102) {
- $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_selected_vn', implode('+', $garages_nids));
- }
- //$markup .= views_embed_view('garage', 'garage_nearby_selected', implode('+', $garages_nids));
- }
- if (!empty($node->field_request_type)) {
- if ($node->field_request_type['und'][0]['tid'] == 33
- ) {
- // Show form filter on garage view
- $markup .= '';
- $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby', $brand);
- }
- elseif ($node->field_request_type['und'][0]['tid'] == 102
- ) {
- // Show form filter on garage view
- $markup .= '<div id="edit-field-garage-address-postal-code-wrapper2" class="views-exposed-widget views-widget-filter-field_garage_address_postal_code">
- <label for="edit-field-garage-address-postal-code">' . t('Code postal du bénéficiaire') . ' </label>
- <div class="views-widget">
- <div class="form-item form-type-textfield form-item-field-garage-address-postal-code">
- <input id="edit-field-garage-address-postal-code2" name="field_garage_address_postal_code2" value="" size="30" maxlength="128" class="form-text" type="text">
- </div>
- <input id="edit-button-garage" name="Chercher" value="Chercher" class="form-submit" type="button">
- </div>
- </div>';
- $markup .= '';
- $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_vn', $brand);
- }
- elseif ($node->field_request_type['und'][0]['tid'] == 35) {
- // Save garages when is VO
- $garages = _mobiliz_get_nearby_view_data($geo, 'garage', 'garage_nearby_vo');
- foreach ($garages as $key => $value) {
- $form['field_record_garage_selected']['und'][$key] = $form['field_record_garage_selected']['und'][0];
- $form['field_record_garage_selected']['und'][$key]['target_id']['#default_value'] = "{$value->users_name} ($value->uid)";
- }
- $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_vo');
- }
- }
- //$markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby');
- }
- $markup .= '</div>';
- $form['garage_selection_views'] = array(
- '#markup' => $markup
- );
- $form['#groups']['group_record_garage_info']->children[] = 'garage_selection_views';
- $form['#group_children'][] = 'garage_selection_views';
- }
- /**
- *
- * WORKFLOW GUIDE BUTTONS
- *
- */
- $state_sid = _mobiliz_get_field($node, 'field_record_workflow', 'value');
- $form['#attributes']['class']['3'] = 'form-state-'.$state_sid;
- $form['record_container']['field_record_status'] = array(
- '#markup' => '<div class="record-status record-status-'.$state_sid.' element-invisible">'.$state_sid.'</div>'
- );
- // creates the states flow arrows
- $states = _mobiliz_workflow_get_states();
- $states_markup = '<ul class="states-flow type-'.$type.'">';
- foreach($states as $key => $state){
- if(($state['sid'] != WORKFLOW_STATE_CANCELLED) && ($state['sid'] != WORKFLOW_STATE_SENT_TO_CLUB_MOBILITE)) {
- if ($state_sid == $state['sid'] && $form['field_request_type']['und']['#default_value'][0] != 102) {
- $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active">' . $state['state'] . '</li>';
- }
- elseif ($state_sid == $state['sid'] && $state['state'] == 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
- $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active">ENVOYÉ AU CLUB MOBILITÉ</li>';
- }
- elseif ($state['state'] == 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
- $states_markup .= '<li class="state-flow state-' . $state['sid'] . '">ENVOYÉ AU CLUB MOBILITÉ</li>';
- }
- elseif ($state_sid == $state['sid'] && $state['state'] != 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
- $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active ">' . $state['state'] . '</li>';
- }
- else {
- $states_markup .= '<li class="state-flow state-' . $state['sid'] . '">' . $state['state'] . '</li>';
- }
- }
- }
- $states_markup .= '</ul>';
- $form['states_flow'] = array(
- '#markup' => $states_markup,
- '#weight' => 1
- );
- $substate_fields = array(
- 1 => 'field_record_substates_'.WORKFLOW_STATE_NEW_REQUEST, 2 => 'field_record_substates_'.WORKFLOW_STATE_CHECKING_ELIGIBILITY,
- 3 => 'field_record_substates_'.WORKFLOW_STATE_SUITABLE, 4 => 'field_record_substates_5',
- 6 => 'field_record_substates_6', 7 => 'field_record_substates_'.WORKFLOW_STATE_CANCELLED,
- );
- // 1. put actual state substates checkboxes in actions container
- // 2. put cancelled substate checkboxes at the end of the actions container
- foreach($substate_fields as $key => $field){
- $id = substr($field, -1);
- // unset N/A options for non-mandatory fields
- unset($form[$field][LANGUAGE_NONE]['#options']['_none']);
- if($field != 'field_record_substates_7'){
- if($id != $state_sid){
- // hides substates that are not children of the actual state
- //kpr($id);
- unset($form[$field]);
- }else{
- if($id == $state_sid){
- // puts current state substates in actions container
- $form['actions']['inner'][$field] = $form[$field];
- $form['actions']['inner'][$field]['#weight'] = 0;
- }
- unset($form[$field]);
- }
- }else{
- // what to do with cancelled states?
- // they should go in a fancybox
- $form['actions']['inner'][$field] = $form[$field];
- $form['actions']['inner']['field_record_closing_explanation'] = $form['field_record_closing_explanation'];
- $form['actions']['inner'][$field]['#weight'] = 1000;
- unset($form[$field]);
- }
- }
- // assigned financial disable
- $form['field_record_assigned_finantial']['#access'] = FALSE;
- /**
- *
- * BUTTONS
- *
- */
- // back button
- $form['back'] = array(
- '#type' => 'submit',
- '#value' => t('< Revenir a la liste des demandes'),
- '#attributes' => array('data-action' => array('btn-back')),
- '#weight' => -10,
- '#prefix' => '<div class="revenire"><div class="container">',
- '#suffix' => '</div></div>',
- '#submit' => array('_mobiliz_record_back')
- );
- // add a container for buttons like save, cancel, delete..
- $form['actions']['inner']['buttons'] = array(
- '#type' => 'container',
- '#tree' => true,
- '#weight' => 1,
- );
- // add cancel button
- $form['actions']['inner']['buttons']['cancel'] = array(
- '#markup' => l(t('Annuler saisie'), url('node/'.$nid.'/edit'), array('attributes' => array('class' => array('btn-cancel'), 'data-action' => array('action-cancel')))),
- '#weight' => 0,
- );
- $form['actions']['inner']['buttons']['submit'] = $form['actions']['submit'];
- $form['actions']['inner']['buttons']['delete'] = $form['actions']['delete'];
- $form['actions']['inner']['buttons']['delete']['#weight'] = -10;
- $form['actions']['inner']['buttons']['delete']['#value'] = 'Supprimer dossier';
- // remove standard buttons
- unset($form['actions']['submit']);
- unset($form['actions']['delete']);
- $form['actions']['salva'] = array(
- '#type' => 'hidden',
- '#access' => TRUE,
- '#weight' => 10,
- );
- /**
- *
- *
- * Caso cerrado
- *
- *
- */
- if($state_sid != '6' && $state_sid != '7') {
- if ($state_sid == '2') {
- $form['false'] = array(
- '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Poursuivre l\'étude du dossier</span></div>',
- '#weight' => 1
- );
- }
- if ($state_sid == '3') {
- $form['false'] = array(
- '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Valider l\'éligibilité</span></div>',
- '#weight' => 1
- );
- }
- if ($state_sid == '4') {
- $form['false'] = array(
- '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Envoyer au garage</span></div>',
- '#weight' => 1
- );
- }
- if ($state_sid == '4' && $form['field_request_type']['und']['#default_value'][0] == 102) {
- $form['false'] = array(
- '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Envoyer au Club Mobilité</span></div>',
- '#weight' => 1
- );
- }
- }
- /**
- *
- * CLOSE RECORD BUTTON + TRIGGER
- *
- */
- if ($state_sid =='7') {
- //kpr($form);
- if (isset($form['field_record_closing_explanation']['und'][0])) {
- $form['actions']['inner']['closed']= array(
- '#markup' => views_embed_view('records', 'closing',$form['nid']['#value']),
- '#weight' => 1
- );
- }
- }
- if (!in_array('10',array_keys($user->roles)) && !in_array('3',array_keys($user->roles)) && $state_sid==5){
- $form['actions']['#access'] = FALSE;
- }
- if (!in_array('10',array_keys($user->roles))) {
- //Add false button, when click show cancel options and trigger
- if($state_sid != WORKFLOW_STATE_CANCELLED && $state_sid != '6' ){
- $form['actions']['inner']['closing']= array(
- '#markup' => '<span class="confirm" id="edit-close-record-trigger">Abandon du dossier</span>',
- '#weight' => 1
- );
- $form['actions']['inner']['closing-2']= array(
- '#markup' => '<span class="confirm" id="edit-close-record-trigger-2">Abandon du dossier</span>',
- '#weight' => 1
- );
- }
- }
- }
- }
- /**
- * Back button redirect to all records page
- * @return [type] [description]
- */
- function _mobiliz_record_back(){
- drupal_goto('toutes-les-demandes');
- exit;
- }
- function _mobiliz_postal_code_save($form, &$form_state) {
- // Postal code Save on other fields
- $form_state['values']['field_field_record_address2']['und'][0]['postal_code'] = $form_state['values']['field_record_address']['und'][0]['postal_code'];
- $form_state['values']['field_record_code_postal']['und'][0]['value'] = $form_state['values']['field_record_address']['und'][0]['postal_code'];
- }
- /**
- * Record edit: on save redirect to same node edit
- * @param [type] $form [description]
- * @param [type] &$form_state [description]
- * @return [type] [description]
- */
- function _mobiliz_record_submit($form, &$form_state) {
- $state_id = $form_state['values']['field_record_workflow']['und'][0]['workflow']['workflow_sid'];
- $params['record_nid'] = $form_state['values']['nid'];
- if($form_state['clicked_button']['#value'] == 'Next step') {
- if ($state_id == 3 && (isset($form_state['values']['field_record_assigned']['und']['#value']))
- || isset($form_state['values']['field_record_assigned']['und']['0']['target_id'])) {
- // Mail prescriber assigned
- drupal_mail('mobiliz_record', 'record_mail_to_prescriptor_assign', $to, $language, $params, $from = NULL, $send = TRUE);
- }
- if ($state_id == 6) {
- /* Record Leasing send mails */
- if ($form_state['values']['field_request_type']['und'][0]['tid'] == 102) {
- //drupal_mail('mobiliz_record', 'record_l_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
- drupal_mail('mobiliz_record', 'record_mail_to_prescriptor_club_mobiliz', $to, $language, $params, $from = NULL, $send = TRUE);
- drupal_mail('mobiliz_record', 'record_l_mail_to_cm', $to, $language, $params, $from = NULL, $send = TRUE);
- }
- /* Record Repair send mails */
- if ($form_state['values']['field_request_type']['und'][0]['tid'] == 33) {
- drupal_mail('mobiliz_record', 'record_r_mail_to_garage', $to, $language, $params, $from = NULL, $send = TRUE);
- drupal_mail('mobiliz_record', 'record_r_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
- drupal_mail('mobiliz_record', 'record_r_mail_to_prescriber', $to, $language, $params, $from = NULL, $send = TRUE);
- }
- /* Record VO send mails */
- if ($form_state['values']['field_request_type']['und'][0]['tid'] == 35) {
- drupal_mail('mobiliz_record', 'record_vo_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
- drupal_mail('mobiliz_record', 'record_vo_mail_to_prescriber', $to, $language, $params, $from = NULL, $send = TRUE);
- $node = node_load($form_state['values']['nid']);
- foreach($node->field_record_garage_selected['und'] as $key => $value) {
- $profile = profile2_load_by_user($value['target_id'], 'garage');
- if (valid_email_address($profile->field_garage_email['und'][0]['email'])) {
- drupal_mail('mobiliz_record', 'record_vo_mail_to_garages', $profile->field_garage_email['und'][0]['email'], $language, $params, $from = NULL, $send = TRUE);
- }
- }
- }
- }
- }
- if (!empty($form['nid']['#value'])) {
- // redirect al mismo nodo si es edit
- //$form_state['redirect'] = 'node/'.$form['nid']['#value'] . '/edit';
- $node = node_form_submit_build_node($form, $form_state);
- $fragment = $form_state['values']['salva'];
- node_save($node);
- if ($node->nid) {
- $form_state['values']['nid'] = $node->nid;
- $form_state['nid'] = $node->nid;
- $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => $fragment));
- }
- }else{
- // todo: si es un nuevo record, donde redirije? aun no está el node
- }
- //$_GET['destination'] = $form_state['redirect'];
- }
- /**
- * Implements hook_block_info().
- */
- function omitsis_mobiliz_block_info() {
- $blocks['social_networks_links'] = array(
- 'info' => MYSITE_MODULE_NAME . ': Social Networks links',
- 'cache' => DRUPAL_CACHE_PER_ROLE, //Default
- );
- return $blocks;
- }
- /**
- * Implements hook_block_view().
- *
- * Prepares the contents of the block.
- */
- function omitsis_mobiliz_block_view($delta = '') {
- $block = array();
- switch ($delta) {
- case 'social_networks_links':
- $block['subject'] = '';
- $block['content'] = omitsis_mobiliz_render_social_network_links();
- break;
- }
- }
- /**
- * Implements hook_theme().
- */
- function omitsis_mobiliz_theme($existing, $type, $theme, $path) {
- return array(
- 'social_network_links' => array(
- 'variables' => array('list' => array()),
- 'template' => 'theme/social_network_links',
- ),
- );
- }
- /**
- * Implements hook_menu().
- */
- function omitsis_mobiliz_menu() {
- $items = array();
- /*
- $items['node/%'] = array(
- 'page callback' => '_mobiliz_node_view_redirect',
- 'page arguments' => array(1),
- 'access arguments' => array('create record content'),
- );
- */
- $items['record/%/change/state/%'] = array(
- 'page callback' => '_mobiliz_workflow_state_change',
- 'page arguments' => array(1,4),
- 'access arguments' => array('create record content'),
- );
- $items['admin/config/services/config'] = array(
- 'title' => 'Site configuration',
- 'description' => 'Change parameters for this site.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('omitsis_mobiliz_settings'),
- 'access arguments' => array('administer mobiliz settings'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['test'] = array(
- 'page callback' => '_mobiliz_test',
- 'access arguments '=> array('administer mobiliz settings')
- );
- return $items;
- }
- /**
- * Redirect a node view to its node edit
- * if it belongs to the rediractable types array defined here
- * @param [type] $nid [description]
- * @return [type] [description]
- */
- function _mobiliz_node_view_redirect($nid){
- if(empty($nid)) return false;
- $rediractable_types = array('record');
- $type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(":nid" => $nid))->fetchField();
- if(in_array($type, $rediractable_types)){
- drupal_goto('node/'.$nid.'/edit');
- exit;
- }
- }
- /**
- * Implements hook_permission().
- */
- function omitsis_mobiliz_permission(){
- return array(
- 'administer mobiliz settings' => array(
- 'title' => t("Administer Mobiliz Site settings"),
- ),
- );
- }
- function _mobiliz_record_cancel_submit(){
- drupal_goto('records');
- exit;
- }
- /**
- * Implementation of hook_menu_alter().
- */
- function omitsis_mobiliz_menu_alter(&$items) {
- // remove the /node page
- global $user;
- unset($items['node']);
- }
- /**
- * Page callback: Current posts settings
- *
- * @see omitsis_mobiliz_menu()
- */
- function omitsis_mobiliz_settings($form, &$form_state) {
- $form = array();
- // SOCIAL NETWORKS
- $form['social'] = array(
- '#type' => 'fieldset',
- '#title' => t("Social networks"),
- '#description' => t("Defines all social networks in the site"),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $social_types = omitsis_mobiliz_get_social_types();
- foreach ($social_types as $social_machine => $social_name) {
- $field = 'social_' . $social_machine;
- $form['social'][$field] = array(
- '#type' => 'textfield',
- '#title' => $social_name,
- '#default_value' => variable_get('omitsis_mobiliz_' . $field, ''),
- '#size' => 64,
- );
- }
- $form['#submit'][] = 'omitsis_mobiliz_settings_form_submit';
- return system_settings_form($form);
- }
- /**
- * Implements validation from the Form API.
- *
- * @param $form
- * A structured array containing the elements and properties of the form.
- * @param $form_state
- * An array that stores information about the form's current state
- * during processing.
- */
- function omitsis_mobiliz_settings_validate($form, &$form_state){
- // SOCIAL NETWORKS
- $social_types = omitsis_mobiliz_get_social_types();
- foreach ($social_types as $social_machine => $social_name) {
- $field = 'social_' . $social_machine;
- $value = $form_state['values'][$field];
- if ($value != '' && !valid_url($value, true)) {
- form_set_error($field, t("Invalid url format"));
- }
- }
- }
- /**
- * Implements submission from the Form API.
- *
- * @param $form
- * A structured array containing the elements and properties of the form.
- * @param $form_state
- * An array that stores information about the form's current state
- * during processing.
- */
- function omitsis_mobiliz_settings_form_submit($form, &$form_state) {
- // Attention! use ['value'] at the end for 'text_format' fields
- // SOCIAL NETWORKS
- $social_types = omitsis_mobiliz_get_social_types();
- foreach ($social_types as $social_machine => $social_name) {
- $field = 'social_' . $social_machine;
- variable_set('omitsis_mobiliz_' . $field, $form_state['values'][$field]);
- }
- }
- function omitsis_mobiliz_render_social_network_links() {
- $final_list = array();
- $social_types = omitsis_mobiliz_get_social_types();
- foreach ($social_types as $social_machine => $social_name) {
- $field = 'social_' . $social_machine;
- $social_url = variable_get('omitsis_mobiliz_' . $field, '');
- if ($social_url != '') {
- $final_list[] = array(
- 'machine_name' => $social_machine,
- 'name' => $social_name,
- 'url' => $social_url,
- );
- }
- }
- $variables = array(
- 'list' => $final_list,
- );
- return theme('social_network_links', $variables);
- }
- /**
- * Social types array
- *
- * @return array
- */
- function omitsis_mobiliz_get_social_types() {
- return array(
- 'facebook' => 'Facebook',
- 'twitter' => 'Twitter',
- 'youtube' => 'Youtube',
- 'instagram' => 'Instagram',
- 'rss' => 'RSS',
- 'linkedin' => 'LinkedIn'
- );
- }
- /**
- * General test page accesible via /test
- * @return [type] [description]
- */
- function _mobiliz_test(){
- print _mobiliz_render_block('views','garages-garages_nearby');
- }
- /**
- * Implements hook_libraries_info().
- */
- function omitsis_mobiliz_libraries_info() {
- $libraries = array();
- $libraries['fancybox'] = array(
- 'name' => 'Fancybox',
- 'vendor url' => 'http://fancybox.net/',
- 'download url' => 'http://fancyapps.com/fancybox/#license',
- 'version callback' => '_mobiliz_short_circuit_version',
- 'files' => array(
- 'js' => array(
- 'source/jquery.fancybox.pack.js',
- ),
- 'css' => array(
- 'source/jquery.fancybox.css'
- )
- ),
- );
- return $libraries;
- }
- function _mobiliz_short_circuit_version(){
- return TRUE;
- }
- /**
- * Render a block.
- *
- * @param $module
- * String Block's Module name.
- * @param $name
- * String Block name
- * @return string
- * Rendered block as HTML.
- */
- function _mobiliz_render_block($module, $name) {
- $block = block_load($module, $name);
- $block = _block_get_renderable_array(_block_render_blocks(array($block)));
- return drupal_render($block);
- }
- /**
- * Controla si el usuario es un administrador (u otro rol de administracion)
- * @param [type] $user_obj [description]
- * @return [bool] [description]
- */
- function _mobiliz_user_is_admin($user_obj = NULL) {
- if (empty($user_obj)) {
- global $user;
- $user_obj = $user;
- }
- $admin_roles = array('administrator', 'manager', 'supervisor');
- foreach ($user_obj->roles as $user_role) {
- if (in_array($user_role, $admin_roles)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- /**
- * Helper para recuperar informacion de un nodo
- * @param [obj] $obj el objeto "nodo"
- * @param [string] $field el campo a buscar, ej "field_ingrediente_nombre"
- * @param [string] $field_type el valor guardado en la bbdd, ej "safe_value"
- * @return [type] [description]
- */
- function _mobiliz_get_field($obj, $field, $field_type, $bundle = 'node') {
- $f = field_get_items($bundle, $obj, $field);
- if (!empty($f[0][$field_type])) {
- return $f[0][$field_type];
- }
- return NULL;
- }
- /**
- * Helper para recuperar informacion multiple de un nodo
- * @param [obj] $obj el objeto "nodo"
- * @param [string] $field el campo a buscar, ej "field_ingrediente_nombre"
- * @param [string] $field_type el valor guardado en la bbdd, ej "safe_value"
- * @return [type] [description]
- */
- function _mobiliz_get_multiple_field($obj, $field, $field_type, $bundle = 'node') {
- $f = field_get_items($bundle, $obj, $field);
- if (!empty($f[0][$field_type])) {
- return $f;
- }
- return NULL;
- }
- function _mobiliz_workflow_get_states(){
- $states_raw = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 1 AND sysid = 0 ORDER BY weight ASC")->fetchAll();
- $states = array();
- foreach($states_raw as $key => $state){
- $states[$key]['sid'] = $state->sid;
- $states[$key]['state'] = $state->state;
- }
- return $states;
- }
- /**
- * Workflow: get state name given its sid
- * @param [type] $sid [description]
- * @return [type] [description]
- */
- function _mobiliz_workflow_get_state_name($sid){
- return db_query("SELECT state FROM {workflow_states} WHERE sid = :sid AND status = 1 AND sysid = 0", array(":sid" => $sid))->fetchField();
- }
- /**
- * Returns lat/lng values for a node
- * @param [type] $nid [description]
- * @return array [description]
- */
- function _mobiliz_get_latlng($nid){
- $geo = db_query("SELECT field_record_geolocation_lat as lat, field_record_geolocation_lng as lng FROM {field_data_field_record_geolocation} WHERE entity_id = :nid", array(":nid" => $nid))->fetchAll();
- if(isset($geo[0])){
- return array('lat' => $geo[0]->lat, 'lng' => $geo[0]->lng);
- }
- return false;
- }
- /**
- * Renders the nearby garages view passing record lat/lng coordinates
- * @param [type] $geo [description]
- * @return [type] [description]
- */
- function _mobiliz_get_nearby_view($geo, $view_name, $display_name, $args = array(), $personal_situation = array(), $type = array()) {
- $view = views_get_view($view_name);
- $view->set_display($display_name);
- $view->set_arguments(array($args));
- $view->exposed_input['geo'] = array('latitude' => $geo['lat'], 'longitude' => $geo['lng']);
- if (!empty($personal_situation)) {
- foreach ($personal_situation['und'] as $key => $value) {
- $ps[] = $value['target_id'];
- }
- }
- //$types[] = $type;
- $view->exposed_input['field_prescriber_personal_sit_tid'] = $ps;
- $view->exposed_input['field_prescriber_type_tid'] = $type;
- /*
- * Filtering garage tool by car brand
- * brand = 0 -> renault et dacia
- * brand = 1 >
- */
- $node = menu_get_object();
- $filter_brand = 0;
- if (isset($node->field_brand['und'][0]['tid']) && $node->field_brand['und'][0]['tid'] != 73 && $node->field_brand['und'][0]['tid'] != 74) {
- $filter_brand = 1;
- }
- //kpr($view);
- $view->exposed_input['field_garage_repairs_all_brands_value'] = $filter_brand;
- $view->pre_execute();
- $view->execute();
- //$r = $view->result;
- return $view->render();
- }
- /**
- * Renders the nearby garages view passing record lat/lng coordinates
- * @param [type] $geo [description]
- * @return [type] [description]
- */
- function _mobiliz_get_nearby_view_data($geo, $view_name, $display_name){
- $view = views_get_view($view_name);
- $view->set_display($display_name);
- $view->exposed_input['geo'] = array('latitude' => $geo['lat'], 'longitude' => $geo['lng']);
- $view->pre_execute();
- $view->execute();
- $view->preview();
- $view->render();
- return $view->result;
- }
- /**
- * Borra la cache de un field en concreto.
- *
- * @param int $eid
- * El id de la entity.
- * @param string $bundle
- * El bundle, ej user, node, taxonomy.
- */
- function _mobiliz_cache_reset($eid, $bundle = 'node') {
- cache_clear_all('field:' . $bundle . ':' . $eid, 'cache_field');
- }
- function omitsis_mobiliz_form_user_register_form_alter(&$form, &$form_state, $form_id) {
- }
- function _mobiliz_after_build($form, &$form_state) {
- $form['path']['#access'] = FALSE;
- $form['menu']['#access'] = FALSE;
- return ($form);
- }
- //FALTA AFEGIR birth date i sumar nom i cognom
- function _mobiliz_check_before_18_months($nid) {
- $node = node_load($nid);
- $mail ='';
- if (isset($node->field_record_email['und'][0]['email'])) {
- $mail = $node->field_record_email['und'][0]['email'];
- }
- if (isset($node->field_record_birth['und'][0]['value'])) {
- $birth = $node->field_record_birth['und'][0]['value'];
- }
- if (isset($node->field_record_prenom['und'][0]['value'])) {
- $prenom = $node->field_record_prenom['und'][0]['value'];
- }
- $check = db_query("
- SELECT node.nid, node.created AS node_created, node.title AS node_title
- FROM {node} node
- LEFT JOIN {workflow_node_history} workflow_node_current ON ( SELECT max(hid) FROM {workflow_node_history}
- where nid = node.nid
- and sid != old_sid ) = workflow_node_current.hid
- LEFT JOIN {field_data_field_record_email} field_data_field_record_email ON node.nid = field_data_field_record_email.entity_id AND (field_data_field_record_email.entity_type = 'node' AND field_data_field_record_email.deleted = '0')
- LEFT JOIN {field_data_field_record_birth} field_data_field_record_birth ON node.nid = field_data_field_record_birth.entity_id AND (field_data_field_record_birth.entity_type = 'node' AND field_data_field_record_birth.deleted = '0')
- LEFT JOIN {field_data_field_record_prenom} field_data_field_record_prenom ON node.nid = field_data_field_record_prenom.entity_id AND (field_data_field_record_prenom.entity_type = 'node' AND field_data_field_record_prenom.deleted = '0')
- WHERE
- (
- (
- (node.title = '$node->title')
- AND
- (node.nid != '$node->nid')
- AND
- (field_data_field_record_email.field_record_email_email = '$mail')
- AND
- (field_data_field_record_birth.field_record_birth_value = '$birth')
- AND
- (field_data_field_record_prenom.field_record_prenom_value = '$prenom')
- )
- AND
- (
- (
- (node.status = '1')
- AND
- (node.type IN ('record'))
- AND
- (workflow_node_current.sid IN ('6'))
- )
- )
- AND
- (
- node.created > UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL '18' MONTH)
- )
- )
- ")->fetchAll();
- if (isset($check[0])) {
- return array('requester' => $check[0]->node_title, 'date' => $check[0]->node_created);
- }
- return false;
- }
- function omitsis_mobiliz_form_organisation_partenaire_node_form_alter(&$form, &$form_state, $form_id){
- if (!empty($form['nid']['#value'])) {
- $form['list_users'] = array(
- '#sufix' => '<h2>Members</h2>',
- '#markup' => views_embed_view('prescribers_administration_users', 'block_1'),
- '#weight' => 99
- );
- }
- $form['#after_build'][] = '_mobiliz_after_build';
- $form['actions']['#weight'] = 97;
- unset($form['options']);
- unset($form['author']);
- unset($form['revision_information']);
- //Prescriber
- global $user;
- if (in_array('7',array_keys($user->roles))) {
- $form['actions']['#access'] = FALSE;
- }
- }
- function submit_button_1_submit($form, &$form_state) {
- $node = node_form_submit_build_node($form, $form_state);
- node_save($node);
- if ($node->nid) {
- $form_state['values']['nid'] = $node->nid;
- $form_state['nid'] = $node->nid;
- $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => '5'));
- }
- else {
- drupal_set_message(t('The post could not be saved.'), 'error');
- $form_state['rebuild'] = TRUE;
- }
- }
- function submit_button_2_submit($form, &$form_state) {
- $node = node_form_submit_build_node($form, $form_state);
- node_save($node);
- if ($node->nid) {
- $form_state['values']['nid'] = $node->nid;
- $form_state['nid'] = $node->nid;
- $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => '4'));
- }
- else {
- drupal_set_message(t('The post could not be saved.'), 'error');
- $form_state['rebuild'] = TRUE;
- }
- }
- //function ($form, &$form_state) {
- // $node = node_form_submit_build_node($form, $form_state);
- // $fragment = $form_state['values']['salva'];
- // kpr($fragment);
- // die;
- //
- // node_save($node);
- // if ($node->nid) {
- // $form_state['values']['nid'] = $node->nid;
- // $form_state['nid'] = $node->nid;
- // $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => $fragment));
- // }
- // else {
- // drupal_set_message(t('The post could not be saved.'), 'error');
- // $form_state['rebuild'] = TRUE;
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement