src/Controller/VStudentCardController.php line 678

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Psr\Log\LoggerInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use App\Entity\VCard;
  6. use App\Form\VCardType;
  7. use App\Entity\VCardStudent;
  8. use App\Form\VCardStudentType;
  9. use App\Repository\VCardRepository;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Component\Mailer\MailerInterface;
  15. use Symfony\Component\Mime\Email;
  16. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  17. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  18. use Symfony\Component\Filesystem\Filesystem;
  19. use Symfony\Component\Filesystem\Path;
  20. use Symfony\Component\HttpClient\CurlHttpClient;
  21. use JeroenDesloovere\VCard\VCard as VCardFile;
  22. use chillerlan\QRCode\QRCode;
  23. use chillerlan\QRCode\QROptions;
  24. use phpCAS;
  25. use App\Controller\VCardController;
  26. use DateTime;
  27. use DateTimeZone;
  28. class VStudentCardController extends  CustomController // AbstractController
  29. {
  30.     private    $applicationSender 'no-reply';
  31.     // private $uploadsDIR = __DIR__.'/../../public/uploads/';
  32.     private $qrcodeOutDIR __DIR__.'/../../public/uploads/';
  33.     private $studentsFileURL 'https://am-auriontbo-1/servlet/Dispatcher?action=transformFavori&data=<transformFavori><favori><id>132012446</id></favori><database>ensam</database><xslFile>JSON_json.xsl</xslFile></transformFavori>';
  34.     
  35.     // private $studentsCacheFile = __DIR__.'/../../public/uploads/'.'students.json';
  36.     private $CACHE_DURATION 120;
  37.     private $SOCIAL_NETS = array(
  38.                 'linkedin'     => 'https://www.linkedin.com/in/',
  39.                 'facebook'    => 'https://www.facebook.com/',
  40.                 'twitter'    => '',
  41.                 'tiktok'    => 'https://www.tiktok.com/',
  42.                 'instagram'    => 'https://www.instagram.com/',
  43.                 'other'        => '',
  44.             );
  45.     private $pendingMailDatas = array(
  46.                         'à valider' => array(
  47.                             'subject' => '[Rappel] Carte de visite',
  48.                             'content' => 'La carte de {PRENOM} {NOM} attend votre validation, cliquez sur le lien pour accéder à la demande de validation.<br/>'
  49.                                         '<a href="{URI}/v/card/manager">'
  50.                                         'Voir...'
  51.                                     '</a><br/>'
  52.                                     '<i>Ce message a été créé automatiquement par le gestionnaire de carte de visites des Arts et Métiers, merci de ne pas y répondre.</i>'
  53.                         ),
  54.                         'enregistrée' => array('subject' => '[Rappel] Carte de visite',
  55.                         'content' => "N'oubliez-pas de soumettre votre carte de visite pour sa publication...<br/>"
  56. .'Cliquez sur le lien pour la soumettre.<br/>'
  57.                                         '<a href="{URI}/v/card/">'
  58.                                         'Voir...'
  59.                                     '</a><br/>'
  60.                                     '<i>Ce message a été créé automatiquement par le gestionnaire de carte de visites des Arts et Métiers, merci de ne pas y répondre.</i>'
  61.                         ),
  62.                         'rejetée' => array('subject' => '[Rappel] Carte de visite',
  63.                                     'content' => 'Votre carte de visite a été rejetée.<br/>'
  64.                                             .'Vous pouvez la modifier à cette adresse:<br/>'
  65.                                             '<a href="{URI}/v/card/{ID_VCARD}">'
  66.                                             'Voir...'
  67.                                         '</a><br/>'
  68.                                         '<i>Ce message a été créé automatiquement par le gestionnaire de carte de visites des Arts et Métiers, merci de ne pas y répondre.</i>'
  69. // "VALIDATE_CONTENT"
  70.                                 ),
  71.     );
  72.     protected function getNewStudentVersion($id) {
  73.     $out = -1;
  74.     $query 'select max(version)+1 as NEW_VERSION from vcard_student where id_apprenant='.$id;
  75.     $result $this->selectRaw($query);
  76.     if (isset($result[0]['NEW_VERSION'])) {
  77.         $out $result[0]['NEW_VERSION'];
  78.     }
  79.     return $out;
  80.     }
  81.     protected function getNewStudentVCardId($TEST_MODE false) {
  82.         $out = -1;
  83.     if ($TEST_MODE === false) {
  84.     $query 'select max(id_vcard) + 1 as NEW_ID from VCARD_STUDENT';
  85.     $result $this->selectRaw($query);
  86.     if (isset($result[0]['NEW_ID'])) {
  87.         $out $result[0]['NEW_ID'];
  88.     }
  89.     } else {
  90.         $out date_timestamp_get(date_create());
  91.     }
  92.     return $out;
  93.     }
  94.     protected function getParamType($param) : String{
  95.         $out 's';
  96.     if (ctype_digit((string) $param)) {
  97.         $out =  $param <= PHP_INT_MAX 'i' 's';
  98.     }
  99.     if (is_numeric($param)) {
  100.         $out 'd';
  101.     }
  102.     return $out;
  103. }
  104. protected function getBoundTypes(array $values) : String {
  105.     $out "";
  106.     foreach($values as $k => $v) {
  107.         $out .= $this->getParamType($values[$k]); 
  108.     }
  109.     return $out;
  110. }    
  111. protected function writeRaw($SQL, array $values$DBG false) {
  112.     $out false;
  113.     $nb_values count($values);
  114.     if (isset($SQL)
  115.         && strpos($SQL':') !== false
  116.         && $nb_values 0
  117.     ) {
  118.         $wc_count substr_count($SQL':');
  119.         if ($wc_count == $nb_values) {
  120.             // $bound_types = $this-> getBoundTypes($values);
  121.             // echo(__METHOD__. ': SQL:' . $SQL . ', '. $bound_types);
  122.             $em $this->getDoctrine()->getManager();
  123.             // $statement = $em->getConnection()->prepare($SQL);
  124.             
  125.            $db $em->getConnection(); // Doctrine_Manager::getInstance()->getCurrentConnection();
  126.             $query $db->prepare($SQL);
  127.             $res $query->execute($values);
  128.             /*
  129.             $results = $res->fetchAllAssociative();
  130.              echo(__METHOD__.' results: '.var_export($results, true));       
  131.              */
  132. /*
  133.             // Set parameters
  134.             foreach($values as $item => $item_value) {
  135.                 $statement->bindValue($item, $item_value);
  136.             }
  137.             $res = $statement->execute();
  138.  */
  139.             if ( TRUE || // TODO: remove Debug 
  140.                 isset($_GET['DBG'])
  141.                 && $_GET['DBG'] == 1
  142.             ) {
  143.                   echo(__METHOD__.' values: '.var_export($valuestrue));       
  144.             }
  145.             $out true;
  146.         } // END if count
  147.     }
  148.     return $out;
  149. }
  150.     /**
  151.      * @Route("/v/student/card/", name="app_v_card_student_index", methods={"GET", "POST"})
  152.      */
  153. public function index(Request $requestVCardRepository $vCardRepositoryLoggerInterface $logger): Response {
  154.                 return new Response(null302, array(
  155.                     'Location'        => 'show',
  156.                 ));
  157. }
  158.  /**
  159.      * @Route("/v/student/card/auth", name="app_v_card_student_auth", methods={"GET", "POST"})
  160.      */
  161.     public function auth(Request $request): Response {
  162.                 return new Response(null302, array(
  163.                     'Location'        => "https://{$_SERVER['HTTP_HOST']}",
  164.                 ));
  165.     }
  166.     /**
  167.      * @Route("/v/student/card/testauth", name="app_v_card_student_testauth", methods={"GET", "POST"})
  168.      */
  169.     public function testauth(Request $request): Response {
  170.         $session $request->getSession();
  171.         $this->checkAuth($session'app_v_card_student_testauth');
  172.         $content __METHOD__.': authentified';
  173.         return new Response($content302, array(
  174.                     'Location'        => 'auth',
  175.         ));
  176.     }
  177.     /**
  178.      * @Route("/v/student/card/edit", name="app_v_card_student_edit", methods={"GET", "POST"})
  179.      */
  180. public function edit(Request $request): Response {
  181.         $session $request->getSession();
  182.         
  183.         $this->checkAuth($session'app_v_card_student_edit');
  184.         $user_email $session->get('user_email'); // $_GET['email'];
  185.         $is_auth $session->get('is_auth'); // $_GET['email'];
  186.     $url "https://{$_SERVER['HTTP_HOST']}/v/student/card/last?";
  187.     $DBG = isset($_GET['DBG']) && $_GET['DBG'] == '1';
  188.     $student_datas = array(
  189.         'avecphoto'    => 'non',
  190.         'tel2'        => '',
  191.             );
  192.     if (isset($user_email)
  193.         && $is_auth
  194.     ) {
  195.         /*
  196.         $found = $this->getStudentDatasFromMail($user_email);
  197.         if (isset($found)) {
  198.             $student_datas['titre'] = $found['Fonction'];
  199.             $student_datas['tel']    = $found['Portable'];
  200.             $student_datas['emailPerso']    = $found['emailPerso'];
  201.         */
  202.         $student_datas $this->getAllStudentDatas($user_email$DBG);
  203.     // echo(__METHOD__.' student_datas:'.var_export($student_datas, true)); exit();
  204.     if (!isset($student_datas['id.Apprenant'])) {
  205.         return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  206.     } else if (!isset($student_datas['ID_VCARD'])) {
  207.             $args = array();
  208.             if (isset($_GET['email'])) {
  209.                 $args['email'] = $_GET['email'];
  210.             }
  211.             return $this->redirectToRoute('app_v_card_student_new'$argsResponse::HTTP_SEE_OTHER);
  212.      }
  213.         $ide_dossier 'E-'.$student_datas['id.Apprenant'];
  214.     $custom_photo_key '';
  215.     $delete_custom_key '';
  216.     $file_path $this->uploadsDIR.('photo_'.$ide_dossier.'.jpg');
  217.     $is_custom_photo = (file_exists($file_path)); // NOTE: user needs to delete to disable custom
  218.     if ($is_custom_photo) {
  219.         $custom_photo_key $this->storeInSession($session$file_path);
  220.         $delete_custom_key $this->storeInSession($session$file_path);
  221.     }
  222.             $comm_datas json_decode($student_datas['COMMENTAIRE'], true); // NOTE: commentaire used for keeping opt fields 
  223.             $comm_datas['login'] = $student_datas['login.Individu'];
  224.             if (isset($comm_datas['role'])) {
  225.                 $student_datas['role'] = $comm_datas['role'];
  226.             }
  227.             if (!isset($comm_datas['date_expiration'])
  228.                 && isset($student_datas['date_expiration'])
  229.             ) {
  230.                 $comm_datas['date_expiration'] = $student_datas['date_expiration'];
  231.             }
  232.             /* TODO: enable social networks
  233.              
  234.             foreach($this->SOCIAL_NETS as $net_item => $val) {
  235.                 if (isset($comm_datas[$net_item])
  236.             ) {
  237.                     $student_datas[$net_item] = $comm_datas[$net_item];
  238.                 }
  239.             }
  240.             // */
  241.             $vCardStudent = new VCardStudent();
  242.             $vCardStudent->setcommentaire($student_datas['COMMENTAIRE']);
  243.             $form $this->createForm(VCardStudentType::class, $vCardStudent);
  244.             $form->handleRequest($request);
  245.             if ($form->isSubmitted() && $form->isValid()) {
  246.                 $datas $form->getData();
  247.                 $titre_datas json_decode($datas->gettitre(), true);
  248.                 if (isset($titre_datas[1])) {
  249.                     $comm_datas['role'] = $titre_datas[1];
  250.                 } else {
  251.                     $comm_datas['role'] = '';
  252.                 }
  253.                 $form_comment $datas->getcommentaire();
  254.                 if (isset($form_comment)) {
  255.                     $tmp_comms json_decode($form_commenttrue);
  256.                     $comm_datas array_merge($comm_datas$tmp_comms);    
  257.                 }
  258.                 $datas->setid_apprenant($student_datas['id.Apprenant']);
  259.                 $datas->setformation($student_datas['Formation']);
  260.                 $datas->setVERSION(printf("%d"$student_datas['VERSION']) + 1);
  261.                 $datas->setcommentaire(json_encode($comm_datas));
  262.                 $this->addVCardStudent($datas); // , true); // TODO: REMOVE true !!!!!
  263.                 $this->generateQrCodeFile($url$user_email);
  264.                 if (isset($_GET['DBG'])) {
  265.                     echo(__METHOD__.': 'var_export($datas->gettitre(), true));
  266.                     echo(__METHOD__.': 'var_export($datastrue));
  267.                 } else {
  268.                     return $this->redirectToRoute('app_v_card_student_show', [], Response::HTTP_SEE_OTHER);
  269.                 }
  270.             }
  271.             
  272.         //} // END if found
  273.             return $this->renderForm('v_card_student/new.html.twig', [
  274.             // 'v_card' => $vCard,
  275.             'user_email' => $user_email,
  276.             // 'personnel'    => $personnel_datas,
  277.             'student'    => $student_datas,
  278.             'is_new'    => true,
  279.             'current_card'     => true,
  280.             'disp_form_student'    => true,
  281.             // 'is_manager'    => $session->get('is_manager'),
  282.         'custom_photo_key'     => $custom_photo_key,
  283.         'delete_custom_key'    => $delete_custom_key,
  284.             'form' => $form,
  285.         ]);
  286.     } else { // END if user_email
  287.         return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  288.     }
  289.         }
  290.     /**
  291.      * @Route("/v/student/card/{id}/vcardinfo", name="app_v_card_student_vcardinfo", methods={"GET", "POST"})
  292.      */
  293. public function vcardinfo(Request $request$id): Response {
  294.     $datas = array();
  295.     $found $this->selectVcardStudentWhere('ID_VCARD='.sprintf("%d"$id));
  296.     if (isset($found)) {
  297.         $datas $found;
  298.     }
  299.     $content __METHOD__.' datas: '.var_export($datastrue);
  300.     return new Response($content200, array(
  301.                     )
  302.             );
  303.     }
  304.     /**
  305.      * @Route("/v/student/card/notfound", name="app_v_card_student_notfound", methods={"GET"})
  306.      */
  307.     public function notfound(Request $request): Response {
  308.     // echo(__METHOD__); exit(); 
  309.     $v_datas = array();
  310.     $tpl_name 'v_card_student/message.html.twig';
  311.     $needs_create false;
  312.     $v_datas'disp_message'] = true;
  313.     $v_datas'is_student'] = true;
  314.     $v_datas['message'] = ($needs_create 'Aucune carte' 'Carte non').'  trouvée....';
  315.     if (isset($_GET['embedded'])) {
  316.         $v_datas['embedded'] = true;
  317.         // $v_datas['message'] = 'Carte non trouvée.<br/>Créer votre carte de visite <a href="/v/card">ici</a>';
  318.         if (isset($_GET['needs_create']) && $_GET['needs_create'] == 1) {
  319.             $v_datas['needs_create'] = $needs_create true;
  320.         
  321.         }
  322.         $tpl_name 'v_card_student/notfound_embedded.html.twig';
  323.     }
  324.         return $this->render($tpl_name$v_datas); 
  325.     }
  326.     /**
  327.      * @Route("/v/student/card/show", name="app_v_card_student_show", methods={"GET", "POST"})
  328.      */
  329.     public function show(Request $request): Response {
  330.         $session $request->getSession();
  331.         $this->checkAuth($session'app_v_card_student_show');
  332.     $email $session->get('user_email'); // $_GET['email'];
  333.     $is_auth $session->get('is_auth');
  334.     $student_datas $this->getAllStudentDatas($email, isset($_GET['DBG']) && $_GET['DBG'] == 1); // $this->getStudentDatasFromMail($email);
  335.     if (!isset($student_datas['id.Apprenant'])) {
  336.         return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  337.     }
  338.     if (!isset($student_datas['ID_VCARD'])) {
  339.         return $this->redirectToRoute('app_v_card_student_new', [], Response::HTTP_SEE_OTHER);
  340.     }
  341.     $ide_dossier 'E-'.$student_datas['id.Apprenant'];
  342.     // echo(__METHOD__.': student_datas: '. var_export($student_datas, true));
  343.     $vcard_datas = array();
  344.     $vcard_datas['user_email'] = $email;
  345.     $vcard_datas['disp_vcard_student'] = true;
  346.     $vcard_datas['current_card'] = true;
  347.     $vcard_datas['can_validate'] = false;
  348.     $vcard_datas['can_duplicate'] = false;
  349.     $vcard_datas['validated'] = true;
  350.     $vcard_datas['new_version'] = true;
  351.         $vcard_datas['is_manager'] = false;
  352.         // $vcard_datas['published'] = true;
  353.         // $vcard_datas['published_card'] = true; 
  354.     $vcard_datas['needs_submit'] = false;
  355.     $vcard_datas['personnel_datas'] = array(
  356.         'PRENOM'=> $student_datas['Prénom'],
  357.         'NOM'    => $student_datas['Nom'],
  358.         'TEL_PRO'    => $student_datas['Portable'],
  359.         'EMAIL_PRO'    => $email,
  360.     );
  361.     $comm_datas json_decode($student_datas['COMMENTAIRE'], true);
  362.     if (isset($comm_datas['role'])) {
  363.         $vcard_datas['personnel_datas']['ROLE'] = $comm_datas['role'];
  364.     }
  365.     $vcard_datas['v_datas_card'] = array(
  366.         'SITE_RATTACHEMENT' => $student_datas['Campus'],
  367.         'ADRESSE_PRO'    => $student_datas['Campus'].' - '$student_datas['ADRESSE_PRO'],
  368.         // 'ADRESSE_PRO'        => $student_datas['ADRESSE_PRO'],
  369.     );
  370.     $vcard_datas['v_card'] = array(
  371.         'titre'    => '["'.$student_datas['Fonction'].'"]',
  372.         'tel'    => $student_datas['TEL'], // '["'.$student_datas['Portable'].'"]',
  373.         'email' => '["'.$student_datas['email'].'","'.$student_datas['emailPerso'].'"]'
  374.     );
  375.     //* // TODO: enable social links
  376.     foreach ($this->SOCIAL_NETS as $net_item => $net_value) {
  377.         if (isset($comm_datas[$net_item])
  378.             && $comm_datas[$net_item] != ''
  379.         ) {
  380.             $vcard_datas['v_card'][$net_item] = // $net_value.
  381.                 $comm_datas[$net_item];
  382.             $vcard_datas['v_card'][$net_item.'_url'] = $net_value.$comm_datas[$net_item];
  383.         }
  384.     }
  385.     //  */
  386.     $photo_file '/mnt/recadre/'.$ide_dossier.'.jpg';
  387.     if ($student_datas['AVEC_PHOTO'] == 'oui'
  388.         || (file_exists($this->uploadsDIR.('photo_'.$ide_dossier.'.jpg')))
  389.     ) {
  390.                 if ($student_datas['AVEC_PHOTO'] != 'oui') {
  391.                     $photo_file $this->uploadsDIR.('photo_'.$ide_dossier.'.jpg');
  392.                 }
  393.         $key $this->storeInSession($session$photo_file);
  394.         if (!empty($key)) {
  395.             $vcard_datas['PHOTO_K'] = $key;
  396.         }
  397.     }
  398.         return $this->renderForm('v_card_student/show.html.twig'$vcard_datas); 
  399.     /* 
  400.         [
  401.             'v_card' => $vCard,
  402.         'vcard_datas' => $vcard_datas,
  403.         'v_datas_card' => $v_datas_card,
  404.         'personnel_datas' => $personnel_datas,
  405.         'infos_carte' => $infos_carte,
  406.         'can_validate' => $this->isCardManager($vCard),
  407.         ]
  408. );
  409.     */
  410. }
  411.     public function selectMailLike($search$DBG false) {
  412.     $out = array();
  413.         if (!empty($search)) {
  414.         $RAW_QUERY "SELECT EMAIL FROM VCARD_STUDENT where EMAIL like '%".$search."%' order by VERSION desc FETCH FIRST 1 ROWS ONLY"// "SELECT EMAIL FROM VCARD where STATUT='validé' and LOWER(EMAIL) like '%".$search."%' order by VERSION desc FETCH FIRST 1 ROWS ONLY"; // "SELECT EMAIL FROM VCARD where LOWER(EMAIL) like '%". $search."%'"; // ' where IDE_DOSSIER='.$ide_dossier;
  415.         
  416.         $found $this->selectRaw($RAW_QUERY$DBG);
  417.         if (count($found) > 0) {
  418.             $out $found;
  419.         }    
  420.     }
  421.     return $out;
  422.     }
  423.     /**
  424.      * @Route("/v/student/card/search", name="app_v_card_student_search", methods={"GET", "POST"})
  425.      */
  426.     public function search(Request $request): Response {
  427.         // echo(__METHOD__.' _POST: '.var_export($_POST, true)); exit();
  428.     $session $request->getSession();
  429.     $is_auth $session->get('is_auth');
  430.     $datas = array();
  431.     $datas['is_manager'] = $session->get('is_manager');
  432.     if (!$is_auth) {
  433.         $datas['needs_auth'] = true;
  434.     }
  435.     $datas['disp_search_student'] = true;
  436.     if (isset($_POST['email'])
  437.         && $_POST['email'] != ''
  438.     ) {
  439.         $ans = array('msg' => 'NOT_FOUND');
  440.         $found $this->selectMailLike($_POST['email']); // getVCardFromEmail($_POST['email'], $get_like = true);
  441.         // echo(__METHOD__.' found: '.var_export($found, true));
  442.         /*
  443.         if (isset($found['EMAIL_PRO'])) {
  444.             $ans['msg'] = 'ok';
  445.             $ans['EMAIL_PRO'] = $found['EMAIL_PRO'];
  446.         }
  447.         //*/
  448.         //
  449.         if (count($found) > 0) {
  450.             $ans $found;
  451.         }
  452.         $content json_encode($ans);
  453.         return new Response($content200, array(
  454.                 'Content-type'        => 'text/json',
  455.             )
  456.         );
  457.     } else {
  458.          return $this->render('v_card_student/search.html.twig'$datas); 
  459.     }
  460.     }
  461.     protected function addOptVcardFields($vcard, array $datas$DBG false) {
  462.         if (isset($vcard)) {
  463.         if ($DBG !== false) {
  464.                 echo(__METHOD__.': datas: '.var_export($datastrue));
  465.         }
  466.             $vcard->addRole('Elève ingénieur Arts et Métiers');
  467.             if (isset($datas['personnel_datas']['ROLE'])) {
  468.                 $vcard->addNote($datas['personnel_datas']['ROLE']);
  469.             }
  470.         foreach ($this->SOCIAL_NETS as $field_type => $values) {
  471.         if (isset($datas['v_datas_card'][$field_type])) {
  472.             $vcard->addURL($datas['v_datas_card'][$field_type], $field_type);
  473.         }
  474.         }
  475.         }
  476.     
  477.     }
  478.    /**
  479.      * @Route("/v/student/card/last", name="app_v_card_student_last", methods={"GET"})
  480.      */
  481. public function last(Request $requestLoggerInterface $logger): Response {
  482.     $session $request->getSession();
  483.     $is_auth $session->get('is_auth');
  484.     $user_email = isset($_GET['email']) ?  $_GET['email'] : $session->get('user_email');
  485.     $student_datas = array(
  486.         'avec_photo'    => 'non',
  487.         'tel2'        => '',
  488.             );
  489.     $vcard_datas['can_validate'] = false;
  490.     $vcard_datas['needs_submit'] = false;
  491.     $vcard_datas['can_duplicate'] = false;
  492.     $vcard_datas['disp_vcard_student'] = true;
  493.     $vcard_datas['is_last'] = true;
  494.     $ide_dossier null;
  495.     $tpl_name 'v_card_student/last.html.twig';
  496.     $is_download = (    
  497.             (isset($_GET['download']) && $_GET['download'] == 1)
  498.             || (isset($_POST['download']) && $_POST['download'] == 1)
  499.             );
  500.     if (!$is_download) {
  501.             $vcard_datas['is_search'] = true;
  502.         if (isset($_GET['back'])
  503.             && !empty($_GET['back'])
  504.         ) {
  505.             $vcard_datas['back_url'] = '/v/card/search';
  506.         }
  507.         if (isset($_GET['embedded'])) {
  508.             $vcard_datas['embedded'] = true;
  509.         }
  510.         $vcard_datas['is_manager'] = false;
  511.         $vcard_datas['published'] = true;
  512.         $vcard_datas['published_card'] = true
  513.         if (isset($_GET['back'])
  514.             && $_GET['back'] == 'search'
  515.         ) {
  516.             $vcard_datas['from_search'] = true;
  517.         }
  518.     }
  519.     if (isset($user_email)) {
  520.         $found $this->getStudentDatasFromMail($user_email);
  521.         if (isset($found)) { 
  522.             /*
  523.             $student_datas['email'] = $user_email;
  524.             $student_datas['Fonction'] = $found['Fonction'];
  525.             $student_datas['Portable']    = $found['Portable'];
  526.             $student_datas['emailPerso']    = $found['emailPerso'];
  527.             $student_datas['Campus']    = $found['Campus'];
  528.             //*/
  529.             //
  530.             $student_datas $this->getAllStudentDatas($user_email, isset($_GET['DBG']) && $_GET['DBG'] == 1);
  531.             if (!isset($student_datas['ID_VCARD'])) {
  532.                 return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  533.             }
  534.             $ide_dossier 'E-'.$student_datas['id.Apprenant'];
  535.             /*
  536.                 $tmp_vcard  = new VCard();
  537.                 $tmp_vcard->setid_vcard(123);
  538.                 $tmp_vcard->settitre($student_datas['titre']);
  539.                 $tmp_vcard->settel($student_datas['tel']);
  540.                 $tmp_vcard->setemail($user_email);
  541.                 $tmp_vcard->setavec_photo($student_datas['avec_photo']);
  542.              */
  543.     $vcard_datas['v_card'] = array(
  544.         'titre'    => '["'.$student_datas['Fonction'].'"]',
  545.         'tel'    => $student_datas['TEL'], // '["'.$student_datas['Portable'].'"]',
  546.         'email' => '["'.$student_datas['email'].'","'.$student_datas['emailPerso'].'"]',
  547.     );
  548.     $tmp_tel_datas json_decode($student_datas['TEL'], true);
  549.     $d_creation_datas explode(' '$student_datas['D_CREATION']);
  550.     $d_creation_label $d_creation_datas[1];
  551.     $d_creation_datas explode('-'$d_creation_datas[0]);
  552.     $d_creation_label $d_creation_datas[2].'/'$d_creation_datas[1].'/'.$d_creation_datas[0].' '.$d_creation_label;
  553.     $vcard_datas['v_datas_card'] = array(
  554.         'IDE_DOSSIER'    => $ide_dossier,
  555.         'SITE_RATTACHEMENT' => $student_datas['Campus'],
  556.         'ID_VCARD'    => $student_datas['ID_VCARD'],
  557.         'EMAIL_PRO'    => $user_email,
  558.         'ADRESSE_PRO'    => $student_datas['Campus'].' - '$student_datas['ADRESSE_PRO'],
  559.         'AVEC_PHOTO'    => $student_datas['AVEC_PHOTO'],
  560.         'PRENOM'    => $student_datas['Prénom'],
  561.         'NOM'        => $student_datas['Nom'],
  562.         'TITRE'        => '["'.$student_datas['Fonction'].'"]',
  563.         'TEL_PRO'    => (isset($tmp_tel_datas[0]) ? $tmp_tel_datas[0] : ''), // $student_datas['Portable'],
  564.         'TEL'        => $student_datas['TEL'],
  565.         'EMAIL'     => '["'.$student_datas['email'].'","'.$student_datas['emailPerso'].'"]',
  566.         // TODO: comment social links for now
  567.         /*
  568.         'facebook'    => 'test_facebook',
  569.         'linkedin'    => 'test_linkedin',
  570.         'tikTok'    => 'test_tiktok',
  571.         'instagram'    => 'test_insta',
  572.          // */
  573.         'D_CREATION'    => $d_creation_label 
  574.     );
  575.                 // echo(__METHOD__.' adding v_card....');
  576.         } else { // ENDIF isset found
  577.         return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  578.     } 
  579.     $comm_datas json_decode($student_datas['COMMENTAIRE'], true);
  580. //*    // TODO: enable social networks support
  581.     foreach ($this->SOCIAL_NETS as $net_item => $net_value) {
  582.         if (isset($comm_datas[$net_item])
  583.             && $comm_datas[$net_item] != ''
  584.         ) {
  585.             $vcard_datas['v_card'][$net_item] = $net_value.$comm_datas[$net_item];
  586.             $vcard_datas['v_datas_card'][$net_item] = $net_value.$comm_datas[$net_item];
  587.             $vcard_datas['v_card'][$net_item.'_url'] = $net_value.$comm_datas[$net_item];
  588.         }
  589.     }
  590. //*/
  591.     $vcard_datas['personnel_datas'] = array(
  592.         'PRENOM'=> $found['Prénom'],
  593.         'NOM'    => $found['Nom'],
  594.         'TEL_PRO'    => $found['Portable'],
  595.         'EMAIL_PRO'    => $user_email,
  596.     );
  597.     if (isset($comm_datas['role'])) {
  598.         $vcard_datas['personnel_datas']['ROLE'] = $comm_datas['role'];
  599.     }
  600.     $uri "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  601.     $uri .=(isset($_GET['email']) || isset($_GET['embedded']) ? '&' '?');
  602.         
  603.     $dwnl $uri 'download=1'.(isset($user_email) ? '&email='.$user_email '&email='.$personnel_datas['EMAIL_PRO']);
  604.     $vcard_datas['download_url'] = $dwnl;
  605.     $vcard_datas['qr_code_url'] = $this->generateQrCode($vcard_datas);
  606.     $vcard_datas['disp_vcard_student'] = true;
  607.     $vcard_datas['is_last'] = true;
  608.     $is_download = (    
  609.             (isset($_GET['download']) && $_GET['download'] == 1)
  610.             || (isset($_POST['download']) && $_POST['download'] == 1)
  611.             );
  612.     //*    // TODO: enable social links
  613.             foreach($this->SOCIAL_NETS as $net_item => $val) {
  614.                 if (isset($comm_datas[$net_item])
  615.                     && $comm_datas[$net_item] != ''
  616.                 ) {
  617.                     $vcard_datas['v_card'][$net_item] = $comm_datas[$net_item];
  618.                 }
  619.             }
  620.     //*/
  621.         $tpl_name = isset($_GET['embedded']) // ($_GET['v2']) 
  622.                 ?  'v_card_student/embedded.html.twig' 
  623.                 'v_card_student/last.html.twig';
  624.         if (isset($_GET['embedded'])
  625.             && isset($_GET['v4'])
  626.         ) {
  627.             $tpl_name =  'v_card_student/embedded_v4.html.twig'
  628.         }
  629.     $photo_file '/mnt/recadre/'.$ide_dossier.'.jpg';
  630.     // $photo_file = '/mnt/recadre/'.$ide_dossier.'.jpg';
  631.     if ($student_datas['AVEC_PHOTO'] == 'oui'
  632.         || (file_exists($this->uploadsDIR.('photo_'.$ide_dossier.'.jpg')))
  633.     ) {
  634.                 if ($student_datas['AVEC_PHOTO'] != 'oui') {
  635.                     $photo_file $this->uploadsDIR.('photo_'.$ide_dossier.'.jpg');
  636.                 }
  637.         $key $this->storeInSession($session$photo_file);
  638.         if (!empty($key)) {
  639.             $vcard_datas['PHOTO_K'] = $key;
  640.         }
  641.     }
  642. /*
  643.             // echo(__METHOD__.': '. var_export($last_vcard, true)); exit();
  644.             if (isset($student_datas['AVEC_PHOTO']) && $student_datas['AVEC_PHOTO'] == 'oui'
  645.                 || (file_exists($this->uploadsDIR.('photo_'.$ide_dossier.'.jpg')))
  646.             ) {
  647.                 if (!isset($last_vcard['AVEC_PHOTO']) || $last_vcard['AVEC_PHOTO'] != 'oui') {
  648.                     $photo_file = $this->uploadsDIR.('photo_'.$ide_dossier.'.jpg');
  649.                 }
  650.                 $key = $this->storeInSession($session, $photo_file);
  651.                 if (!empty($key)) {
  652.                     $vcard_datas['PHOTO_K'] = $key;
  653.                 }
  654.             }
  655.     //*/
  656.     if (isset($_GET['DBG'])) {
  657.         echo('<br/>'.__METHOD__.': user_email: '.$user_email);
  658.         echo('<br/>'.__METHOD__.': download_url: '.$vcard_datas['download_url']);
  659.     }
  660.         if ($is_download) {
  661.             $vcard_struct_datas $this->buildVCardFileStructure($user_email);
  662.             $vcard_datas array_merge($vcard_struct_datas$vcard_datas);
  663.             // echo(__METHOD__.': vcard_datas: '.var_export($vcard_datas, true));
  664.      $content $this->getVCardFileContent($vcard_datas, isset($_GET['DBG']));
  665.         $filename 'vcard_'.$ide_dossier.'.vcf';
  666.         // echo(__METHOD__.' content:'.$content); exit();
  667.              $logger->debug('Downloading QRCODE', [
  668.         // 'user_email' => $user_email,
  669.         'IP_ADDR'    => $_SERVER['REMOTE_ADDR'],
  670.                     ]);
  671.             return new Response($content200, array(
  672.                 //*
  673.                 'X-Sendfile'          => $filename,
  674.                 'Content-type'        => 'application/octet-stream',
  675.             'Content-Disposition' => sprintf('attachment; filename="%s"'$filename)
  676.             //*/
  677.             )
  678.         );
  679.     }
  680.     } else { // END if user_email
  681.             return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  682.     }
  683.     if (isset($_GET['DBG'])
  684.         && $tpl_name == 'v_card_student/last.html.twig'
  685.     ) {
  686.         echo(__METHOD__.': '.var_export($vcard_datastrue));
  687.     }
  688.     return $this->renderForm($tpl_name$vcard_datas);
  689.     }
  690.   /**
  691.      * @Route("/v/student/card/lastcardinfo", name="app_v_card_student_lastcardinfo", methods={"GET"})
  692.      */
  693.    public function lastcardinfo(Request $requestVCardRepository $vCardRepository): Response {
  694.     $content 'NOT FOUND';
  695.     $session $request->getSession();
  696.     $user_email $session->get('user_email');
  697.     $student_datas $this->getAllStudentDatas($user_email);
  698.     $found $this->selectLastVcardStudent($student_datas['id.Apprenant']);
  699.     $content __METHOD__.'<br/>'.var_export($foundtrue);
  700.     $content .= '<br/>'.var_export($student_datastrue);
  701.     return new Response($content200, array(
  702.                     )
  703.             );
  704.    }
  705.     /**
  706.      * @Route("/v/student/card/testvcardstruct", name="app_v_card_student_testvcardstruct", methods={"GET"})
  707.      */
  708.    public function testvcardstruct(Request $requestVCardRepository $vCardRepository): Response {
  709.     $datas $this->buildVCardFileStructure($_GET['email'], true);
  710.     $content __METHOD__.' datas: '.var_export($datastrue);
  711.     return new Response($content200, array(
  712.                     )
  713.             );
  714.     }
  715. protected function DEP_selectVcardStudentWhere($where '') {
  716.     $out null;
  717.     // $id_apprenant = isset($datas['id.Apprenant']) ? $datas['id.Apprenant'] : null;
  718.     if (isset($where)) {
  719.         $where ' where '.$where;
  720.     }
  721.         $query  'select * from  vcard_student'$where;
  722.         $found $this->selectRaw($query);
  723.         echo(__METHOD__.': query:'.var_export($querytrue));
  724.         if (count($found) > 0) {
  725.             // $found = $found[0];
  726.             if (isset($found[0]['ID_VCARD'])) {
  727.                 $out $found;
  728.             }
  729.         }
  730.     
  731.     return $out;
  732. }
  733. protected function buildVCardFileStructure($user_email$DBG false) {
  734.         $out = array();
  735.     $student_datas $this->getStudentDatasFromMail($user_email);
  736.     $out['v_datas_card'] = array(
  737.                     'NOM'     => $student_datas['Nom'],
  738.                     'PRENOM'=> $student_datas['Prénom'],
  739.                     'TITRE' => '["'.$student_datas['Fonction'].'"]',
  740.                     'EMAIL_PRO'    => $user_email,
  741.                     'EMAIL'    => $student_datas['emailPerso'],
  742.                     'TEL_PRO'    => '',
  743.                     'TEL'    => '["'.$student_datas['Portable'].'"]',
  744.                     'ADRESSE_PRO' => $this->getFromSite($student_datas['Campus']),
  745.                     'IDE_DOSSIER' => $student_datas['id.Apprenant'],
  746.                 );
  747.     $out['personnel_datas'] = array(
  748.                     'SERVICE' => $student_datas['Formation'],
  749.                 );
  750.     $out array_merge($out$this->getAllStudentDatas($user_email));
  751.     if ($DBG !== false) {
  752.         echo(__METHOD__.' out: 'var_export($outtrue));
  753.     }
  754.         return $out;
  755.     }
  756. protected function selectLastVcardStudent($id_apprenant) {
  757.     $out null;
  758.     // $id_apprenant = isset($datas['id.Apprenant']) ? $datas['id.Apprenant'] : null;
  759.     if (isset($id_apprenant)) {
  760.         $query  'select * from  vcard_student where id_apprenant = '$id_apprenant .' order by id_vcard desc fetch first 1 rows only';
  761.         $found $this->selectRaw($query);
  762.         // echo(__METHOD__.': found:'.var_export($found, true));
  763.         if (count($found) > 0) {
  764.             $found $found[0];
  765.             if (isset($found['ID_VCARD'])) {
  766.                 $out $found;
  767.             }
  768.         }
  769.     }
  770.     return $out;
  771. }
  772. protected function addStudentOptFields($datas) {
  773.     $out $datas;
  774.     $add_fields = array(
  775.         'Formation'
  776.     );
  777.     $add_fields array_merge($add_fieldsarray_keys($this->SOCIAL_NETS));
  778.     if (isset($datas['COMMENTAIRE'])) {
  779.         $tmp_val json_decode($datas['COMMENTAIRE'], true);
  780.     
  781.         foreach($add_fields as $k => $item) {
  782.             if (isset($tmp_val[$item])) {
  783.                 $out[$item] = $tmp_val[$item]; 
  784.             }
  785.         }
  786.     }
  787.     return $out;
  788. }
  789. protected function getAllStudentDatas($user_email$DBG false) {
  790.     $out = array();
  791.     if (isset($user_email)) {
  792.         $found $this->getStudentDatasFromMail($user_email);
  793.         if (isset($found)) {
  794.             $student_datas = array(
  795.                 'avecphoto'    => 'non',
  796.                 'tel2'        => '',
  797.             );
  798.             $student_datas array_merge($found$student_datas);
  799.             $student_datas['titre'] = $found['Fonction'];
  800.             $student_datas['tel']    = $found['Portable'];
  801.             $student_datas['emailPerso']    = $found['emailPerso'];
  802.             $student_datas['ADRESSE_PRO']     = $this->getFromSite($found['Campus']);
  803.             $db_datas $this->selectLastVcardStudent($found['id.Apprenant']);
  804.             if (isset($db_datas['ID_VCARD']) 
  805.             ) {
  806.                 $tmp_val json_decode($db_datas['EMAIL'], true);
  807.                 if (count($tmp_val) > 1) {
  808.                     $student_datas['emailPerso'] = $tmp_val[1];
  809.                 } 
  810.                 $tmp_val json_decode($db_datas['TEL'], true);
  811.                 if (count($tmp_val) > 0) {
  812.                     $student_datas['tel'] = '0' substr($tmp_val[0], 3);
  813.                     if (isset($tmp_val[1])) {
  814.                         $student_datas['tel2'] = '0' substr($tmp_val[1], 3);
  815.                     }
  816.                 }
  817.                 if ($db_datas['AVEC_PHOTO'] == 'oui') {
  818.                     $student_datas['avecphoto'] = $db_datas['AVEC_PHOTO'];
  819.                 }
  820.                 $student_datas array_merge($student_datas$this->addStudentOptFields($db_datas));
  821.             }
  822.             $student_datas['avec_photo'] = $student_datas['avecphoto'];
  823.             $out $student_datas;
  824.             if ($DBG !== false) {
  825.                 echo(__METHOD__.' out:'var_export($outtrue));
  826.             }
  827.         }
  828.     }
  829.     return $out;
  830. }
  831.     /**
  832.      * @Route("/v/student/card/new", name="app_v_card_student_new", methods={"GET", "POST"})
  833.      */
  834. public function new(Request $requestVCardRepository $vCardRepository): Response {
  835.     $session $request->getSession();
  836.     $this->checkAuth($session'app_v_card_student_new');
  837.     $user_email $session->get('user_email'); // $_GET['email'];
  838.     $is_auth $session->get('is_auth');
  839.     $DBG // true ||    // TODO: remove true 
  840.         isset($_GET['DBG']) && $_GET['DBG'] == '1';
  841.     $student_datas = array(
  842.         'avecphoto'    => 'non',
  843.         'tel2'        => '',
  844.             );
  845.     $comm_datas = array();
  846.     $url "https://{$_SERVER['HTTP_HOST']}/v/student/card/last?";
  847.     if (!isset($user_email)) {
  848.             return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  849.     }
  850.     if (isset($user_email)
  851.         && $is_auth
  852.     ) {
  853.         $db_datas $this->getAllStudentDatas($user_email);
  854.         if (isset($db_datas['ID_VCARD'])) { // NOTE: card exists in DB
  855.                 return $this->redirectToRoute('app_v_card_student_edit', [], Response::HTTP_SEE_OTHER);
  856.         }
  857.         //*
  858.         $found $this->getStudentDatasFromMail($user_email$DBG);
  859.         if (isset($found)) {
  860.             $student_datas['titre'] = $found['Fonction'];
  861.             $student_datas['tel']    = $found['Portable'];
  862.             $student_datas['Nom']     = $found['Nom'];
  863.             $student_datas['Prénom']    = $found['Prénom'];
  864.             $student_datas['Campus']    = $found['Campus'];
  865.             $student_datas['ADRESSE_PRO']    = $this->getFromSite($student_datas['Campus']);
  866.             $student_datas['emailPerso']    = $found['emailPerso'];
  867.             $student_datas['id.Apprenant']    = $found['id.Apprenant'];
  868.             $student_datas['Formation']    = $found['Formation'];
  869.             $student_datas['VERSION']    = 0;
  870.         //*/
  871.         // $student_datas = $this->getAllStudentDatas($user_email, $DBG);
  872.             
  873.             $vCardStudent = new VCardStudent(); 
  874.             $form $this->createForm(VCardStudentType::class, $vCardStudent);
  875.             $form->handleRequest($request);
  876.             if ($form->isSubmitted() && $form->isValid()) {
  877.                 $datas $form->getData();
  878.                 $tmp_comms = array();
  879.                 $comm_datas['date_expiration']    = $found['date_expiration'];
  880.                 $comm_datas['login']    = $found['login.Individu'];
  881.                 $datas->setid_apprenant($student_datas['id.Apprenant']);
  882.                 $datas->setformation($student_datas['Formation']);
  883.                 $datas->setVERSION(sprintf("%d"$student_datas['VERSION']) + 1);
  884.                 // NOTE: getting titre opt used for storing role
  885.                 $titre_datas json_decode($datas->gettitre(), true);
  886.                 if (isset($titre_datas[1])) {
  887.                     $comm_datas['role'] = $titre_datas[1];
  888.                 }
  889.                 $form_comment $datas->getcommentaire();
  890.                 if (isset($form_comment)) {
  891.                     $tmp_comms json_decode($form_commenttrue);
  892.                     $comm_datas array_merge($comm_datas$tmp_comms);    
  893.                 }
  894.                 if (isset($found['date_expiration'])) {
  895.                     $datas->setcommentaire(json_encode($comm_datas));
  896.                 }
  897.                 // echo(__METHOD__.': '.var_export($datas->gettitre(), true));
  898.                 // echo(__METHOD__.': '. var_export($datas, true));
  899.                 if (false !== $this->addVCardStudent($datas)) { // , true)) { // TODO: REMOVE true !!!!!
  900.                     $this->generateQrCodeFile($url$user_email);
  901.                     return $this->redirectToRoute('app_v_card_student_show', [], Response::HTTP_SEE_OTHER);
  902.                 } else {
  903.                     echo(__METHOD__' addVCardStudent FAILURE: datas: '.var_export($datastrue)); exit();    
  904.                 }
  905.             }
  906.         } else { // END if found
  907.             return $this->redirectToRoute('app_v_card_student_notfound', [], Response::HTTP_SEE_OTHER);
  908.         }
  909.     } // END if user_email
  910.         return $this->renderForm('v_card_student/new.html.twig', [
  911.             // 'v_card' => $vCard,
  912.             'user_email' => $user_email,
  913.             // 'personnel'    => $personnel_datas,
  914.             'student'    => $student_datas,
  915.             'is_new'    => true,
  916.             'disp_form_student'    => true,
  917.             // 'is_manager'    => $session->get('is_manager'),
  918.             'form' => $form,
  919.         ]);
  920.     }
  921. protected function addVCardStudent(VCardStudent $datas$TEST_MODE false) {
  922.     // INSERT INTO "EASYID"."VCARD_STUDENT" (ID_VCARD, ID_APPRENANT, FORMATION, EMAIL, TEL, STATUT, COMMENTAIRE, VERSION, AVEC_PHOTO) VALUES ('1', '1234', 'TEST_FORMATION', 'email@test.com', '[""]', 'enregistrée', '{}', '1', 'non')
  923.         $out false;
  924.         if (isset($datas)) {
  925.             $query 'INSERT INTO "EASYID"."VCARD_STUDENT" (ID_VCARD, ID_APPRENANT, FORMATION, EMAIL, TEL, STATUT, COMMENTAIRE, VERSION, AVEC_PHOTO, D_CREATION) VALUES (:ID_VCARD, :ID_APPRENANT, :FORMATION, :EMAIL, :TEL, :STATUT, :COMMENTAIRE, :VERSION, :AVEC_PHOTO, CURRENT_DATE)';
  926.             $tmp_id $this->getNewStudentVCardId(); // $datas->getId();
  927.             if (!isset($tmp_id)) {
  928.                 $tmp_id $this->getNewStudentVCardId($TEST_MODE);
  929.                 $datas->setid_vcard($tmp_id);
  930.             }
  931.             $version  $datas->getversion();
  932.             $version = ((int) $version) + 1;
  933.             $version $this->getNewStudentVersion($datas->getid_apprenant());
  934.             $commentaire_datas $datas->getcommentaire();
  935.             if (!isset($commentaire_datas)) {
  936.                 $commentaire_datas '{}';
  937.             };
  938.             $avec_photo $datas->getavecphoto();
  939.             if ($avec_photo != 'oui') {
  940.                 $avec_photo 'non';
  941.             }
  942.             $values = array(
  943.             'ID_VCARD'    => $tmp_id,
  944.             'ID_APPRENANT'    => $datas->getid_apprenant(),
  945.             'FORMATION'    => $datas->getformation(),
  946.             'EMAIL'        => $datas->getemail(),
  947.             'TEL'        => $datas->gettel(),
  948.             'STATUT'    => $datas->getstatut(),
  949.             'COMMENTAIRE'    => $commentaire_datas,
  950.             'VERSION'    => $version,
  951.             'AVEC_PHOTO'    => $avec_photo 
  952.             );
  953.         // $tmp_datas[] = $datas[];
  954.         if ($TEST_MODE) {
  955.             echo(__METHOD__.': SQL:' $query '<br/>' var_export($valuestrue));
  956.         }
  957.         $out $this->writeRaw($query$values$TEST_MODE);
  958.         }
  959.         return $out;
  960.     }
  961.     /**
  962.      * @Route("/v/student/card/setuser", name="app_v_card_student_setuser", methods={"GET", "POST"})
  963.      */
  964.     public function setuser(Request $request): Response {
  965.         $session $request->getSession();
  966.     $session->set('is_auth'true);
  967.     $session->set('user_email'$_GET['email']);
  968.         $content __METHOD__.': session:'.var_export($sessiontrue);
  969.     return new Response($content200, array(
  970.             'Content-type'        => 'text/html'
  971.         )
  972.     );
  973.         
  974.     }
  975.     /**
  976.      * @Route("/v/student/card/logout", name="app_v_card_student_logout", methods={"GET", "POST"})
  977.      */
  978.     public function logout(Request $request): Response {
  979.         $session $request->getSession();
  980.         $session->set('is_auth'false);
  981.         $session->set('user_email'null);
  982.         $content __METHOD__.': LOGGED_OUT';
  983.     return new Response($content200, array(
  984.             'Content-type'        => 'text/html'
  985.         )
  986.     );
  987.     }
  988.     /**
  989.      * @Route("/v/student/card/userinfo", name="app_v_card_student_userinfo", methods={"GET", "POST"})
  990.      */
  991.     public function userinfo(Request $request): Response {
  992.         $session $request->getSession();
  993.         $user $session->get('user_email');
  994.         $content __METHOD__.': session:'.var_export($sessiontrue);
  995.         $content .= ' user: ' $user;
  996.         $content .= '<br/>'.var_export($this->getStudentDatasFromMail($user), true);
  997.     return new Response($content200, array(
  998.             'Content-type'        => 'text/html'
  999.         )
  1000.     );
  1001.         
  1002.     }
  1003.     /**
  1004.      * @Route("/v/student/card/uploadres", name="app_v_card_student_uploadres", methods={"GET", "POST"})
  1005.      */
  1006.     public function uploadres(Request $requestVCardRepository $vCardRepository): Response
  1007.     {
  1008.         $session $request->getSession();
  1009.         /*
  1010.     $is_auth = $session->get('is_auth');
  1011.         //*/
  1012.         $is_auth true;
  1013.     if (!$is_auth) {
  1014.         $session->set('previous''app_v_card_student_show');
  1015.         // $session->set('prev_id', $vCard->getId());
  1016.         return new Response(null302, array(
  1017.                 'Location'        => 'auth',
  1018.         ));
  1019.     } else {
  1020.     $user_email $session->get('user_email');
  1021.     $personnel_datas $this->getAllStudentDatas($user_email); // getPersonnelFromEnv($session);
  1022.     $ide_dossier 'E-'.$personnel_datas['id.Apprenant'];
  1023.     /*
  1024.     $filename = '/mnt/recadre/E-94824323.jpg';
  1025.     $target_dir = 'public/uploads/';
  1026.     if (!isset($_GET['key'])) {
  1027.         $key = $this->storeInSession($session, $filename);
  1028.         // echo(__METHOD__.': key: '.$key);
  1029.     } else {
  1030.         $val = $session->get($_GET['key']);
  1031.         echo(__METHOD__.': val: '.$val);
  1032.     }
  1033.     // exit();
  1034.     //
  1035.     //
  1036.     */
  1037.     if (isset($_FILES['fileToUpload']['name'])) { // (isset($_POST['submit']))
  1038.         $file_out $this->uploadFile('photo_'.$ide_dossier.'.jpg');
  1039.         $file_path __DIR__.'/../../public'.$file_out;
  1040.         // echo(__METHOD__.': file_out: '.$file_path);
  1041.         $key $this->storeInSession($session$file_path);
  1042.         $del_key $this->storeInSession($session$file_path);
  1043.         $data_out = array(
  1044.                     'src' => '/v/card/photo?rel='.$key,
  1045.                     'del_key' => $del_key,
  1046.                 );
  1047.         $content json_encode($data_out); 
  1048.         // $content = 'Done.';
  1049.     return new Response($content200, array(
  1050.             'Content-type'        => 'text/html'
  1051.         )
  1052.     );
  1053.     } else if (!empty($_GET['remove'])){
  1054.         $datas = array();
  1055.         $datas['status'] = $this->deleteUploadedFile($_GET['remove']);
  1056.         $content json_encode($datas);
  1057.         return new Response($content200, array(
  1058.             'Content-type'        => 'text/html'
  1059.         ));
  1060.     
  1061.     } else {
  1062.         return $this->render('v_card/upload.html.twig', []); 
  1063.     }
  1064.     } // END else not auth
  1065.     }
  1066.     /**
  1067.      * @Route("/v/student/card/photo", name="app_v_card_student_photo", methods={"GET", "POST"})
  1068.      */
  1069.     public function photo(Request $requestVCardRepository $vCardRepository): Response
  1070.     {
  1071.     $params array_merge($_GET$_POST);
  1072.     $session $request->getSession();
  1073.     // $is_auth = $session->get('is_auth');
  1074.     $img_filename $this->retrieveFromSession($session$params['rel']); // $session->get($params['rel']);
  1075.     $content = (isset($params['rel']) && !empty($params['rel']) && isset($img_filename)) ? file_get_contents($img_filename) : '';
  1076.     return new Response($content200, array(
  1077.             'Content-type'        => 'image/jpeg'
  1078.         )
  1079.     );
  1080.     }
  1081.     /**
  1082.      * @Route("/v/student/card/testbound", name="app_v_studentcard_testbound")
  1083.      */
  1084.     public function testbound(): Response {
  1085.         echo(__METHOD__.': '$this->writeRaw('insert into ma_table values(?, ?, ?, ?)',['un''deuz''3'4])); exit(); 
  1086.     }
  1087.     /**
  1088.      * @Route("/v/student/card/sonsbeurk", name="app_v_card_student_sonsbeurk")
  1089.      */
  1090. public function sonsbeurk(): Response {
  1091.         $tmp_card = (new VCardFile());
  1092.         $test_datas = array(
  1093.                     'v_datas_card' => array(
  1094.                                     'linkedin' => 'https://my_linked_in_URL'
  1095.                                 )
  1096.                 );
  1097.         $this->addVcardOptionalFields($tmp_card$test_datas);
  1098.         echo(__METHOD__.'tmp_vard: ' $tmp_card->getOutput());
  1099.         $this->beurk(); exit(); 
  1100.     }
  1101. protected function addVcardSocialFields(VCardFile $vcard$datas) {
  1102.     $out $vcard;
  1103.     // $lastname = $datas['v_datas_card']['NOM'];
  1104.     if (isset($datas)
  1105.         && isset($datas['v_datas_card'])
  1106.     ) {
  1107.         $field_type 'linkedin';
  1108.         if (isset($datas['v_datas_card'][$field_type])) {
  1109.             $vcard->addURL($datas['v_datas_card'][$field_type], $field_type);
  1110.         }
  1111.     }
  1112.         echo(__METHOD__.' vcard: '.var_export($vcardtrue). '<br/>datas:' var_export($datastrue));
  1113.     return $out;
  1114. }
  1115.     public function generateQrCodeFile($uri$email ''$prefix 'QRC') {
  1116.         // $uri = "https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
  1117.     // $uri .=(isset($_GET['email']) || isset($_GET['embedded']) ? '&' : '?');
  1118.         
  1119.         $dwnl $uri 'download=1&email='.$email;
  1120.         $DBG = isset($_GET['DBG']);
  1121.         if (!is_null($uri)
  1122.             && !is_null($email)
  1123.         ) {
  1124.         $student_datas $this->getAllStudentDatas($email);
  1125.         // TODO: write to file
  1126.         /*
  1127.          $vcard = $this->getVCardFromEmail($email);
  1128.         if ($DBG) {
  1129.             echo(__METHOD__.': vcard: '. var_export($vcard, true));
  1130.         }
  1131.         // */
  1132.         if (isset($student_datas['id.Apprenant'])) {
  1133.             $ide_dossier 'E-'.$student_datas['id.Apprenant'];
  1134.             $filename $ide_dossier.'.JPG';
  1135.             $filesystem = new Filesystem();
  1136.             try {
  1137.                 $filename Path::normalize('/mnt/qrcode/'
  1138.                     // .'TEST__' // TEST ONLY
  1139.                     .$prefix.$filename
  1140.                 ); // sys_get_temp_dir().'/'. $filename);
  1141.                 if (!$this->isNewQRCode($filename)) {
  1142.                     if (file_exists($filename)) {
  1143.                         rename($filename$filename.'.OLD'); // NOTE: backup old version
  1144.                     }
  1145.                     $options = new QROptions([
  1146.                         'version'         => 5,
  1147.                         'eccLevel'        => QRCode::ECC_L,
  1148.                         'scale'     => 6,                     // 275x275
  1149.                         'outputType'      => QRCode::OUTPUT_IMAGE_JPG,
  1150.                         'imageTransparent' => false,
  1151.                     ]);
  1152. // echo(strpos(file('/mnt/qrcode/TEST__QRC5474.jpg')[0], 'CREATOR'));
  1153.                     $content = (new QRCode($options))->render($dwnl$filename);
  1154. /*            $filesystem->appendToFile(
  1155.             $filename, $content, true
  1156.             );
  1157.                  */
  1158.         if ($DBG) {
  1159.             echo(__METHOD__.': dwnl:'.$dwnl.'<br/>File: '.$filename);
  1160.         }
  1161.                 } else {
  1162.         if ($DBG) {
  1163.             echo(__METHOD__.': filename: '.$filename.' already updated....');
  1164.         }
  1165.                 }
  1166.             } catch (IOExceptionInterface $exception) {
  1167.                 echo "An error occurred while creating your directory at ".$exception->getPath();
  1168.             }
  1169.         } // END if IDE_DOSSIER
  1170.     }
  1171.     }
  1172.     /**
  1173.      * @Route("/v/student/card/testcreate", name="app_v_card_student_testcreate", methods={"GET", "POST"})
  1174.      */
  1175.     public function testcreate(Request $requestVCardRepository $vCardRepository): Response {
  1176.         $content 'NOT_FOUND';
  1177.     /*
  1178.         $new_id = $this->getNewStudentVCardId();
  1179.         $content = __METHOD__.': new_id: '. $new_id;
  1180.     //*/
  1181.         echo(__METHOD__.': POST: '.var_export($_POSTtrue));
  1182.         if ( isset($_POST['v_card']['id_etudiant'])
  1183. //            && isset($_POST['v_card']['email'])
  1184. //            && isset($_POST['v_card']['titre'])
  1185. //            && isset($_POST['v_card']['tel'])
  1186. //            && isset($_POST['v_card']['commentaire'])
  1187. //            && isset($_POST['v_card']['avecphoto'])
  1188.         ) {
  1189.             $content __METHOD__.' datas: '.$_POST['v_card']['id_etudiant'];
  1190.         }
  1191.     return new Response($content200, array(
  1192.                     )
  1193.             );
  1194.     }
  1195.     /**
  1196.      * @Route("/v/student/card/getcachedate", name="app_v_card_student__getcachedate", methods={"GET"})
  1197.      */
  1198.     public function getcachedate(Request $requestVCardRepository $vCardRepository): Response {
  1199.         $content 'NOT_FOUND';
  1200.         $js_datas = array();
  1201.         $found $this->getStudentDatasById('CREATED');
  1202.         $content = isset($found) ? $found 'NOT_FOUND';
  1203.     return new Response($content200, array(
  1204.                     )
  1205.             );
  1206.     
  1207.     }
  1208.     /**
  1209.      * @Route("/v/student/card/getdatasbymail", name="app_v_card_student__getdatasbymail", methods={"GET"})
  1210.      */
  1211.     public function getdatasbymail(Request $requestVCardRepository $vCardRepository): Response {
  1212.         $content 'NOT_FOUND';
  1213.         $js_datas = array();
  1214.         /*
  1215.     if (isset($_GET['email'])) {
  1216.         $file_datas = file_get_contents($this->studentsCacheFile);
  1217.         if (isset($file_datas)) {
  1218.             $js_datas = json_decode($file_datas, true);
  1219.             if (count($js_datas) > 0
  1220.             ) {
  1221.                 $js_datas = $js_datas[$_GET['email']];
  1222.                 if (isset($js_datas['email'])) {
  1223.                     $content = json_encode($js_datas);
  1224.                 }
  1225.             }
  1226.         }
  1227.     }
  1228.      */
  1229.         $found $this->getStudentDatasFromMail($_GET['email']);
  1230.         $content = isset($found) ? json_encode($found) : 'NOT_FOUND';
  1231.     return new Response($content200, array(
  1232.                     )
  1233.             );
  1234.     }
  1235.     /**
  1236.      * @Route("/v/student/card/refreshstudentsfile", name="app_v_studentcard_refreshstudentsfile", methods={"GET"})
  1237.      */
  1238.     public function refreshstudentsfile(Request $requestVCardRepository $vCardRepository): Response {
  1239.     $content 'KO';
  1240.         $cache_date = (file_exists($this->studentsCacheFile)) ? $this->getStudentDatasById('CREATED') : 0;
  1241.         if (isset($cache_date)) {
  1242.             $content $cache_date;
  1243.         $timestamp_now date_timestamp_get(date_create());
  1244.         $duration $timestamp_now - ((int) $cache_date);
  1245.         if ($duration $this->CACHE_DURATION) {
  1246.             $datas $this->getStudentDatasFromServer();
  1247.             if (isset($datas['CREATED'])) {
  1248.                 $content $datas['CREATED'];
  1249.             }
  1250.         }
  1251.             if (isset($_GET['DBG'])) {
  1252.                 $content .= ' delta:' .$duration;
  1253.             }
  1254.         }
  1255.     return new Response($content200, array(
  1256.                     )
  1257.             );
  1258.     }
  1259.     public function getStudentDatasFromServer($DBG false) {
  1260.         $out false;
  1261.         $client = new CurlHttpClient();
  1262.         // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  1263. // $client->AllowSelfSignedCertificate();
  1264. $response $client->request('GET'$this->studentsFileURL, [
  1265.     // ...
  1266.     "verify_peer"=>false,
  1267.     "verify_host"=>false,
  1268.     'extra' => [
  1269.         'curl' => [
  1270.             CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
  1271.         ],
  1272.     ],
  1273. ]);
  1274.         $content $response->getContent();
  1275.         $datas json_decode($contenttrue);
  1276.         $students_datas = array();
  1277.         foreach($datas as $k => $data_line) {
  1278.             if (isset($data_line['email'])) {
  1279.                 $students_datas[$data_line['email']] = $data_line;
  1280.             }
  1281.         }
  1282.         if (count($students_datas) > 1) {
  1283.             $students_datas['CREATED'] = date_timestamp_get(date_create());
  1284.             file_put_contents($this->studentsCacheFilejson_encode($students_datas));
  1285.             $out $students_datas['CREATED'];
  1286.         }
  1287.         if ($DBG !== false) {
  1288.         echo(__METHOD__' Response: ' var_export($students_datastrue)); exit();
  1289.         }
  1290.         return $out;
  1291.     }
  1292.     /**
  1293.      * @Route("/v/student/card/testSQL", name="app_v_card_student_testSQL", methods={"GET"})
  1294.      */
  1295.         public function testSQL(Request $requestVCardRepository $vCardRepository): Response {
  1296.             //*
  1297.         $query "INSERT INTO \"EASYID\".\"VCARD_STUDENT\" (ID_VCARD, ID_APPRENANT, FORMATION, EMAIL, TEL, STATUT, COMMENTAIRE, VERSION, AVEC_PHOTO) VALUES (:ID_VCARD, :ID_APPRENANT, :FORMATION, :EMAIL, :TEL, :STATUT, :COMMENTAIRE, :VERSION, :AVEC_PHOTO)";
  1298.         
  1299.         $result $this->writeRaw($query, array(
  1300.                 'ID_VCARD'     => 2
  1301.             'ID_APPRENANT'     => 1234,
  1302.             'FORMATION'    => 'TEST_FORMATION',
  1303.             'EMAIL'        => 'email@test.com'
  1304.             'TEL'        => '[\"\"]',
  1305.             'STATUT'    => 'enregistrée'
  1306.             'COMMENTAIRE'    => '{}'
  1307.             'VERSION'    => '1'
  1308.             'AVEC_PHOTO'    => 'non'
  1309.             )
  1310.         );
  1311.      // */
  1312.         /*
  1313.         $query = 'select id_vcard,email from vcard_student where id_apprenant = :id_apprenant';
  1314.         $result = $this->writeRaw($query, array(
  1315.                             'id_apprenant'    => 1234
  1316.                         )
  1317.         );
  1318.      */
  1319.     $content __METHOD__.' result: '.$result;
  1320.     return new Response($content200, array(
  1321.                     )
  1322.             );
  1323.     }
  1324.     /**
  1325.      * @Route("/v/student/card/testcurl", name="app_v_card_student_testcurl", methods={"GET"})
  1326.      */
  1327.     public function testcurl(Request $requestVCardRepository $vCardRepository): Response {
  1328. $client = new CurlHttpClient();
  1329. $response $client->request('GET''https://www.google.com', [
  1330.     // ...
  1331.     'extra' => [
  1332.         'curl' => [
  1333.             CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
  1334.         ],
  1335.     ],
  1336. ]);
  1337.     $content $response->getContent();
  1338.     echo(__METHOD__' Response: ' .$content); exit();
  1339.     }
  1340.     /**
  1341.      * @Route("/studentindex", name="app_v_card_student_index", methods={"GET"})
  1342.     public function index(Request $request, VCardRepository $vCardRepository): Response
  1343.     {
  1344.        
  1345.     $session = $request->getSession();
  1346.     $is_auth = $session->get('is_auth');
  1347.     $user_email = $session->get('user_email');
  1348.     print(__METHOD__.' session: '.var_export($session, true).'<br/>'); exit();
  1349.     if (!$is_auth) {
  1350.         $session->set('previous', 'app_v_card_index');
  1351.         return new Response(null, 302, array(
  1352.                 'Location'        => '/v/card/auth',
  1353.         ));
  1354.     } else if (isset($_GET['admin']) && $_GET['admin'] == 1) {
  1355.     // echo(__METHOD__.': user_mail:'.var_export($user_email, true)); exit();
  1356.         return $this->render('v_card/index.html.twig', [
  1357.             'v_cards' => $vCardRepository->findAll(),
  1358.     ]);
  1359.     } else {
  1360.         $content = __METHOD__.': user not found...';
  1361.         $personnel_datas = $this->getPersonnelFromEnv($session);
  1362.         $is_manager = $session->get('is_manager'); // $this->isManager($personnel_datas, $session);
  1363.         // echo(__METHOD__.': personnel_datas: '.var_export($personnel_datas, true)); exit();
  1364.         if (isset($personnel_datas['IDE_DOSSIER'])) {
  1365.             $ide_dossier = $personnel_datas['IDE_DOSSIER'];
  1366.             $last_card = $this->getRecentVCardByIdeDossier($ide_dossier);
  1367.             // $content = var_export($last_card, true);
  1368.             if (isset($last_card['IDE_DOSSIER'])) {
  1369.                     return $this->redirectToRoute('app_v_card_student_show', ['id_vcard' => $last_card['ID_VCARD']], Response::HTTP_SEE_OTHER);
  1370.             } else {
  1371.                         return $this->redirectToRoute('app_v_card_student_new', [], Response::HTTP_SEE_OTHER);
  1372.             }
  1373.         }
  1374.         return new Response($content, 200, array(
  1375.                     )
  1376.             );
  1377.     }
  1378.     }
  1379.      */
  1380. }