Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.77 KB | None | 0 0
  1. <?php
  2. define('MYSITE_MODULE_NAME', basename(__FILE__, '.module'));
  3. define('ALL_RECORDS_NODE_NID', 36);
  4. define('WORKFLOW_STATE_NEW_REQUEST', 2);
  5. define('WORKFLOW_STATE_CHECKING_ELIGIBILITY', 3);
  6. define('WORKFLOW_STATE_SUITABLE', 4);
  7. define('WORKFLOW_STATE_SENT_TO_CLUB_MOBILITE', 5);
  8. define('WORKFLOW_STATE_SENT_TO_GARAGE', 6);
  9. define('WORKFLOW_STATE_CANCELLED', 7);
  10. /**
  11. * Implementation of hook_views_query_alter
  12. * @param type $view
  13. * @param type $query
  14. */
  15. function omitsis_mobiliz_views_query_alter(&$view, &$query) {
  16.  
  17. if ($view->name == 'check_eligibilite') {
  18. $node = menu_get_object();
  19. // kpr($node);
  20. $prenom = $node->field_record_prenom['und'][0]['safe_value'];
  21. $title = $node->title;
  22. $birth = $node->field_record_birth['und'][0]['value'];
  23. $email = $node->field_record_email['und'][0]['email'];
  24. //kpr($view);
  25.  
  26. $view->query->where[1]['conditions'][2]['value'] = $prenom;
  27. $view->query->where[1]['conditions'][3]['value'] = $title;
  28. //$query->add_where(1,'field_data_field_record_email.field_record_email_email',$email,'=');
  29. $query->add_where(1,'field_data_field_record_birth.field_record_birth_value',$birth,'=');
  30. } elseif ($view->name == 'garage') {
  31.  
  32. switch($view->current_display) {
  33. //Filter two digits
  34. case 'panel_pane_1':
  35. foreach($query->where[1]['conditions'] as $idx => $condition) {
  36. if ($condition['field'] == 'profile_users__field_data_field_garage_address.field_garage_address_postal_code') {
  37. $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
  38. $query->where[1]['conditions'][$idx]['value'] = $value.'%';
  39. }
  40. }
  41. break;
  42.  
  43. case 'page_2':
  44. foreach($query->where[1]['conditions'] as $idx => $condition) {
  45. if($condition['field'] == 'profile_users__field_data_field_garage_address.field_garage_address_postal_code') {
  46. $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
  47. $query->where[1]['conditions'][$idx]['value'] = $value.'%';
  48. }
  49. }
  50. break;
  51. }
  52. } elseif ($view->name == 'prescribers' && $view->current_display == 'page') {
  53. foreach($query->where[1]['conditions'] as $idx => $condition) {
  54. if ($condition['field'] == 'field_data_field_prescriber_address.field_prescriber_address_postal_code') {
  55. $value = substr($query->where[1]['conditions'][$idx]['value'],0,2);
  56. $query->where[1]['conditions'][$idx]['value'] = $value.'%';
  57. }
  58. }
  59. }
  60. }
  61.  
  62. function omitsis_mobiliz_form_alter(&$form, &$form_state, $form_id) {
  63. if ($form_id == 'views_form_records_panel_pane_3') {
  64. $form['field_supervisor_assign'][0]['actions']['edit']['#value'] = 'Désigner superviseur';
  65. }
  66. if ($form_id == 'views_form_records_panel_pane_5') {
  67. $form['field_record_presciber_user'][0]['actions']['edit']['#value']= 'Désigner agent prescripteur';
  68. }
  69. //Translating labels
  70. $form['sid']['#options']['All'] = "Choisissez l'option";
  71. $form['field_garage_type_tid']['#options']['All']= "Choisissez l'option";
  72. $form['field_request_type_tid']['#options']['All'] = "Choisissez l'option";
  73. $form['field_record_address']['und'][0]['street_block']['thoroughfare']['#title'] = 'Adresse';
  74. $form['field_record_address']['und'][0]['locality_block']['locality']['#title'] = 'Commune';
  75. $form['field_record_address']['und'][0]['locality_block']['postal_code']['#title'] = 'Code Postal';
  76. $form['field_record_commentaires']['und']['add_more']['#value'] = 'Ajouter un commentaire';
  77.  
  78. //Modify edit profile
  79. if ($form_id == 'user_profile_form') {
  80. global $user;
  81. $userid = user_load($user->uid);
  82. $uid = user_load($user->uid);
  83. if (!in_array('4',array_keys($user->roles)) && in_array('4',array_keys($form['#user']->roles))) {
  84. $form['edit_g'] = array(
  85. '#markup' => '<div class="buttons-garage">
  86. <div class="garage-user"><a href="/user/'.$form['#user']->uid.'/edit/">Gestionar le compte</a></div>
  87. <div class="garage-profil"><a href="/user/'.$form['#user']->uid.'/edit/garage">Profil du garage</a> </div>
  88. </div>',
  89. '#weight' => -1,
  90. );
  91. }
  92.  
  93. 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))))){
  94. $markup = '<div class="own-organisation"><div id="content">';
  95. $markup .= '<h3>Organisation</h3>';
  96. $markup .= views_embed_view('organisation_s_user', 'my_org');
  97. $markup .= '</div></div>';
  98. $form['own_organisation'] = array(
  99. '#markup' => $markup,
  100. '#weight' => 98,
  101. );
  102. $form['actions']['#weight'] = 97;
  103. $form['my_records'] = array(
  104. '#markup' => '<div class="my-demands"><h3>Demandes assignées à mon organisation</h3>'.views_embed_view('records', 'panel_pane_6').'</div>',
  105. '#weight' => 99
  106. );
  107. }
  108. //SUPERVISOR
  109. if (in_array('8',array_keys($user->roles))) {
  110. unset($form['field_organisation_partenaire']);
  111. $form['locale']['language']['#access'] = FALSE;
  112. }
  113. //FINANCIAL
  114. if (in_array('10',array_keys($user->roles))) {
  115. unset($form['field_organisation_partenaire']);
  116. $form['field_name_field_record_docs']['#access'] = FALSE;
  117. $form['locale']['language']['#access'] = FALSE;
  118.  
  119. }
  120. //Prescriber
  121. if (in_array('7',array_keys($user->roles)) || in_array('9',array_keys($user->roles))) {
  122. $form['field_organisation_partenaire']['#access'] = FALSE;
  123. $form['field_name_field_record_docs']['#access'] = FALSE;
  124. $form['locale']['language']['#access'] = FALSE;
  125. if ($form['#user']->uid != $user->uid) {
  126. $form['actions']['#access'] = FALSE;
  127. }
  128. if ($form['#user']->field_organisation_partenaire['und'][0]['target_id'] != $userid->field_organisation_partenaire['und'][0]['target_id']) {
  129. drupal_goto('/toutes-les-demandes');
  130. }
  131. }
  132.  
  133. //Prescriber Responsable
  134. if (in_array('9',array_keys($user->roles))) {
  135. $form['field_name_field_record_docs']['#access'] = FALSE;
  136. if ($form['#user']->field_organisation_partenaire['und'][0]['target_id'] == $userid->field_organisation_partenaire['und'][0]['target_id']) {
  137. $form['actions']['#access'] = TRUE;
  138. }
  139. }
  140.  
  141.  
  142. //GARAGE
  143. if (in_array('4',array_keys($user->roles))) {
  144. unset($form['field_organisation_partenaire']);
  145. $form['field_name_field_record_docs']['#access'] = FALSE;
  146. $form['locale']['language']['#access'] = FALSE;
  147.  
  148. $types = profile2_get_types();
  149. if (!empty($types)){
  150. foreach ($types as $type) {
  151. $profile = profile2_load_by_user($form['#user'], $type->type);
  152. if (!empty($profile)) {
  153. $form_state['profiles'][$profile->type] = $profile;
  154.  
  155. profile2_attach_form($form, $form_state);
  156. }
  157. }
  158. }
  159. }
  160. if ($form_id == 'user_profile_form') {
  161. unset($form['picture']);
  162. }
  163. $form['actions']['#prefix'] = '<div class="extra_div">';
  164. $form['actions']['#suffix'] = '</div>';
  165. }
  166.  
  167. // Garage register form
  168. if ($form_id == 'webform_client_form_31') {
  169. // Create user and profile garage information for webform submit
  170. $form['#validate'][] = 'omitsis_garage_validate';
  171. $form['actions']['submit']['#submit'][] = 'omitsis_garage_save';
  172. }
  173. // Prescriber register form
  174. if ($form_id == 'webform_client_form_33') {
  175. $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) ?');
  176. // Create organisation and prescriber user for webform submit
  177. $form['actions']['submit']['#submit'][] = 'omitsis_prescriber_save';
  178. }
  179. }
  180.  
  181. function omitsis_garage_validate($form, &$form_state) {
  182. if(!empty($form_state['values']['submitted']['nom_du_garage'])) {
  183. $user = user_load_by_name($form_state['values']['submitted']['nom_du_garage']);
  184. if($user) {
  185. form_set_error('nom_du_garage', t('Nom du garage @name already exist.', array('@name' => $form_state['values']['submitted']['nom_du_garage'])));
  186. }
  187. }
  188. }
  189.  
  190. function omitsis_garage_save($form, &$form_state) {
  191. $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';
  192. $new_user = array(
  193. 'name' => $form_state['values']['submitted']['nom_du_garage'],
  194. 'pass' => $password, // note: do not md5 the password
  195. 'mail' => $form_state['values']['submitted']['email'],
  196. 'status' => 0,
  197. 'init' => $form_state['values']['submitted']['email'],
  198. 'roles' => array(
  199. DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  200. 4 => 'garage',
  201. ),
  202. );
  203.  
  204. // The first parameter is sent blank so a new user is created.
  205. $user = user_save('', $new_user);
  206. // Where 'main' is your profile2 type machine name.
  207. $profile = profile2_create(array('type' => 'garage', 'uid' => $user->uid));
  208.  
  209. if (!empty($form_state['values']['submitted']['direction_regionale_de_rattachement'])) {
  210. $profile->field_garage_regional_directorat[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['direction_regionale_de_rattachement'];
  211. }
  212. if (!empty($form_state['values']['submitted']['telephon'])) {
  213. $profile->field_garage_telephone[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['telephon'];
  214. }
  215. if (!empty($form_state['values']['submitted']['adresse'])) {
  216. $profile->field_garage_address[LANGUAGE_NONE][0] = array(
  217. "country" => "FR",
  218. "thoroughfare" => $form_state['values']['submitted']['adresse'],
  219. "locality" => $form_state['values']['submitted']['localite'],
  220. "postal_code" => $form_state['values']['submitted']['cp'],
  221. );
  222. }
  223. if (!empty($form_state['values']['submitted']['personne_a_contacter'])) {
  224. $profile->field_gargae_contact_person[LANGUAGE_NONE][0]['value'] = $form_state['values']['submitted']['personne_a_contacter'];
  225. }
  226. // Save the profile2 to the user account.
  227. profile2_save($profile);
  228.  
  229. drupal_goto('/thank-you');
  230.  
  231. }
  232.  
  233. function omitsis_prescriber_save($form, &$form_state) {
  234.  
  235. // add node properties
  236. $newNode = new stdClass();
  237. $newNode->type = 'organisation_partenaire';
  238. $newNode->title = $form_state['values']['submitted']['nom_de_lorganisation_partenaire'];
  239. node_object_prepare($newNode); // Sets some defaults. Invokes hook_prepare() and hook_node_prepare().
  240. $newNode->language = LANGUAGE_NONE;
  241. $newNode->uid = 1;
  242. $newNode->status = 0;
  243. $newNode->comment = 0;
  244. $newNode->promote = 0;
  245.  
  246. if ($form_state['values']['submitted']['vos_publics']) {
  247. $vos = $form_state['values']['submitted']['vos_publics'];
  248. foreach ($vos as $tids => $tid) {
  249. if ($tid != 0) {
  250. $newNode->field_prescriber_personal_sit[$newNode->language][]['tid'] = $tid;
  251. }
  252. }
  253. }
  254. if($form_state['values']['submitted']['mission_de_votre_structure']) {
  255. $newNode->field_prescriber_description[$newNode->language][0]['value'] = $form_state['values']['submitted']['mission_de_votre_structure'];
  256. }
  257. if(!empty($form_state['values']['submitted']['heure_de_contact_souhaite'])) {
  258. $newNode->field_prescriber_accept[$newNode->language][0]['value'] = $form_state['values']['submitted']['heure_de_contact_souhaite'][1];
  259. }
  260.  
  261.  
  262. $newNode = node_submit($newNode); // Prepare node for saving
  263. node_save($newNode);
  264.  
  265. $password = $form_state['values']['submitted']['prenom'] . $form_state['values']['submitted']['nom'] . '2345';
  266. $new_user = array(
  267. 'name' => $form_state['values']['submitted']['prenom'] . $form_state['values']['submitted']['nom'],
  268. 'pass' => $password, // note: do not md5 the password
  269. 'mail' => $form_state['values']['submitted']['e_mail'],
  270. 'status' => 0,
  271. 'init' => $form_state['values']['submitted']['e_mail'],
  272. 'roles' => array(
  273. DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  274. 9 => 'prescriber boss',
  275. ),
  276. 'field_user_name' => array(
  277. LANGUAGE_NONE => array(
  278. 0 => array(
  279. 'value' => $form_state['values']['submitted']['prenom']
  280. ),
  281. ),
  282. ),
  283. 'field_user_surname' => array(
  284. LANGUAGE_NONE => array(
  285. 0 => array(
  286. 'value' => $form_state['values']['submitted']['nom']
  287. ),
  288. ),
  289. ),
  290. 'field_telephone' => array(
  291. LANGUAGE_NONE => array(
  292. 0 => array(
  293. 'value' => $form_state['values']['submitted']['telephon']
  294. ),
  295. ),
  296. ),
  297. 'field_organisation_partenaire' => array(
  298. LANGUAGE_NONE => array(
  299. 0 => array(
  300. 'target_id' => $newNode->nid
  301. ),
  302. ),
  303. ),
  304. );
  305.  
  306. // The first parameter is sent blank so a new user is created.
  307. $user = user_save('', $new_user);
  308. drupal_goto('/thank-you');
  309. }
  310.  
  311. function omitsis_mobiliz_form_record_node_form_alter(&$form, &$form_state, $form_id){
  312. global $user;
  313. $form['field_request_type']['und']['#options']['_none'] = 'Choisissez un service';
  314. $form['field_record_mail_survey']['#access'] = FALSE;
  315. // New record
  316. if(empty($form['nid']['#value'])){
  317. //Add new record button
  318. $form['actions']['submit']['#value'] = 'Sauvegarder saisie';
  319. $form['field_request_type']['und']['#options']['_none'] = 'Choisissez une offre';
  320. $args = arg();
  321. // remove fields from front page add new record
  322. if($args[1] != 'add' && $args[2] != 'record') {
  323. $form['actions']['submit']['#value'] = "ENVOYER MA DEMANDE DE CONTACT" ; //Canvi nom botó
  324. $form['#after_build'][] = '_mobiliz_after_build';
  325. $hidden_fields_node_add_front = array(
  326. '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',
  327. 'field_record_assigned', 'field_record_birth', 'field_record_tel_mobile', 'field_record_geolocation',
  328. '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');
  329. foreach($hidden_fields_node_add_front as $field){
  330. unset($form[$field]);
  331. }
  332. }
  333.  
  334. //if prescriber add new record, autoassign for their entity
  335. global $user;
  336. $uid = user_load($user->uid);
  337. if ((in_array('7',array_keys($user->roles))) || (in_array('9',array_keys($user->roles))) || (in_array('3',array_keys($user->roles)))){
  338. $organisation = $uid->field_organisation_partenaire['und'][0]['target_id'];
  339. $form['field_record_assigned']['und']['#default_value'] = $organisation;
  340. }
  341.  
  342.  
  343. // remove fields related to record type from new record form
  344. $hidden_fields_new_record = array(
  345.  
  346. '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',
  347. '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',
  348. 'field_record_l_situation', 'field_record_l_particular_cars', 'field_record_l_professional_cars', 'field_record_l_amount_funding', 'field_record_l_adie',
  349. 'field_record_substates_'.WORKFLOW_STATE_CANCELLED);
  350.  
  351.  
  352. foreach($hidden_fields_new_record as $field){
  353. unset($form[$field]);
  354. }
  355. if (empty($form['field_record_closing_explanation']['und'][0]['value']['#default_value'])) {
  356. unset($form['field_record_closing_explanation']);
  357. }
  358. // copy the code postal value from address field to new fields of addres and cp (encrypt issues)
  359.  
  360. $form['#submit'][] = '_mobiliz_postal_code_save';
  361. $form['actions']['submit']['#submit'][] = '_mobiliz_postal_code_save';
  362. if (!in_array('3',array_keys($user->roles))) {
  363. unset($form['field_supervisor_assign']);
  364. }
  365. }
  366.  
  367. // Editing an existing record
  368. if(!empty($form['nid']['#value'])) {
  369. $form['actions']['submit']['#value'] = 'Sauvegarder saisie';
  370. $nid = $form['nid']['#value'];
  371. $node = $form['#node'];
  372. $form['actions']['inner'] = array(
  373. '#type' => 'container'
  374. );
  375. if (!_mobiliz_user_is_admin()) {
  376. global $user;
  377. $user_fields = user_load($user->uid);
  378. $assigned = _mobiliz_get_field($node, 'field_record_assigned', 'target_id');
  379. $garage_assigned = _mobiliz_get_field($node, 'field_record_garage_selected', 'target_id');
  380. $organisation = $user_fields->field_organisation_partenaire['und'][0]['target_id'];
  381.  
  382. //PRESCRIBERS
  383. if (in_array('7',array_keys($user->roles)) || in_array('9',array_keys($user->roles))) {
  384. $form['field_record_docs']['#access'] = FALSE;
  385. if ($assigned != $organisation) {
  386. // access denied si el prescriptor no tiene asignado el record (partiendo de la reference)
  387. //drupal_access_denied();
  388. drupal_goto('toutes-les-demandes');
  389.  
  390. } else {
  391. // disable delete button if not admin
  392. $form['actions']['delete']['#access'] = FALSE;
  393. $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
  394. }
  395. }
  396. //GARAGE
  397. else if (in_array('4',array_keys($user->roles))){
  398. $form['field_record_docs']['#access'] = FALSE;
  399. if ($garage_assigned != $user->uid) {
  400. // access denied si el prescriptor no tiene asignado el record (partiendo de la reference)
  401. drupal_goto('toutes-les-demandes');
  402.  
  403. } else {
  404. // disable delete button if not admin
  405. $form['actions']['delete']['#access'] = FALSE;
  406. $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
  407. }
  408. }
  409. // FINANCIAL
  410. else if (in_array('10',array_keys($user->roles))){
  411. $form['field_record_docs']['#access'] = FALSE;
  412. $form['field_nom_de_l_organisme_finance']['#access'] = FALSE;
  413. $form['field_record_closing_explanation']['#access'] = FALSE;
  414. }
  415. }
  416. // unset N/A options for non-mandatory fields
  417. unset($form['field_elegibilite']['und']['#options']['_none']);
  418. unset($form['field_record_u_car_body'][LANGUAGE_NONE]['#options']['_none']);
  419. unset($form['field_record_l_situation'][LANGUAGE_NONE]['#options']['_none']);
  420. unset($form['field_record_l_particular_cars'][LANGUAGE_NONE]['#options']['_none']);
  421. unset($form['field_record_l_professional_cars'][LANGUAGE_NONE]['#options']['_none']);
  422. unset($form['field_l_situation_emploie'][LANGUAGE_NONE]['#options']['_none']);
  423. unset($form['field_record_term_confirmation']);
  424. unset($form['field_l_creation_entreprise'][LANGUAGE_NONE]['#options']['_none']);
  425. // redirect to node edit
  426. $form['#submit'][] = '_mobiliz_postal_code_save';
  427. $form['actions']['submit']['#submit'][] = '_mobiliz_postal_code_save';
  428. //$form['#submit'][] = '_mobiliz_record_submit';
  429. $form['actions']['submit']['#submit'][] = '_mobiliz_record_submit';
  430.  
  431. // hide record type selector to prevent changes
  432. // but add a normal div to keep a trace of what type of record this is
  433. // and create a container for the form (for the sake of design)
  434.  
  435. //$form['field_record_type']['#access'] = FALSE;
  436. //$type = _mobiliz_get_field($node, 'field_request_type', 'value');
  437.  
  438. $form['selected_record'] = array(
  439. '#markup' => _mobiliz_render_block('views', 'records-single'),
  440. '#weight' => 2
  441. );
  442. $form['18_months']= array(
  443. '#markup' => views_embed_view('check_eligibilite', 'block_1'),
  444. '#weight' => 1,
  445. ); //-> si la data que retorna es 18 mesos (maxim) abans que la actual -> no cal verificar, else -> verificar
  446.  
  447.  
  448.  
  449. $type = $form['field_request_type']['und']['#default_value'][0];
  450. if (empty($type)) $type = 33;
  451.  
  452.  
  453. $form['record_container'] = array(
  454. '#type' => 'container',
  455. '#weight' => 0,
  456. '#tree' => true,
  457. '#attributes' => array('class' => array('type-' . $type)),
  458. );
  459.  
  460. $form['record_container']['field_record_type_selected'] = array(
  461. '#markup' => '<div class="record-type record-type-' . $type . ' element-invisible">' . $type . '</div>'
  462. );
  463. if (in_array('3',array_keys($user->roles)) || in_array('8',array_keys($user->roles)) || in_array('11',array_keys($user->roles))) {
  464. $form['record_container']['doc_info'] = array(
  465. //'#markup' => '<div class="doc-info">'. t('Add documentacion info').'</div>'
  466. );
  467. }
  468. if (in_array('3',array_keys($user->roles)) || in_array('11',array_keys($user->roles))) {
  469. /* Survey button */
  470. $form['surve_link'] = array(
  471. '#markup' => l(t('Access to Survey'), url('entretien-reparation-questionnaire?nid=40'.$nid), array('attributes' => array('class' => array('survey-button')))),
  472. );
  473. }
  474. $form['record_container']['identification'] = array(
  475. '#markup' => '<div class="identification-infodep">'. t("Merci d'indiquer les informations du bénéficiaire").'</div>'
  476. );
  477. /*$form['actions']['inner']['taches'] = array(
  478. '#markup' => '<div class="taches-realiz">'. t("Tà ches à réaliser").'</div>'
  479. );*/
  480. $geo = _mobiliz_get_latlng($nid);
  481. $type = $form['#node']->field_request_type['und'][0]['tid'];
  482. $personal_situation = $form['#node']->field_record_personal_situation;
  483. $brand = $form['#node']->field_brand['und'][0]['tid'];
  484. //kpr($brand);
  485.  
  486.  
  487. /**
  488. * Record info
  489. */
  490. 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)))) {
  491.  
  492. /* if geo is location of france country only. reset $geo */
  493. if ($geo['lat'] == '46.227638' && $geo['lng'] == '2.213749') {
  494. unset($geo);
  495. }
  496. /**
  497. *
  498. * ASSIGN TO
  499. *
  500. */
  501.  
  502. // show another empty ajax view and solved problem with multiple views ajax on form
  503. $markup = views_embed_view('ajax_null', 'block');
  504.  
  505. $markup .= '<div id="prescribers-geo">';
  506.  
  507. if (!empty($form['#node']->field_record_assigned)) {
  508. $markup .= _mobiliz_get_nearby_view($geo, 'assignable_prescribers', 'prescriber_nearby_selected', $form['#node']->field_record_assigned[LANGUAGE_NONE][0]['target_id']);
  509. //$markup .= views_embed_view('assignable_prescribers', 'prescriber_nearby_selected', $form['#node']->field_record_assigned[LANGUAGE_NONE][0]['target_id']);
  510. }
  511. if (!$geo) {
  512. $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>';
  513.  
  514. // Get Ps-> save node and redirect to this tab
  515.  
  516. $form['get-ps'] = array(
  517. '#type' => 'submit',
  518. '#value' => t('Obtenir liste des prescripteurs'),
  519. '#access' => TRUE,
  520. '#submit' => array('submit_button_1_submit'),
  521. '#weight' => -10,
  522. );
  523.  
  524.  
  525. } else {
  526.  
  527. $markup .= '';
  528. $markup .= _mobiliz_get_nearby_view($geo,'assignable_prescribers', 'prescriber_nearby', array(), $personal_situation, $type);
  529. }
  530.  
  531. $markup .= '</div>';
  532. $form['assign_to_views'] = array(
  533. '#markup' => $markup
  534. );
  535. }
  536. // Show
  537. if (!(in_array('8',array_keys($user->roles)) || in_array('3',array_keys($user->roles)) || in_array('11',array_keys($user->roles)))) {
  538. foreach($form['#group_children'] as $key => $value) {
  539. if ($value == 'group_record_assigned_prescriber') {
  540. unset($form['#group_children'][$key]);
  541. }
  542. }
  543. //$form['field_request_type']['#access'] = FALSE;
  544. unset($form['field_supervisor_assign']);
  545. unset($form['#fieldgroups']['group_record_assigned_prescriber']);
  546. // unset($form['field_record_docs']);
  547.  
  548.  
  549. foreach($form['#group_children'] as $key => $value) {
  550. if ($value == 'group_administration') {
  551. unset($form['#group_children'][$key]);
  552. }
  553. }
  554.  
  555.  
  556. unset($form['#fieldgroups']['group_administration']);
  557. }
  558. //SUPERVISOR
  559. if (in_array('8',array_keys($user->roles))) {
  560. foreach($form['#group_children'] as $key => $value) {
  561. if ($value == 'group_administration') {
  562. unset($form['#group_children'][$key]);
  563. }
  564. unset($form['field_supervisor_assign']);
  565. }
  566. if (isset($form['field_record_assigned']['und']['#default_value'][0])) {
  567. $form['actions']['#access'] = FALSE;
  568. }
  569. }
  570. //IF GARAGE DISABLE BUTTONS
  571. if (in_array('4',array_keys($user->roles))) {
  572. $form['actions']['#access'] = FALSE;
  573. foreach($form['#group_children'] as $key => $value) {
  574. if ($value == 'group_record_garage_info') {
  575. unset($form['#group_children'][$key]);
  576. }
  577. }
  578.  
  579. }
  580. if (in_array('10',array_keys($user->roles))) {
  581.  
  582. }
  583. if (!in_array('3',array_keys($user->roles)) && in_array('3',array_keys($user->roles)) && isset($form['field_record_assigned']['und']['#default_value'][0])) {
  584. $form['actions']['#access'] = FALSE;
  585. }
  586.  
  587.  
  588. $form['#groups']['group_record_garage_info']->children[] = 'garage_selection_views';
  589. $form['#group_children'][] = 'garage_selection_views';
  590. $form['#fieldgroups']['group_record_assigned_prescriber']->type = 'hidden';
  591.  
  592. /**
  593. *
  594. * GARAGE SELECT
  595. *
  596. */
  597. if (!in_array('4',array_keys($user->roles))) {
  598.  
  599. $markup = '<div id="garage-geo">';
  600.  
  601. if (!$geo) {
  602. $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>';
  603.  
  604. // Get garage -> save node and redirect to this tab
  605. $form['get-grs'] = array(
  606. '#type' => 'submit',
  607. '#value' => t('Obtenir liste des garajes'),
  608. '#access' => TRUE,
  609. '#submit' => array('submit_button_2_submit'),
  610. '#weight' => -10,
  611. );
  612.  
  613. } else {
  614. $markup .= '<div id="hidden-geo" style="display:none;"><div id="geo-lng">'. $geo['lng'] .'</div><div id="geo-lat">'.$geo['lat'].'</div></div>';
  615. $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>';
  616.  
  617.  
  618.  
  619.  
  620. if (!empty($form['#node']->field_record_garage_selected)) {
  621. foreach ($form['#node']->field_record_garage_selected[LANGUAGE_NONE] as $key => $value) {
  622. $garages_nids[] = $value['target_id'];
  623. }
  624. if ($node->field_request_type['und'][0]['tid'] != 35 && $node->field_request_type['und'][0]['tid'] != 102) {
  625. $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_selected', implode('+', $garages_nids));
  626. }
  627. elseif ($node->field_request_type['und'][0]['tid'] == 102) {
  628. $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_selected_vn', implode('+', $garages_nids));
  629. }
  630. //$markup .= views_embed_view('garage', 'garage_nearby_selected', implode('+', $garages_nids));
  631. }
  632. if (!empty($node->field_request_type)) {
  633. if ($node->field_request_type['und'][0]['tid'] == 33
  634. ) {
  635. // Show form filter on garage view
  636.  
  637. $markup .= '';
  638. $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby', $brand);
  639. }
  640. elseif ($node->field_request_type['und'][0]['tid'] == 102
  641. ) {
  642. // Show form filter on garage view
  643. $markup .= '<div id="edit-field-garage-address-postal-code-wrapper2" class="views-exposed-widget views-widget-filter-field_garage_address_postal_code">
  644. <label for="edit-field-garage-address-postal-code">' . t('Code postal du bénéficiaire') . ' </label>
  645. <div class="views-widget">
  646. <div class="form-item form-type-textfield form-item-field-garage-address-postal-code">
  647. <input id="edit-field-garage-address-postal-code2" name="field_garage_address_postal_code2" value="" size="30" maxlength="128" class="form-text" type="text">
  648. </div>
  649. <input id="edit-button-garage" name="Chercher" value="Chercher" class="form-submit" type="button">
  650. </div>
  651. </div>';
  652. $markup .= '';
  653. $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_vn', $brand);
  654. }
  655. elseif ($node->field_request_type['und'][0]['tid'] == 35) {
  656. // Save garages when is VO
  657. $garages = _mobiliz_get_nearby_view_data($geo, 'garage', 'garage_nearby_vo');
  658. foreach ($garages as $key => $value) {
  659. $form['field_record_garage_selected']['und'][$key] = $form['field_record_garage_selected']['und'][0];
  660. $form['field_record_garage_selected']['und'][$key]['target_id']['#default_value'] = "{$value->users_name} ($value->uid)";
  661. }
  662.  
  663. $markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby_vo');
  664. }
  665. }
  666.  
  667.  
  668. //$markup .= _mobiliz_get_nearby_view($geo, 'garage', 'garage_nearby');
  669.  
  670. }
  671. $markup .= '</div>';
  672.  
  673. $form['garage_selection_views'] = array(
  674. '#markup' => $markup
  675. );
  676.  
  677. $form['#groups']['group_record_garage_info']->children[] = 'garage_selection_views';
  678. $form['#group_children'][] = 'garage_selection_views';
  679.  
  680.  
  681. }
  682. /**
  683. *
  684. * WORKFLOW GUIDE BUTTONS
  685. *
  686. */
  687. $state_sid = _mobiliz_get_field($node, 'field_record_workflow', 'value');
  688. $form['#attributes']['class']['3'] = 'form-state-'.$state_sid;
  689. $form['record_container']['field_record_status'] = array(
  690. '#markup' => '<div class="record-status record-status-'.$state_sid.' element-invisible">'.$state_sid.'</div>'
  691. );
  692.  
  693. // creates the states flow arrows
  694. $states = _mobiliz_workflow_get_states();
  695. $states_markup = '<ul class="states-flow type-'.$type.'">';
  696. foreach($states as $key => $state){
  697. if(($state['sid'] != WORKFLOW_STATE_CANCELLED) && ($state['sid'] != WORKFLOW_STATE_SENT_TO_CLUB_MOBILITE)) {
  698. if ($state_sid == $state['sid'] && $form['field_request_type']['und']['#default_value'][0] != 102) {
  699. $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active">' . $state['state'] . '</li>';
  700. }
  701. elseif ($state_sid == $state['sid'] && $state['state'] == 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
  702. $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active">ENVOYÉ AU CLUB MOBILITÉ</li>';
  703. }
  704. elseif ($state['state'] == 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
  705. $states_markup .= '<li class="state-flow state-' . $state['sid'] . '">ENVOYÉ AU CLUB MOBILITÉ</li>';
  706. }
  707. elseif ($state_sid == $state['sid'] && $state['state'] != 'ENVOYÉ AU GARAGE' && $form['field_request_type']['und']['#default_value'][0] == 102) {
  708. $states_markup .= '<li class="state-flow state-' . $state['sid'] . ' active ">' . $state['state'] . '</li>';
  709. }
  710. else {
  711. $states_markup .= '<li class="state-flow state-' . $state['sid'] . '">' . $state['state'] . '</li>';
  712. }
  713. }
  714. }
  715. $states_markup .= '</ul>';
  716.  
  717. $form['states_flow'] = array(
  718. '#markup' => $states_markup,
  719. '#weight' => 1
  720. );
  721.  
  722. $substate_fields = array(
  723. 1 => 'field_record_substates_'.WORKFLOW_STATE_NEW_REQUEST, 2 => 'field_record_substates_'.WORKFLOW_STATE_CHECKING_ELIGIBILITY,
  724. 3 => 'field_record_substates_'.WORKFLOW_STATE_SUITABLE, 4 => 'field_record_substates_5',
  725. 6 => 'field_record_substates_6', 7 => 'field_record_substates_'.WORKFLOW_STATE_CANCELLED,
  726. );
  727.  
  728. // 1. put actual state substates checkboxes in actions container
  729. // 2. put cancelled substate checkboxes at the end of the actions container
  730. foreach($substate_fields as $key => $field){
  731. $id = substr($field, -1);
  732. // unset N/A options for non-mandatory fields
  733. unset($form[$field][LANGUAGE_NONE]['#options']['_none']);
  734. if($field != 'field_record_substates_7'){
  735. if($id != $state_sid){
  736. // hides substates that are not children of the actual state
  737. //kpr($id);
  738. unset($form[$field]);
  739. }else{
  740. if($id == $state_sid){
  741. // puts current state substates in actions container
  742. $form['actions']['inner'][$field] = $form[$field];
  743. $form['actions']['inner'][$field]['#weight'] = 0;
  744. }
  745. unset($form[$field]);
  746. }
  747. }else{
  748. // what to do with cancelled states?
  749. // they should go in a fancybox
  750. $form['actions']['inner'][$field] = $form[$field];
  751. $form['actions']['inner']['field_record_closing_explanation'] = $form['field_record_closing_explanation'];
  752. $form['actions']['inner'][$field]['#weight'] = 1000;
  753. unset($form[$field]);
  754. }
  755. }
  756.  
  757. // assigned financial disable
  758. $form['field_record_assigned_finantial']['#access'] = FALSE;
  759.  
  760. /**
  761. *
  762. * BUTTONS
  763. *
  764. */
  765. // back button
  766. $form['back'] = array(
  767. '#type' => 'submit',
  768. '#value' => t('< Revenir a la liste des demandes'),
  769. '#attributes' => array('data-action' => array('btn-back')),
  770. '#weight' => -10,
  771. '#prefix' => '<div class="revenire"><div class="container">',
  772. '#suffix' => '</div></div>',
  773. '#submit' => array('_mobiliz_record_back')
  774. );
  775.  
  776. // add a container for buttons like save, cancel, delete..
  777. $form['actions']['inner']['buttons'] = array(
  778. '#type' => 'container',
  779. '#tree' => true,
  780. '#weight' => 1,
  781. );
  782.  
  783. // add cancel button
  784. $form['actions']['inner']['buttons']['cancel'] = array(
  785. '#markup' => l(t('Annuler saisie'), url('node/'.$nid.'/edit'), array('attributes' => array('class' => array('btn-cancel'), 'data-action' => array('action-cancel')))),
  786. '#weight' => 0,
  787. );
  788. $form['actions']['inner']['buttons']['submit'] = $form['actions']['submit'];
  789. $form['actions']['inner']['buttons']['delete'] = $form['actions']['delete'];
  790. $form['actions']['inner']['buttons']['delete']['#weight'] = -10;
  791. $form['actions']['inner']['buttons']['delete']['#value'] = 'Supprimer dossier';
  792.  
  793. // remove standard buttons
  794. unset($form['actions']['submit']);
  795. unset($form['actions']['delete']);
  796.  
  797.  
  798. $form['actions']['salva'] = array(
  799. '#type' => 'hidden',
  800. '#access' => TRUE,
  801. '#weight' => 10,
  802. );
  803.  
  804. /**
  805. *
  806. *
  807. * Caso cerrado
  808. *
  809. *
  810. */
  811. if($state_sid != '6' && $state_sid != '7') {
  812. if ($state_sid == '2') {
  813. $form['false'] = array(
  814. '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Poursuivre l\'étude du dossier</span></div>',
  815. '#weight' => 1
  816. );
  817. }
  818. if ($state_sid == '3') {
  819. $form['false'] = array(
  820. '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Valider l\'éligibilité</span></div>',
  821. '#weight' => 1
  822. );
  823. }
  824. if ($state_sid == '4') {
  825. $form['false'] = array(
  826. '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Envoyer au garage</span></div>',
  827. '#weight' => 1
  828. );
  829. }
  830. if ($state_sid == '4' && $form['field_request_type']['und']['#default_value'][0] == 102) {
  831. $form['false'] = array(
  832. '#markup' => '<div class="container-next"><span class="confirm state-'.$state_sid.'" id="false-button"><i></i>Envoyer au Club Mobilité</span></div>',
  833. '#weight' => 1
  834. );
  835. }
  836. }
  837. /**
  838. *
  839. * CLOSE RECORD BUTTON + TRIGGER
  840. *
  841. */
  842. if ($state_sid =='7') {
  843. //kpr($form);
  844. if (isset($form['field_record_closing_explanation']['und'][0])) {
  845. $form['actions']['inner']['closed']= array(
  846. '#markup' => views_embed_view('records', 'closing',$form['nid']['#value']),
  847. '#weight' => 1
  848. );
  849.  
  850. }
  851.  
  852. }
  853.  
  854.  
  855. if (!in_array('10',array_keys($user->roles)) && !in_array('3',array_keys($user->roles)) && $state_sid==5){
  856. $form['actions']['#access'] = FALSE;
  857. }
  858. if (!in_array('10',array_keys($user->roles))) {
  859. //Add false button, when click show cancel options and trigger
  860. if($state_sid != WORKFLOW_STATE_CANCELLED && $state_sid != '6' ){
  861. $form['actions']['inner']['closing']= array(
  862. '#markup' => '<span class="confirm" id="edit-close-record-trigger">Abandon du dossier</span>',
  863. '#weight' => 1
  864. );
  865.  
  866. $form['actions']['inner']['closing-2']= array(
  867. '#markup' => '<span class="confirm" id="edit-close-record-trigger-2">Abandon du dossier</span>',
  868. '#weight' => 1
  869. );
  870.  
  871. }
  872. }
  873. }
  874. }
  875.  
  876. /**
  877. * Back button redirect to all records page
  878. * @return [type] [description]
  879. */
  880. function _mobiliz_record_back(){
  881. drupal_goto('toutes-les-demandes');
  882. exit;
  883. }
  884.  
  885. function _mobiliz_postal_code_save($form, &$form_state) {
  886. // Postal code Save on other fields
  887. $form_state['values']['field_field_record_address2']['und'][0]['postal_code'] = $form_state['values']['field_record_address']['und'][0]['postal_code'];
  888. $form_state['values']['field_record_code_postal']['und'][0]['value'] = $form_state['values']['field_record_address']['und'][0]['postal_code'];
  889. }
  890.  
  891. /**
  892. * Record edit: on save redirect to same node edit
  893. * @param [type] $form [description]
  894. * @param [type] &$form_state [description]
  895. * @return [type] [description]
  896. */
  897. function _mobiliz_record_submit($form, &$form_state) {
  898.  
  899.  
  900.  
  901.  
  902.  
  903. $state_id = $form_state['values']['field_record_workflow']['und'][0]['workflow']['workflow_sid'];
  904. $params['record_nid'] = $form_state['values']['nid'];
  905. if($form_state['clicked_button']['#value'] == 'Next step') {
  906. if ($state_id == 3 && (isset($form_state['values']['field_record_assigned']['und']['#value']))
  907. || isset($form_state['values']['field_record_assigned']['und']['0']['target_id'])) {
  908. // Mail prescriber assigned
  909. drupal_mail('mobiliz_record', 'record_mail_to_prescriptor_assign', $to, $language, $params, $from = NULL, $send = TRUE);
  910. }
  911. if ($state_id == 6) {
  912. /* Record Leasing send mails */
  913. if ($form_state['values']['field_request_type']['und'][0]['tid'] == 102) {
  914. //drupal_mail('mobiliz_record', 'record_l_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
  915. drupal_mail('mobiliz_record', 'record_mail_to_prescriptor_club_mobiliz', $to, $language, $params, $from = NULL, $send = TRUE);
  916. drupal_mail('mobiliz_record', 'record_l_mail_to_cm', $to, $language, $params, $from = NULL, $send = TRUE);
  917. }
  918.  
  919. /* Record Repair send mails */
  920. if ($form_state['values']['field_request_type']['und'][0]['tid'] == 33) {
  921. drupal_mail('mobiliz_record', 'record_r_mail_to_garage', $to, $language, $params, $from = NULL, $send = TRUE);
  922. drupal_mail('mobiliz_record', 'record_r_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
  923. drupal_mail('mobiliz_record', 'record_r_mail_to_prescriber', $to, $language, $params, $from = NULL, $send = TRUE);
  924. }
  925.  
  926. /* Record VO send mails */
  927. if ($form_state['values']['field_request_type']['und'][0]['tid'] == 35) {
  928. drupal_mail('mobiliz_record', 'record_vo_mail_to_beneficiarie', $to, $language, $params, $from = NULL, $send = TRUE);
  929. drupal_mail('mobiliz_record', 'record_vo_mail_to_prescriber', $to, $language, $params, $from = NULL, $send = TRUE);
  930.  
  931. $node = node_load($form_state['values']['nid']);
  932. foreach($node->field_record_garage_selected['und'] as $key => $value) {
  933. $profile = profile2_load_by_user($value['target_id'], 'garage');
  934. if (valid_email_address($profile->field_garage_email['und'][0]['email'])) {
  935. drupal_mail('mobiliz_record', 'record_vo_mail_to_garages', $profile->field_garage_email['und'][0]['email'], $language, $params, $from = NULL, $send = TRUE);
  936. }
  937. }
  938. }
  939. }
  940. }
  941.  
  942. if (!empty($form['nid']['#value'])) {
  943. // redirect al mismo nodo si es edit
  944. //$form_state['redirect'] = 'node/'.$form['nid']['#value'] . '/edit';
  945. $node = node_form_submit_build_node($form, $form_state);
  946. $fragment = $form_state['values']['salva'];
  947. node_save($node);
  948. if ($node->nid) {
  949. $form_state['values']['nid'] = $node->nid;
  950. $form_state['nid'] = $node->nid;
  951. $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => $fragment));
  952. }
  953. }else{
  954. // todo: si es un nuevo record, donde redirije? aun no está el node
  955. }
  956.  
  957. //$_GET['destination'] = $form_state['redirect'];
  958.  
  959.  
  960. }
  961.  
  962. /**
  963. * Implements hook_block_info().
  964. */
  965. function omitsis_mobiliz_block_info() {
  966. $blocks['social_networks_links'] = array(
  967. 'info' => MYSITE_MODULE_NAME . ': Social Networks links',
  968. 'cache' => DRUPAL_CACHE_PER_ROLE, //Default
  969. );
  970.  
  971. return $blocks;
  972. }
  973.  
  974. /**
  975. * Implements hook_block_view().
  976. *
  977. * Prepares the contents of the block.
  978. */
  979. function omitsis_mobiliz_block_view($delta = '') {
  980.  
  981. $block = array();
  982. switch ($delta) {
  983. case 'social_networks_links':
  984. $block['subject'] = '';
  985. $block['content'] = omitsis_mobiliz_render_social_network_links();
  986. break;
  987. }
  988. }
  989.  
  990. /**
  991. * Implements hook_theme().
  992. */
  993. function omitsis_mobiliz_theme($existing, $type, $theme, $path) {
  994. return array(
  995. 'social_network_links' => array(
  996. 'variables' => array('list' => array()),
  997. 'template' => 'theme/social_network_links',
  998. ),
  999. );
  1000. }
  1001.  
  1002. /**
  1003. * Implements hook_menu().
  1004. */
  1005. function omitsis_mobiliz_menu() {
  1006. $items = array();
  1007. /*
  1008. $items['node/%'] = array(
  1009. 'page callback' => '_mobiliz_node_view_redirect',
  1010. 'page arguments' => array(1),
  1011. 'access arguments' => array('create record content'),
  1012. );
  1013. */
  1014. $items['record/%/change/state/%'] = array(
  1015. 'page callback' => '_mobiliz_workflow_state_change',
  1016. 'page arguments' => array(1,4),
  1017. 'access arguments' => array('create record content'),
  1018. );
  1019.  
  1020. $items['admin/config/services/config'] = array(
  1021. 'title' => 'Site configuration',
  1022. 'description' => 'Change parameters for this site.',
  1023. 'page callback' => 'drupal_get_form',
  1024. 'page arguments' => array('omitsis_mobiliz_settings'),
  1025. 'access arguments' => array('administer mobiliz settings'),
  1026. 'type' => MENU_NORMAL_ITEM,
  1027. );
  1028.  
  1029. $items['test'] = array(
  1030. 'page callback' => '_mobiliz_test',
  1031. 'access arguments '=> array('administer mobiliz settings')
  1032. );
  1033.  
  1034. return $items;
  1035. }
  1036.  
  1037.  
  1038. /**
  1039. * Redirect a node view to its node edit
  1040. * if it belongs to the rediractable types array defined here
  1041. * @param [type] $nid [description]
  1042. * @return [type] [description]
  1043. */
  1044. function _mobiliz_node_view_redirect($nid){
  1045. if(empty($nid)) return false;
  1046.  
  1047. $rediractable_types = array('record');
  1048.  
  1049. $type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(":nid" => $nid))->fetchField();
  1050. if(in_array($type, $rediractable_types)){
  1051. drupal_goto('node/'.$nid.'/edit');
  1052. exit;
  1053. }
  1054. }
  1055. /**
  1056. * Implements hook_permission().
  1057. */
  1058. function omitsis_mobiliz_permission(){
  1059. return array(
  1060. 'administer mobiliz settings' => array(
  1061. 'title' => t("Administer Mobiliz Site settings"),
  1062. ),
  1063. );
  1064. }
  1065.  
  1066. function _mobiliz_record_cancel_submit(){
  1067. drupal_goto('records');
  1068. exit;
  1069. }
  1070.  
  1071.  
  1072. /**
  1073. * Implementation of hook_menu_alter().
  1074. */
  1075. function omitsis_mobiliz_menu_alter(&$items) {
  1076. // remove the /node page
  1077. global $user;
  1078. unset($items['node']);
  1079. }
  1080.  
  1081. /**
  1082. * Page callback: Current posts settings
  1083. *
  1084. * @see omitsis_mobiliz_menu()
  1085. */
  1086. function omitsis_mobiliz_settings($form, &$form_state) {
  1087. $form = array();
  1088.  
  1089. // SOCIAL NETWORKS
  1090. $form['social'] = array(
  1091. '#type' => 'fieldset',
  1092. '#title' => t("Social networks"),
  1093. '#description' => t("Defines all social networks in the site"),
  1094. '#collapsible' => FALSE,
  1095. '#collapsed' => FALSE,
  1096. );
  1097. $social_types = omitsis_mobiliz_get_social_types();
  1098. foreach ($social_types as $social_machine => $social_name) {
  1099. $field = 'social_' . $social_machine;
  1100. $form['social'][$field] = array(
  1101. '#type' => 'textfield',
  1102. '#title' => $social_name,
  1103. '#default_value' => variable_get('omitsis_mobiliz_' . $field, ''),
  1104. '#size' => 64,
  1105. );
  1106. }
  1107.  
  1108. $form['#submit'][] = 'omitsis_mobiliz_settings_form_submit';
  1109.  
  1110. return system_settings_form($form);
  1111. }
  1112.  
  1113. /**
  1114. * Implements validation from the Form API.
  1115. *
  1116. * @param $form
  1117. * A structured array containing the elements and properties of the form.
  1118. * @param $form_state
  1119. * An array that stores information about the form's current state
  1120. * during processing.
  1121. */
  1122. function omitsis_mobiliz_settings_validate($form, &$form_state){
  1123. // SOCIAL NETWORKS
  1124. $social_types = omitsis_mobiliz_get_social_types();
  1125. foreach ($social_types as $social_machine => $social_name) {
  1126. $field = 'social_' . $social_machine;
  1127. $value = $form_state['values'][$field];
  1128. if ($value != '' && !valid_url($value, true)) {
  1129. form_set_error($field, t("Invalid url format"));
  1130. }
  1131. }
  1132. }
  1133.  
  1134. /**
  1135. * Implements submission from the Form API.
  1136. *
  1137. * @param $form
  1138. * A structured array containing the elements and properties of the form.
  1139. * @param $form_state
  1140. * An array that stores information about the form's current state
  1141. * during processing.
  1142. */
  1143. function omitsis_mobiliz_settings_form_submit($form, &$form_state) {
  1144. // Attention! use ['value'] at the end for 'text_format' fields
  1145.  
  1146. // SOCIAL NETWORKS
  1147. $social_types = omitsis_mobiliz_get_social_types();
  1148. foreach ($social_types as $social_machine => $social_name) {
  1149. $field = 'social_' . $social_machine;
  1150. variable_set('omitsis_mobiliz_' . $field, $form_state['values'][$field]);
  1151. }
  1152. }
  1153.  
  1154. function omitsis_mobiliz_render_social_network_links() {
  1155. $final_list = array();
  1156. $social_types = omitsis_mobiliz_get_social_types();
  1157. foreach ($social_types as $social_machine => $social_name) {
  1158. $field = 'social_' . $social_machine;
  1159. $social_url = variable_get('omitsis_mobiliz_' . $field, '');
  1160. if ($social_url != '') {
  1161. $final_list[] = array(
  1162. 'machine_name' => $social_machine,
  1163. 'name' => $social_name,
  1164. 'url' => $social_url,
  1165. );
  1166. }
  1167. }
  1168. $variables = array(
  1169. 'list' => $final_list,
  1170. );
  1171. return theme('social_network_links', $variables);
  1172. }
  1173.  
  1174. /**
  1175. * Social types array
  1176. *
  1177. * @return array
  1178. */
  1179. function omitsis_mobiliz_get_social_types() {
  1180. return array(
  1181. 'facebook' => 'Facebook',
  1182. 'twitter' => 'Twitter',
  1183. 'youtube' => 'Youtube',
  1184. 'instagram' => 'Instagram',
  1185. 'rss' => 'RSS',
  1186. 'linkedin' => 'LinkedIn'
  1187. );
  1188. }
  1189. /**
  1190. * General test page accesible via /test
  1191. * @return [type] [description]
  1192. */
  1193. function _mobiliz_test(){
  1194. print _mobiliz_render_block('views','garages-garages_nearby');
  1195. }
  1196.  
  1197. /**
  1198. * Implements hook_libraries_info().
  1199. */
  1200. function omitsis_mobiliz_libraries_info() {
  1201. $libraries = array();
  1202. $libraries['fancybox'] = array(
  1203. 'name' => 'Fancybox',
  1204. 'vendor url' => 'http://fancybox.net/',
  1205. 'download url' => 'http://fancyapps.com/fancybox/#license',
  1206. 'version callback' => '_mobiliz_short_circuit_version',
  1207. 'files' => array(
  1208. 'js' => array(
  1209. 'source/jquery.fancybox.pack.js',
  1210. ),
  1211. 'css' => array(
  1212. 'source/jquery.fancybox.css'
  1213. )
  1214. ),
  1215. );
  1216.  
  1217. return $libraries;
  1218. }
  1219. function _mobiliz_short_circuit_version(){
  1220. return TRUE;
  1221. }
  1222.  
  1223. /**
  1224. * Render a block.
  1225. *
  1226. * @param $module
  1227. * String Block's Module name.
  1228. * @param $name
  1229. * String Block name
  1230. * @return string
  1231. * Rendered block as HTML.
  1232. */
  1233.  
  1234. function _mobiliz_render_block($module, $name) {
  1235. $block = block_load($module, $name);
  1236. $block = _block_get_renderable_array(_block_render_blocks(array($block)));
  1237. return drupal_render($block);
  1238. }
  1239.  
  1240. /**
  1241. * Controla si el usuario es un administrador (u otro rol de administracion)
  1242. * @param [type] $user_obj [description]
  1243. * @return [bool] [description]
  1244. */
  1245. function _mobiliz_user_is_admin($user_obj = NULL) {
  1246. if (empty($user_obj)) {
  1247. global $user;
  1248. $user_obj = $user;
  1249. }
  1250.  
  1251. $admin_roles = array('administrator', 'manager', 'supervisor');
  1252.  
  1253. foreach ($user_obj->roles as $user_role) {
  1254. if (in_array($user_role, $admin_roles)) {
  1255. return TRUE;
  1256. }
  1257. }
  1258. return FALSE;
  1259. }
  1260.  
  1261. /**
  1262. * Helper para recuperar informacion de un nodo
  1263. * @param [obj] $obj el objeto "nodo"
  1264. * @param [string] $field el campo a buscar, ej "field_ingrediente_nombre"
  1265. * @param [string] $field_type el valor guardado en la bbdd, ej "safe_value"
  1266. * @return [type] [description]
  1267. */
  1268. function _mobiliz_get_field($obj, $field, $field_type, $bundle = 'node') {
  1269. $f = field_get_items($bundle, $obj, $field);
  1270. if (!empty($f[0][$field_type])) {
  1271. return $f[0][$field_type];
  1272. }
  1273. return NULL;
  1274. }
  1275.  
  1276. /**
  1277. * Helper para recuperar informacion multiple de un nodo
  1278. * @param [obj] $obj el objeto "nodo"
  1279. * @param [string] $field el campo a buscar, ej "field_ingrediente_nombre"
  1280. * @param [string] $field_type el valor guardado en la bbdd, ej "safe_value"
  1281. * @return [type] [description]
  1282. */
  1283. function _mobiliz_get_multiple_field($obj, $field, $field_type, $bundle = 'node') {
  1284. $f = field_get_items($bundle, $obj, $field);
  1285. if (!empty($f[0][$field_type])) {
  1286. return $f;
  1287. }
  1288. return NULL;
  1289. }
  1290.  
  1291.  
  1292. function _mobiliz_workflow_get_states(){
  1293. $states_raw = db_query("SELECT sid, state FROM {workflow_states} WHERE status = 1 AND sysid = 0 ORDER BY weight ASC")->fetchAll();
  1294. $states = array();
  1295. foreach($states_raw as $key => $state){
  1296. $states[$key]['sid'] = $state->sid;
  1297. $states[$key]['state'] = $state->state;
  1298. }
  1299. return $states;
  1300. }
  1301. /**
  1302. * Workflow: get state name given its sid
  1303. * @param [type] $sid [description]
  1304. * @return [type] [description]
  1305. */
  1306. function _mobiliz_workflow_get_state_name($sid){
  1307. return db_query("SELECT state FROM {workflow_states} WHERE sid = :sid AND status = 1 AND sysid = 0", array(":sid" => $sid))->fetchField();
  1308. }
  1309.  
  1310. /**
  1311. * Returns lat/lng values for a node
  1312. * @param [type] $nid [description]
  1313. * @return array [description]
  1314. */
  1315. function _mobiliz_get_latlng($nid){
  1316. $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();
  1317.  
  1318. if(isset($geo[0])){
  1319. return array('lat' => $geo[0]->lat, 'lng' => $geo[0]->lng);
  1320. }
  1321. return false;
  1322. }
  1323.  
  1324. /**
  1325. * Renders the nearby garages view passing record lat/lng coordinates
  1326. * @param [type] $geo [description]
  1327. * @return [type] [description]
  1328. */
  1329. function _mobiliz_get_nearby_view($geo, $view_name, $display_name, $args = array(), $personal_situation = array(), $type = array()) {
  1330.  
  1331. $view = views_get_view($view_name);
  1332. $view->set_display($display_name);
  1333. $view->set_arguments(array($args));
  1334. $view->exposed_input['geo'] = array('latitude' => $geo['lat'], 'longitude' => $geo['lng']);
  1335. if (!empty($personal_situation)) {
  1336. foreach ($personal_situation['und'] as $key => $value) {
  1337. $ps[] = $value['target_id'];
  1338. }
  1339. }
  1340. //$types[] = $type;
  1341. $view->exposed_input['field_prescriber_personal_sit_tid'] = $ps;
  1342. $view->exposed_input['field_prescriber_type_tid'] = $type;
  1343.  
  1344.  
  1345. /*
  1346. * Filtering garage tool by car brand
  1347. * brand = 0 -> renault et dacia
  1348. * brand = 1 >
  1349. */
  1350. $node = menu_get_object();
  1351. $filter_brand = 0;
  1352. if (isset($node->field_brand['und'][0]['tid']) && $node->field_brand['und'][0]['tid'] != 73 && $node->field_brand['und'][0]['tid'] != 74) {
  1353. $filter_brand = 1;
  1354. }
  1355. //kpr($view);
  1356. $view->exposed_input['field_garage_repairs_all_brands_value'] = $filter_brand;
  1357. $view->pre_execute();
  1358. $view->execute();
  1359.  
  1360. //$r = $view->result;
  1361. return $view->render();
  1362. }
  1363.  
  1364. /**
  1365. * Renders the nearby garages view passing record lat/lng coordinates
  1366. * @param [type] $geo [description]
  1367. * @return [type] [description]
  1368. */
  1369. function _mobiliz_get_nearby_view_data($geo, $view_name, $display_name){
  1370. $view = views_get_view($view_name);
  1371. $view->set_display($display_name);
  1372.  
  1373. $view->exposed_input['geo'] = array('latitude' => $geo['lat'], 'longitude' => $geo['lng']);
  1374.  
  1375. $view->pre_execute();
  1376. $view->execute();
  1377. $view->preview();
  1378. $view->render();
  1379.  
  1380. return $view->result;
  1381. }
  1382.  
  1383. /**
  1384. * Borra la cache de un field en concreto.
  1385. *
  1386. * @param int $eid
  1387. * El id de la entity.
  1388. * @param string $bundle
  1389. * El bundle, ej user, node, taxonomy.
  1390. */
  1391. function _mobiliz_cache_reset($eid, $bundle = 'node') {
  1392. cache_clear_all('field:' . $bundle . ':' . $eid, 'cache_field');
  1393. }
  1394.  
  1395. function omitsis_mobiliz_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  1396.  
  1397. }
  1398. function _mobiliz_after_build($form, &$form_state) {
  1399. $form['path']['#access'] = FALSE;
  1400. $form['menu']['#access'] = FALSE;
  1401. return ($form);
  1402. }
  1403. //FALTA AFEGIR birth date i sumar nom i cognom
  1404. function _mobiliz_check_before_18_months($nid) {
  1405. $node = node_load($nid);
  1406. $mail ='';
  1407. if (isset($node->field_record_email['und'][0]['email'])) {
  1408. $mail = $node->field_record_email['und'][0]['email'];
  1409. }
  1410. if (isset($node->field_record_birth['und'][0]['value'])) {
  1411. $birth = $node->field_record_birth['und'][0]['value'];
  1412. }
  1413. if (isset($node->field_record_prenom['und'][0]['value'])) {
  1414. $prenom = $node->field_record_prenom['und'][0]['value'];
  1415. }
  1416.  
  1417. $check = db_query("
  1418. SELECT node.nid, node.created AS node_created, node.title AS node_title
  1419. FROM {node} node
  1420. LEFT JOIN {workflow_node_history} workflow_node_current ON ( SELECT max(hid) FROM {workflow_node_history}
  1421. where nid = node.nid
  1422. and sid != old_sid ) = workflow_node_current.hid
  1423. 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')
  1424. 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')
  1425. 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')
  1426. WHERE
  1427. (
  1428. (
  1429. (node.title = '$node->title')
  1430. AND
  1431. (node.nid != '$node->nid')
  1432. AND
  1433. (field_data_field_record_email.field_record_email_email = '$mail')
  1434. AND
  1435. (field_data_field_record_birth.field_record_birth_value = '$birth')
  1436. AND
  1437. (field_data_field_record_prenom.field_record_prenom_value = '$prenom')
  1438. )
  1439. AND
  1440. (
  1441. (
  1442. (node.status = '1')
  1443. AND
  1444. (node.type IN ('record'))
  1445. AND
  1446. (workflow_node_current.sid IN ('6'))
  1447. )
  1448. )
  1449. AND
  1450. (
  1451. node.created > UNIX_TIMESTAMP(CURRENT_DATE - INTERVAL '18' MONTH)
  1452. )
  1453. )
  1454. ")->fetchAll();
  1455.  
  1456. if (isset($check[0])) {
  1457. return array('requester' => $check[0]->node_title, 'date' => $check[0]->node_created);
  1458. }
  1459. return false;
  1460. }
  1461.  
  1462.  
  1463. function omitsis_mobiliz_form_organisation_partenaire_node_form_alter(&$form, &$form_state, $form_id){
  1464. if (!empty($form['nid']['#value'])) {
  1465. $form['list_users'] = array(
  1466. '#sufix' => '<h2>Members</h2>',
  1467. '#markup' => views_embed_view('prescribers_administration_users', 'block_1'),
  1468. '#weight' => 99
  1469. );
  1470. }
  1471.  
  1472. $form['#after_build'][] = '_mobiliz_after_build';
  1473. $form['actions']['#weight'] = 97;
  1474. unset($form['options']);
  1475. unset($form['author']);
  1476. unset($form['revision_information']);
  1477. //Prescriber
  1478. global $user;
  1479. if (in_array('7',array_keys($user->roles))) {
  1480. $form['actions']['#access'] = FALSE;
  1481.  
  1482. }
  1483. }
  1484.  
  1485. function submit_button_1_submit($form, &$form_state) {
  1486. $node = node_form_submit_build_node($form, $form_state);
  1487. node_save($node);
  1488. if ($node->nid) {
  1489. $form_state['values']['nid'] = $node->nid;
  1490. $form_state['nid'] = $node->nid;
  1491. $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => '5'));
  1492. }
  1493. else {
  1494. drupal_set_message(t('The post could not be saved.'), 'error');
  1495. $form_state['rebuild'] = TRUE;
  1496. }
  1497. }
  1498. function submit_button_2_submit($form, &$form_state) {
  1499. $node = node_form_submit_build_node($form, $form_state);
  1500. node_save($node);
  1501. if ($node->nid) {
  1502. $form_state['values']['nid'] = $node->nid;
  1503. $form_state['nid'] = $node->nid;
  1504. $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => '4'));
  1505. }
  1506. else {
  1507. drupal_set_message(t('The post could not be saved.'), 'error');
  1508. $form_state['rebuild'] = TRUE;
  1509. }
  1510. }
  1511.  
  1512. //function ($form, &$form_state) {
  1513. // $node = node_form_submit_build_node($form, $form_state);
  1514. // $fragment = $form_state['values']['salva'];
  1515. // kpr($fragment);
  1516. // die;
  1517. //
  1518. // node_save($node);
  1519. // if ($node->nid) {
  1520. // $form_state['values']['nid'] = $node->nid;
  1521. // $form_state['nid'] = $node->nid;
  1522. // $form_state['redirect'] = array('node/'.$node->nid.'/edit', array('fragment' => $fragment));
  1523. // }
  1524. // else {
  1525. // drupal_set_message(t('The post could not be saved.'), 'error');
  1526. // $form_state['rebuild'] = TRUE;
  1527. // }
  1528. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement