src/VcaBundle/Controller/DossierUserController.php line 569

Open in your IDE?
  1. <?php
  2. namespace VcaBundle\Controller;
  3. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use VcaBundle\Entity\Doc;
  9. use VcaBundle\Entity\DossierUser;
  10. use VcaBundle\Entity\Thematique;
  11. use \ZipArchive;
  12. use Symfony\Component\HttpFoundation\Session\Session;
  13. ini_set("memory_limit""-1");
  14. class DossierUserController extends Controller
  15. {
  16.     public function preExecute()
  17.     {
  18.         @UsersController::securityAction();
  19.     }
  20.     /**
  21.      * Displays all the files (DossierUser entities) owned by a user and processes the add of a new DossierUser
  22.      *
  23.      * @Route("/admin/monedp", name="admin_monedp")
  24.      */
  25.     public function monedpAction(Request $request)
  26.     {
  27.         $thematique NULL;
  28.         
  29.         if ($request->isMethod('POST')) {
  30.             $this->createDossier();
  31.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  32.         }
  33.         $em $this->getDoctrine()->getManager();
  34.         $session = new Session();
  35.         
  36.         $userId $session->get('userIdFairdoc');
  37.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  38.         if (!isset($user)){
  39.             return $this->redirect($this->getParameter('baseDir'));
  40.         }
  41.         
  42.         $lecteur $em->getRepository('VcaBundle:Users')->findOneBy(array('userLecteur' => true));
  43.         
  44.         $allKey = array();
  45.         if ($user->getUserChefdoc()){
  46.             $nodess trim($user->getUserThemes());
  47.             $nodesss substr($nodess0, -1);
  48.             $nodesId substr($nodesss1);
  49.             $exp explode(";"$nodesId);
  50.             
  51.             $list "";
  52.             $i 0;
  53.             foreach ($exp as $n) {
  54.                 
  55.                 if ($n != null && $n !== "" && $n != " ") {
  56.                     if ($i == 0) {
  57.                         $list .= $this->getTree($n);
  58.                     } else {
  59.                         $list .= ','.$this->getTree($n);
  60.                     }
  61.                     
  62.                 }
  63.                 $i++;
  64.             }
  65.             
  66.             $allKey explode(','$list);
  67.         }
  68.         
  69.         $dossiers $em->getRepository('VcaBundle:DossierUser')->findBy(array('dosPhoto' => false), array('id' => 'DESC'));
  70.         $index $user->getUserTheme();
  71.         //$thematiques = $em->getRepository('VcaBundle:Thematique')->findAll(array(), array('theme_value' => 'ASC'));
  72.         
  73.         $req " ";
  74.         if (!$session->get('isRealAdminFairdoc')) {
  75.             $nodess trim($user->getUserLisible());
  76.             $nodesss substr($nodess0, -1);
  77.             $nodesId substr($nodesss1);
  78.             $exp explode(";"$nodesId);
  79.             $list "";
  80.             $i 0;
  81.             foreach ($exp as $n) {
  82.                 
  83.                 if ($n != null && $n !== "" && $n != " ") {
  84.                     if ($i == 0) {
  85.                         $list .= $this->getTree($n);
  86.                     } else {
  87.                         $list .= ','.$this->getTree($n);
  88.                     }
  89.                     
  90.                 }
  91.                 $i++;
  92.             }
  93.                         
  94.             $req " AND theme_id IN ($list) ";
  95.         }
  96.         $query "SELECT theme_id, theme_value, theme_parent FROM thematique WHERE 1=1 $req ORDER BY theme_value ASC ";
  97.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  98.       
  99.         $thematiques $db->fetchAll($query);
  100.         
  101.         $query "select distinct mc.motcle_id, mc.motcle_value,
  102.                 (select count(dmc.dos_id) from dossier_motcle WHERE motcle_id = mc.motcle_id group by motcle_id) as count
  103.                 from motcle mc
  104.                 LEFT join dossier_motcle dmc ON dmc.motcle_id = mc.motcle_id
  105.                 group by mc.motcle_id";
  106.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  107.       
  108.         $mots $db->fetchAll($query);
  109.         //$mots = $em->getRepository('VcaBundle:Motcle')->findBy(array(), array('motcleValue' => 'ASC'));
  110.         if ($session->get('isRealAdminFairdoc')){
  111.             $index null;
  112.         }
  113.         $query "select distinct(doc_type) from document_user du 
  114.             JOIN dossier_document dd ON dd.doc_id = du.doc_id
  115.             JOIN dossier_user dou ON dou.dos_id = dd.dos_id
  116.             WHERE dou.dos_photo is false Order by doc_type asc";
  117.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  118.       
  119.         $extensions $db->fetchAll($query);
  120.          
  121.         $docs = array();
  122.         $nbDocs = array();
  123.         foreach ($dossiers as $key => $dos){
  124.             $docs[] = $dos->getDosDocs();
  125.             $nbDocs[] = count(end($docs));
  126.         }
  127.         $dossiers array_values($dossiers);
  128.         $types $em->getRepository('VcaBundle:DataUserType')->findAll();
  129.         $year = array();
  130.         for ($i date("Y"); $i >= 1970$i--) {
  131.             $year[] = $i;
  132.         }
  133.         
  134.         $arbre $this->buildTree($thematiques);
  135.         usort($arbre, function($a$b) {
  136.             return $a['text'] <=> $b['text'];
  137.         });
  138.         $debut=array();
  139.         $debut["text"] = "Tous les répertoires";
  140.         $debut["id"] = 0;
  141.         array_unshift($arbre$debut);
  142.         //var_dump($arbre);exit;
  143.         return $this->render('document/myedp.html.twig', array(
  144.             'dossiers' => $dossiers,
  145.             'nbDocs' => $nbDocs,
  146.             'docs' => $docs,
  147.             'types' => $types,
  148.             'user' => $user,
  149.             'year' => $year,
  150.             'index' => $index,
  151.             'arbre' => $arbre,
  152.             'allKey' => $allKey,
  153.             'lecteur' => $lecteur,
  154.             'mots' => $mots,
  155.             'extensions' => $extensions,
  156.             'node' => null,
  157.             'thematique' => $thematique,
  158.             'thematiques' => $thematiques,
  159.             'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
  160.         ));
  161.     }
  162.     
  163.     /**
  164.      *
  165.      * @Route("/admin/monedploadajax", name="edp_loadajax")
  166.      */
  167.     public function monedploadajaxAction(Request $request)
  168.     {
  169.         $session = new Session();
  170.         
  171.         $userId $session->get('userIdFairdoc');
  172.         $em $this->getDoctrine()->getManager();
  173.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  174.          
  175.         $lecture " AND du.dos_hidden = false";
  176.         if ($user->getUserHidden() || $user->getUserAdmin()){
  177.             $lecture " ";
  178.         }
  179.         $repId=$motReq=$motleft=null;
  180.         $em $this->getDoctrine()->getManager();
  181.         $lecteur $em->getRepository('VcaBundle:Users')->findOneBy(array('userLecteur' => true));
  182.         if (isset($_GET["id"]) && $_GET["id"] != 0){
  183.             $repId $this->getTree($_GET["id"]);
  184.             
  185.             $repId ' AND dt.theme_id IN ('.$repId.') ';
  186.             
  187.             if (isset($_GET["check"]) && $_GET["check"] != 1){
  188.                 $repId ' AND dt.theme_id = '.$_GET["id"].' ';
  189.             }
  190.         } else {
  191.             if (isset($_GET["check"]) && $_GET["check"] != 1){
  192.                 $repId ' AND dt.theme_id = 0 ';
  193.             }
  194.         }
  195.         
  196.         
  197.         $req " ";
  198.         if (!$session->get('isRealAdminFairdoc')) {
  199.             $nodess trim($user->getUserLisible());
  200.             $nodesss substr($nodess0, -1);
  201.             $nodesId substr($nodesss1);
  202.             $exp explode(";"$nodesId);
  203.             $list "";
  204.             $i 0;
  205.             foreach ($exp as $n) {
  206.                 
  207.                 if ($n != null && $n !== "" && $n != " ") {
  208.                     if ($i == 0) {
  209.                         $list .= $this->getTree($n);
  210.                     } else {
  211.                         $list .= ','.$this->getTree($n);
  212.                     }
  213.                     
  214.                 }
  215.                 $i++;
  216.             }
  217.                         
  218.             $req " AND (dt.theme_id IN ($list) OR dt.theme_id is null)";
  219.         }
  220.         
  221.         if (isset($_GET["motcle"]) && $_GET["motcle"] != 0){
  222.             $motleft " LEFT JOIN dossier_motcle dm ON dm.dos_id=du.dos_id ";
  223.             //$motReq = ' AND dm.motcle_id IN ('.$_GET["motcle"].') ';
  224.             
  225.             $motsSearch explode(','$_GET["motcle"]);
  226.             if (count($motsSearch) == 1) {
  227.                 $motReq " HAVING '".$_GET["motcle"]."' = ANY(ARRAY_AGG((select motcle_id from dossier_motcle dm WHERE dm.dos_id=du.dos_id AND dm.motcle_id = ".$_GET["motcle"]." ))) ";
  228.             } else {
  229.                 $motReq .= " HAVING '".$_GET["motcle"]."'  = ANY(ARRAY_AGG(";
  230.                 foreach ($motsSearch as $key => $motSearch) {
  231.                     if ($key == 0){
  232.                        $motReq .= "(select motcle_id from dossier_motcle dm WHERE dm.dos_id=du.dos_id AND dm.motcle_id = ".$motSearch." )"
  233.                     } else {
  234.                         $motReq .= " || ',' ||(select motcle_id from dossier_motcle dm WHERE dm.dos_id=du.dos_id AND dm.motcle_id = ".$motSearch." )";
  235.                     }
  236.                      
  237.                 }
  238.                 $motReq .= "))";
  239.             }
  240.   
  241.         }
  242.         
  243.         //var_dump($_GET["extension"]);exit;
  244.         if (isset($_GET["extension"]) && $_GET["extension"] != ""){
  245.             //echo 'ooooo';exit;
  246.             $motsSearch explode(','$_GET["extension"]);
  247.             //var_dump($_GET["extension"]);exit;
  248.             if (count($motsSearch) == 1) {
  249.                 $req .= " AND doc_type = '".$_GET["extension"]."' ";
  250.             } else {
  251.                 $req .= " AND ( ";
  252.                 foreach ($motsSearch as $key => $motSearch) {
  253.                     if ($key == 0){
  254.                        $req .= " doc_type = '$motSearch' "
  255.                     } else {
  256.                        $req .= " OR doc_type = '$motSearch' "
  257.                     }
  258.                 
  259.                 }
  260.                 $req .= " ) ";
  261.             }
  262.         }
  263.         
  264.         if (isset($_GET["search"]) ) {
  265.             $search $_GET["search"];
  266.             $value $search["value"];
  267.             $req .= " AND lower(translate(dos_name,'éèàçù','eeacu')) like '%".pg_escape_string(strtolower($this->str_to_noaccent($value)))."%' ";
  268.         }
  269.         
  270.         //order[0][column]=1&order[0][dir]=des
  271.         //if (isset($_GET[order[0][column]]))
  272.         $order " ORDER BY TO_DATE(du.dos_date, 'DD/MM/YYYY') DESC, du.dos_id DESC ";
  273.         if (isset($_GET["order"])) {
  274.             $value $_GET["order"];
  275.             if ($value[0]["column"] == 1) {
  276.                 $order " ORDER BY du.dos_name ".$value[0]["dir"];
  277.             }
  278.             if ($value[0]["column"] == 2) {
  279.                 $order " ORDER BY du.dos_description ".$value[0]["dir"];
  280.             }
  281.             if ($value[0]["column"] == 2) {
  282.                 $order " ORDER BY TO_DATE(du.dos_date, 'DD/MM/YYYY') ".$value[0]["dir"]." , du.dos_id DESC ";
  283.             }
  284.             if ($value[0]["column"] == 3) {
  285.                 $order " ORDER BY t.theme_value ".$value[0]["dir"];
  286.             }
  287.             if ($value[0]["column"] == 4) {
  288.                 $order " ORDER BY doc.doc_type ".$value[0]["dir"];
  289.             }
  290.             if ($value[0]["column"] == 5) {
  291.                 $order " ORDER BY doc.doc_size ".$value[0]["dir"];
  292.             }
  293.         }
  294.         //var_dump($_GET["order"]);exit;
  295.         $page $_GET["start"];
  296.         
  297.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  298.       
  299.         $query "select distinct du.dos_id, du.dos_name, du.dos_description, t.theme_value, t.theme_id, dd.doc_id, du.dos_date, doc.doc_type , doc.doc_filename, doc.doc_indb , TO_DATE(du.dos_date, 'DD/MM/YYYY') as test, du.dos_lien, du.dos_islien, doc.doc_size  , doc.doc_type 
  300.             from dossier_user du
  301.             LEFT JOIN dossier_thematique dt ON dt.dos_id = du.dos_id
  302.             LEFT JOIN thematique t ON t.theme_id = dt.theme_id 
  303.             LEFT JOIN dossier_document dd ON dd.dos_id=du.dos_id
  304.             LEFT JOIN document_user doc ON dd.doc_id=doc.doc_id
  305.             $motleft
  306.             where 1=1 $repId $req AND dos_photo = false $lecture GROUP BY du.dos_id, t.theme_value, t.theme_id , dd.doc_id, doc.doc_id  $motReq $order LIMIT 20 OFFSET $page ";
  307.         
  308.         $dossiers $db->fetchAll($query);
  309.         
  310.         $retour = array();
  311.         
  312.         if (isset($_GET["motcle"]) && $_GET["motcle"] != 0){
  313.             $query "select distinct du.dos_id, du.dos_name, du.dos_description, t.theme_value, t.theme_id, dd.doc_id, du.dos_date, doc.doc_type , doc.doc_filename , TO_DATE(du.dos_date, 'DD/MM/YYYY') as test
  314.                 from dossier_user du
  315.                 LEFT JOIN dossier_thematique dt ON dt.dos_id = du.dos_id
  316.                 LEFT JOIN thematique t ON t.theme_id = dt.theme_id 
  317.                 LEFT JOIN dossier_document dd ON dd.dos_id=du.dos_id
  318.                 LEFT JOIN document_user doc ON dd.doc_id=doc.doc_id
  319.                 $motleft
  320.                 where 1=1 $repId $req AND dos_photo = false $lecture GROUP BY du.dos_id, t.theme_value, t.theme_id , dd.doc_id, doc.doc_id  $motReq ";
  321.             
  322.                 $count $db->fetchAll($query);
  323.                 $tot[0]["total"] = count($count);
  324.         } else {
  325.             $query "select count(distinct du.dos_id) as total from dossier_user du
  326.                 LEFT JOIN dossier_thematique dt ON dt.dos_id = du.dos_id
  327.                 LEFT JOIN thematique t ON t.theme_id = dt.theme_id   
  328.                 LEFT JOIN dossier_document dd ON dd.dos_id=du.dos_id
  329.                 LEFT JOIN document_user doc ON dd.doc_id=doc.doc_id
  330.                 $motleft
  331.                 where 1=1 $repId $req AND dos_photo = false $lecture ";
  332.             //echo $query;exit;
  333.             $tot $db->fetchAll($query);
  334.         }
  335.         
  336.         $retour = array();
  337.         
  338.         $retour["draw"] = $_GET["draw"];
  339.         
  340.         if (!isset($tot[0])) {
  341.             $retour["recordsTotal"] = 0;
  342.             $retour["recordsFiltered"] = 0;
  343.         } else {
  344.             $retour["recordsTotal"] = $tot[0]["total"];
  345.             $retour["recordsFiltered"] = $tot[0]["total"];
  346.         }
  347.         $i 0;
  348.         
  349.         foreach ($dossiers as $row) {
  350.             $query "select motcle_value FROM motcle mc
  351.                         LEFT JOIN dossier_motcle dmc ON mc.motcle_id = dmc.motcle_id 
  352.                         WHERE dos_id = ".$row["dos_id"]."";
  353.             $mots $db->fetchAll($query);
  354.             
  355.                                                             
  356.             $motcles '<div class="form-group keywords"><ul class="holder" style="width: 426px;">';    
  357.             //var_dump($row->getDosThematique());exit;
  358.             foreach ($mots as $mot) {
  359.                 $motcles .= '<li class="bit-box" rel="8" id="pt_RRBwwVRaTRVuBfdKgmzUZbqtA5a09wRx" style="font-size: 0.6em;">'.strtoupper($mot["motcle_value"]).'</li><br />';
  360.             }
  361.              $motcles .= '</ul></div>';
  362.              
  363.             $retour["data"][$i][0] = '';
  364.             if ($row["dos_islien"]) {
  365.                 $retour["data"][$i][0] = '<a href="'.$row["dos_lien"].'" target="_blank"><img src="../img/link.png" style="width: 45px;" /></a>';
  366.             } else {
  367.                 if ($row["doc_id"] != null) {
  368.                     if ($row["doc_type"] == "doc" || $row["doc_type"] == "docx") {
  369.                         $parts explode('.'$row["doc_filename"]);
  370.                         $last array_pop($parts);
  371.                         $parts = array(implode('.'$parts), $last);
  372.                         $filename $parts[0]; // outputs "one_two_three"
  373.                         $retour["data"][$i][0] = '<a href="#"  data-toggle="modal" data-target="#exampleModal" title="Prévisualiser le Document" alt="Prévisualiser le Document" onclick="changDoc(\''.$row["dos_id"].'/'.$filename.'.pdf\');return false;"><img src="../img/word.png" style="width: 30px;" /></a>';
  374.                     }
  375.                     if ($row["doc_type"] == "xls" || $row["doc_type"] == "xlsx") {
  376.                         $retour["data"][$i][0] = '<img src="../img/excel.png" style="width: 30px;" />';
  377.                     }
  378.                     if ($row["doc_type"] == "ppt" || $row["doc_type"] == "pptx") {
  379.                         $retour["data"][$i][0] = '<a href="#"  data-toggle="modal" data-target="#exampleModal" title="Prévisualiser le Document" alt="Prévisualiser le Document" onclick="changeppt(\''.$row["dos_id"].'/'.$row["doc_filename"].'\');return false;"><img src="../img/ppt.png" style="width: 30px;" /></a>';
  380.                     }
  381.                     if ($row["doc_type"] == "mp3" || $row["doc_type"] == "m4a") {
  382.                         $retour["data"][$i][0] = '<a href="#"  data-toggle="modal" data-target="#exampleModal" title="Prévisualiser le Document" alt="Prévisualiser le Document" onclick="changemp3(\''.$row["dos_id"].'/'.$row["doc_filename"].'\');return false;"><img src="../img/audio.png" style="width: 30px;" /></a>';
  383.                     }
  384.                     if ($row["doc_type"] == "mp4") {
  385.                         $retour["data"][$i][0] = '<a href="#"  data-toggle="modal" data-target="#exampleModal" title="Prévisualiser le Document" alt="Prévisualiser le Document" onclick="changevideo(\''.$row["dos_id"].'/'.$row["doc_filename"].'\');return false;"><img src="../img/film.png" style="width: 30px;" /></a>';
  386.                     }
  387.                     if ($row["doc_type"] == "pdf") {
  388.                         $retour["data"][$i][0] = '<a href="#"  data-toggle="modal" data-target="#exampleModal" title="Prévisualiser le Document" alt="Prévisualiser le Document" onclick="changDoc(\''.$row["dos_id"].'/'.$row["doc_filename"].'\');return false;"><img src="../img/pdf.png" style="width: 30px;" /></a>';
  389.                     }
  390.                     if ($row["doc_type"] == "zip" || $row["doc_type"] == "rar") {
  391.                         $retour["data"][$i][0] = '<img src="../img/zip.png" style="width: 45px;" />';
  392.                     }
  393.                 }
  394.             }
  395.             $retour["data"][$i][1] = (string) $row["dos_name"];
  396.             //$retour["data"][$i][2] = (string) $row["dos_description"];
  397.             $retour["data"][$i][2] = (string) $row["dos_date"];
  398.             $retour["data"][$i][3] = (string) strtoupper($row["theme_value"]);
  399.             $retour["data"][$i][4] = (string) strtoupper($row["doc_type"]);
  400.             $retour["data"][$i][5] = (string) round($row["doc_size"]/(1024*1024),2).' Mo';
  401.             //$retour["data"][$i][5] = (string) $motcles;
  402.             $retour["data"][$i][6] = '';
  403.             
  404.             if (!$row["dos_islien"]) {
  405.                 if ($row["doc_id"] != null) {
  406.                     $retour["data"][$i][6] = (string) '<a href="'.$this->container->getParameter('baseDir').'admin/downloadDoc/'.$row["doc_id"].'"target="_blank">
  407.                                 <button type="button" class="btn btn-success btn-xs" title="Télécharger le Fichier ">
  408.                                     <i class="fa fa-download"></i>
  409.                                 </button>
  410.                             </a>&nbsp';
  411.                 }
  412.             }
  413.             if ($session->get('isRealAdminFairdoc')) {
  414.                 $retour["data"][$i][6] .= '<a href="'.$this->container->getParameter('baseDir').'admin/deleteDos/'.$row["dos_id"].'" onClick="deleteDossier('.$row["dos_id"].'); return false;">
  415.                             <button type="button" class="btn btn-danger btn-xs"  alt="Supprimer le Fichier" title="Supprimer le Fichier">
  416.                                 <i class="fa fa-times"></i>
  417.                             </button>
  418.                         </a>
  419.                          <a href="'.$this->container->getParameter('baseDir').'admin/editFolder/'.$row["dos_id"].'">
  420.                             <button type="button" class="btn btn-secondary btn-xs"  alt="Modifier le Fichier" title="Modifier le Fichier">
  421.                                 <i class="fa fa-pencil-square-o"></i>
  422.                             </button>
  423.                         </a>
  424.                         <input type="checkbox" name="supp['.$row["dos_id"].']" class="myCheck" onclick="suppCheck()" value="'.$row["dos_id"].'">
  425.                             &nbsp;    
  426.                         ';
  427.             }
  428.             
  429.             if ($user->getUserChefdoc() && !$session->get('isRealAdminFairdoc')){
  430.                 $nodess trim($user->getUserThemes());
  431.                 $nodesss substr($nodess0, -1);
  432.                 $nodesId substr($nodesss1);
  433.                 $exp explode(";"$nodesId);
  434.                 $list "";
  435.                 $j 0;
  436.                 foreach ($exp as $n) {
  437.                     if ($n != null && $n !== "" && $n != " ") {
  438.                         if ($j == 0) {
  439.                             $list .= $this->getTree($n);
  440.                         } else {
  441.                             $list .= ','.$this->getTree($n);
  442.                         }
  443.                     }
  444.                     $j++;
  445.                 }
  446.                 $allKey explode(','$list);
  447.                 if (in_array($row["theme_id"], $allKey)) {
  448.                     $retour["data"][$i][6] .= '<a href="'.$this->container->getParameter('baseDir').'/admin/deleteDos/'.$row["dos_id"].'" onClick="deleteDossier('.$row["dos_id"].'); return false;">
  449.                             <button type="button" class="btn btn-danger btn-xs"  alt="Supprimer le Fichier" title="Supprimer le Fichier">
  450.                                 <i class="fa fa-times"></i>
  451.                             </button>
  452.                         </a>
  453.                          <a href="'.$this->container->getParameter('baseDir').'/admin/editFolder/'.$row["dos_id"].'">
  454.                             <button type="button" class="btn btn-secondary btn-xs"  alt="Modifier le Fichier" title="Modifier le Fichier">
  455.                                 <i class="fa fa-pencil-square-o"></i>
  456.                             </button>
  457.                         </a>
  458.                         <input type="checkbox" name="supp['.$row["dos_id"].']" class="myCheck" onclick="suppCheck()"  value="'.$row["dos_id"].'">
  459.                             &nbsp;  ';
  460.                 }
  461.             }
  462.             
  463.             if ($row["doc_type"] == "csv" && !$row["doc_indb"] && $this->getParameter('myTitle') != 'FairDoc') {
  464.                 $retour["data"][$i][6] .= '<a href="'.$this->container->getParameter('baseDir').'admin/addToDb/'.$row["doc_id"].'">
  465.                         <button type="button" class="btn btn-warning btn-xs"  alt="Mettre en BDD" title="Mettre en BDD">
  466.                                 <i class="fa fa-database"></i>
  467.                             </button>
  468.                         </a>';
  469.             }
  470.             
  471.             if ($row["doc_type"] == "csv" && $row["doc_indb"]) {
  472.                 $retour["data"][$i][6] .= '<a href="'.$this->container->getParameter('baseDir').'admin/seeDoc/'.$row["doc_id"].'">
  473.                         <button type="button" class="btn btn-info btn-xs"  alt="Voir en BDD" title="Voir en BDD">
  474.                                 <i class="fa fa-database"></i>
  475.                             </button>
  476.                         </a>';
  477.             }
  478.                     
  479.             if (!$row["dos_islien"]) {
  480.                 $retour["data"][$i][6] .= '&nbsp;<a href="#"  data-toggle="modal" data-target="#exampleModalDirect" title="Lien Direct" alt="Lien Direct" onclick="changLien(\''.$lecteur->getUserLogin().'\', \''.str_pad($row["doc_id"], 6"0"STR_PAD_LEFT).'\');return false;" style="text-decoration: none;color: black;"><i class="fa fa-link mypopover"></i></a>';
  481.             }
  482.                 $i++;
  483.         }
  484.         
  485.         if (!isset($tot[0])) {
  486.             $retour["data"] = array(); 
  487.         } else {
  488.             if ($tot[0]["total"] == 0) {
  489.                $retour["data"] = array(); 
  490.             }
  491.         }
  492.         
  493.         echo json_encode($retour);exit;
  494.     }
  495.     
  496.     
  497.     public function str_to_noaccent($str)
  498.     {
  499.         $url $str;
  500.         $url preg_replace('#Ç#''C'$url);
  501.         $url preg_replace('#ç#''c'$url);
  502.         $url preg_replace('#è|é|ê|ë#''e'$url);
  503.         $url preg_replace('#È|É|Ê|Ë#''E'$url);
  504.         $url preg_replace('#à|á|â|ã|ä|å#''a'$url);
  505.         $url preg_replace('#@|À|Á|Â|Ã|Ä|Å#''A'$url);
  506.         $url preg_replace('#ì|í|î|ï#''i'$url);
  507.         $url preg_replace('#Ì|Í|Î|Ï#''I'$url);
  508.         $url preg_replace('#ð|ò|ó|ô|õ|ö#''o'$url);
  509.         $url preg_replace('#Ò|Ó|Ô|Õ|Ö#''O'$url);
  510.         $url preg_replace('#ù|ú|û|ü#''u'$url);
  511.         $url preg_replace('#Ù|Ú|Û|Ü#''U'$url);
  512.         $url preg_replace('#ý|ÿ#''y'$url);
  513.         $url preg_replace('#Ý#''Y'$url);
  514.         return ($url);
  515.     }
  516.     /**
  517.      * Create theme entities.
  518.      *
  519.      * @Route("/addThemeGroupe", name="addThemeGroupe")
  520.      * @Method("POST")
  521.      */
  522.     public function createAction(Request $request)
  523.     {
  524.         if (!$request->isMethod('POST')) {
  525.             return NULL;
  526.         }
  527.         $pays = new Thematique();
  528.         $pays->setThemeValue($_POST["nameTheme"]);
  529.         if (isset($_POST["parentTheme"]) && $_POST["parentTheme"] != "") {
  530.            $pays->setThemeParent($_POST["parentTheme"]);
  531.         } else {
  532.             $pays->setThemeParent(null);
  533.         }
  534.         
  535.         $em $this->getDoctrine()->getManager();
  536.         $em->persist($pays);
  537.         $em->flush($pays);
  538.         
  539.         $id=$pays->getThemeId();
  540.         
  541.         if (isset($_POST["visibletous"]) && $_POST["visibletous"]) {
  542.             $query "update users set user_lisible = user_lisible || '$id;'";
  543.             $db $this->get('doctrine.dbal.default_connection');
  544.             $retour $db->fetchAll($query);
  545.         }
  546.         
  547.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  548.     }
  549.     
  550.     /**
  551.      * Create theme entities.
  552.      *
  553.      * @Route("/editThemeGroupe", name="editThemeGroupe")
  554.      * @Method("POST")
  555.      */
  556.     public function editThemeGroupeAction(Request $request)
  557.     {
  558.         if (!$request->isMethod('POST')) {
  559.             return NULL;
  560.         }
  561.         $id $_POST["parenteditTheme"];
  562.         $em $this->getDoctrine()->getManager();
  563.         $pays $em->getRepository('VcaBundle:Thematique')->find($id);
  564.         $pays->setThemeValue($_POST["editthemename"]);
  565.         $em $this->getDoctrine()->getManager();
  566.         $em->persist($pays);
  567.         $em->flush($pays);
  568.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  569.     }
  570.     
  571.     private function buildTree(array $elements$parentId null) {
  572.         $branch = array();
  573.         foreach ($elements as $i=>$element) {
  574.             $test = array();
  575.             $test["text"] = $element["theme_value"];
  576.             $test["id"] = $element["theme_id"];
  577.             if ($element["theme_parent"] == $parentId) {
  578.                 $children $this->buildTree($elements$element["theme_id"]);
  579.                 if ($children) {
  580.                     $test['nodes'] = $children;
  581.                 }
  582.                 $branch[$i] = $test;
  583.             }
  584.         }
  585.         return $branch;
  586.     }
  587.     
  588.     private function  getTree($rootid)
  589.     {
  590.        $arr = array();
  591.        $retour $rootid;
  592.        
  593.        $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  594.       
  595.         $query "select theme_id from thematique where theme_parent = $rootid";
  596.         $rows $db->fetchAll($query);
  597.                 
  598.         foreach ($rows as $row){
  599.             $retour .= ','.$row["theme_id"];
  600.             $retour .= ','.$this->getTree($row["theme_id"]);
  601.                     
  602.         }
  603.        
  604.        return $retour;
  605.     }
  606.     /**
  607.      * Creates a zip that contains all the Doc entities of a DossierUser and downloads it
  608.      *
  609.      * @Route("/admin/downloadFolder/{id}/{check}", name="admin_download")
  610.      */
  611.     public function downloadDossierAction(Request $request$id$check){
  612.         
  613.         $session = new Session();
  614.         
  615.         $userId $session->get('userIdFairdoc');
  616.         $em $this->getDoctrine()->getManager();
  617.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  618.          
  619.         $lecture " AND du.dos_hidden = false";
  620.         if ($user->getUserHidden() || $user->getUserAdmin()){
  621.             $lecture " ";
  622.         }
  623.         $repId=$motReq=$motleft=null;
  624.         $em $this->getDoctrine()->getManager();
  625.         $lecteur $em->getRepository('VcaBundle:Users')->findOneBy(array('userLecteur' => true));
  626.         if (isset($id) && $id != 0){
  627.             $repId $this->getTree($id);
  628.             
  629.             $repId ' AND dt.theme_id IN ('.$repId.') ';
  630.             
  631.             if (isset($check) && $check != 1){
  632.                 $repId ' AND dt.theme_id = '.$id.' ';
  633.             }
  634.             
  635.         } else {
  636.             if (isset($check) && $check != 1){
  637.                 $repId ' AND dt.theme_id = '.$id.' ';
  638.             }
  639.         }
  640.         
  641.         $req " ";
  642.         if (!$session->get('isRealAdminFairdoc')) {
  643.             $nodess trim($user->getUserLisible());
  644.             $nodesss substr($nodess0, -1);
  645.             $nodesId substr($nodesss1);
  646.             $exp explode(";"$nodesId);
  647.             $list "";
  648.             $i 0;
  649.             foreach ($exp as $n) {
  650.                 
  651.                 if ($n != null && $n !== "" && $n != " ") {
  652.                     if ($i == 0) {
  653.                         $list .= $this->getTree($n);
  654.                     } else {
  655.                         $list .= ','.$this->getTree($n);
  656.                     }
  657.                     
  658.                 }
  659.                 $i++;
  660.             }
  661.                         
  662.             $req " AND (dt.theme_id IN ($list) OR dt.theme_id is null)";
  663.         }
  664.         
  665.         $order " ORDER BY TO_DATE(du.dos_date, 'DD/MM/YYYY') DESC ";
  666.         
  667.        
  668.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  669.       
  670.         $query "select distinct du.dos_id, du.dos_name, du.dos_description, t.theme_value, t.theme_id, dd.doc_id, du.dos_date, doc.doc_type , doc.doc_filename, doc.doc_indb , TO_DATE(du.dos_date, 'DD/MM/YYYY') as test, du.dos_lien, du.dos_islien 
  671.             from dossier_user du
  672.             LEFT JOIN dossier_thematique dt ON dt.dos_id = du.dos_id
  673.             LEFT JOIN thematique t ON t.theme_id = dt.theme_id 
  674.             LEFT JOIN dossier_document dd ON dd.dos_id=du.dos_id
  675.             LEFT JOIN document_user doc ON dd.doc_id=doc.doc_id
  676.             $motleft
  677.             where 1=1 $repId $req AND dos_photo = false $lecture GROUP BY du.dos_id, t.theme_value, t.theme_id , dd.doc_id, doc.doc_id  $motReq $order ";
  678.         
  679.         $dossiers $db->fetchAll($query);
  680.         
  681.         exec("rm -f ".realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/Archive.zip");
  682.         
  683.         $zip = new ZipArchive();
  684.         $archive_filename realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/Archive.zip";
  685.         if ($zip->open($archive_filenameZipArchive::CREATE) == TRUE){
  686.             
  687.             foreach ($dossiers as $row) {
  688.                 //$fichiers = scandir(realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/".$row["dos_id"]);
  689.                 
  690.                 //foreach ($fichiers as $fichier) {
  691.                     $fichier realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/".$row["dos_id"]."/".$row["doc_filename"];
  692.                     if (file_exists($fichier) && is_file($fichier)) {
  693.                         $myname str_replace('.'.$row["doc_type"], ""$row["dos_name"]);
  694.                         $myname .= '.'.$row["doc_type"];
  695.                         if(!$zip->addFile($fichier$myname))
  696.                         {
  697.                             throw new Exception("Echec de l'ajout du fichier à l'archive");
  698.                         }
  699.                     }
  700.                 //}
  701.             }
  702.             
  703.             
  704.             
  705.             $zip->close();
  706.             ob_clean();
  707.             header("Content-type: application/zip");
  708.             header("Content-Disposition: attachment; filename=Archive.zip");
  709.             header("Pragma: no-cache");
  710.             header("Expires: 0");
  711.             readfile("$archive_filename");
  712.             unlink($archive_filename);
  713.         }
  714.         exit();
  715.     }
  716.     /**
  717.      * Show folder content
  718.      *
  719.      * @Route("/admin/showFolder/{id}", name="admin_showfolder")
  720.      */
  721.     public function showFolderAction(Request $request$id)
  722.     {
  723.         $session = new Session();
  724.         $thematique NULL;
  725.         $em $this->getDoctrine()->getManager();
  726.         $userId  $session->get('userIdFairdoc');
  727.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  728.         $dossier $em->getRepository('VcaBundle:DossierUser')->find($id);
  729.         $index $user->getUserTheme();
  730.         if($index){
  731.           $thematique $em->getRepository('VcaBundle:Thematique')->findOneBy(["id" => $index]);
  732.         }
  733.         return $this->render('document/showDoc.html.twig', array(
  734.             'user' => $user,
  735.             'thematique' => $thematique,
  736.             'index' => $index,
  737.             'dossier' => $dossier,
  738.         ));
  739.     }
  740.     /**
  741.      * Creates a form to edit the data of a DossierUser entity and to add new Doc entities to it
  742.      *
  743.      * @Route("/admin/editFolder/{id}", name="admin_editfolder")
  744.      */
  745.     public function editFolderAction(Request $requestDossierUser $dos)
  746.     {
  747.         $session = new Session();
  748.         $thematique NULL;
  749.         $em $this->getDoctrine()->getManager();
  750.         $userId $session->get('userIdFairdoc');
  751.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  752.         $dossiers $em->getRepository('VcaBundle:DossierUser')->findBy(array(), array('id' => 'DESC'));
  753.         $index $user->getUserTheme();
  754.         if($index){
  755.           $thematique $em->getRepository('VcaBundle:Thematique')->findOneBy(["id" => $index]);
  756.         }
  757.         $query "select distinct t.theme_id, t.theme_value, 
  758.                         (select th.theme_value from thematique th where th.theme_id = t.theme_parent AND t.theme_parent != 0 AND t.theme_parent is not null ) as parent
  759.                         from thematique t
  760.                         LEFT join dossier_thematique dt ON dt.theme_id = t.theme_id  
  761.                         group by t.theme_id order by parent asc";
  762.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  763.       
  764.         $thematiques $db->fetchAll($query);
  765.         if ($session->get('isRealAdminFairdoc')){
  766.             $index null;
  767.         }
  768.         if (!$this->isDossierOwner($dos)){
  769.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  770.         }
  771.         $id $dos->getDosId();
  772.         if ($request->isMethod('POST')) {
  773.             $dos $em->getRepository('VcaBundle:DossierUser')->find($id);
  774.             
  775.             if ($session->get('isRealAdminFairdoc')){
  776.                 $liste $dos->getDosThematique();
  777.                     foreach ($liste as $docaut) {
  778.                         $dos->getDosThematique()->removeElement($docaut);
  779.                     }
  780.             
  781.                 if ( $_POST["theme"] != &&  $_POST["theme"] != null) {
  782.                     $thematique $em->getRepository('VcaBundle:Thematique')->findOneBy(["id" => $_POST["theme"]]);
  783.                     $dos->getDosThematique()->add($thematique);
  784.                 }
  785.             }
  786.             
  787.             //var_dump($_POST);exit;
  788.             $hidden false;
  789.             if (isset($_POST["cache"])) {
  790.                 $hidden $_POST["cache"];
  791.             }
  792.             $dos->setDosHidden($hidden);
  793.             if (isset($_POST["lien"])) {
  794.                 $dos->setDosLien($_POST["lien"]);
  795.             }
  796.             if (isset($_POST["name"]))
  797.                 $dos->setDosName(substr($_POST["name"], 0255));
  798.             /*
  799.             if (isset($_POST["lat"])) {
  800.                 $dos->setDosLatitude(substr($_POST["lat"], 0, 255));
  801.             }
  802.             if (isset($_POST["lng"])) {
  803.                 $dos->setDosLongitude(substr($_POST["lng"],0,255));
  804.             }
  805.             */
  806.             $dos->setDosDescription(substr($_POST["description"], 0255));
  807.             $dos->setDosDate(substr($_POST["datepicker"], 0,255));
  808.             //$dos->setDosSite(substr($_POST["execution"],0,255));
  809.             // suppression des themes en cours
  810.             /*
  811.             $liste = $dos->getDosThematique();
  812.             foreach ($liste as $docaut) {
  813.                 $dos->getDosThematique()->removeElement($docaut);
  814.             }*/
  815.          
  816.             // suppression des mot en cours
  817.             $liste $dos->getDosMotcle();
  818.             foreach ($liste as $docaut) {
  819.                 $dos->getDosMotcle()->removeElement($docaut);
  820.             }
  821.            
  822.             // edition image de couverture
  823.             if(isset($_FILES['imageCover']) && $_FILES['imageCover'] != ""){
  824.               $imageCover $_FILES['imageCover'];
  825.               $tmpName  $imageCover['tmp_name'];
  826.               $filename "";
  827.               if (isset($imageCover['name'])) {
  828.                   $basename substr($imageCover['name'], 0strrpos($imageCover['name'], "."));
  829.                   $filename BlogController::sublimyFile($basename);
  830.               }
  831.               $extension substr($imageCover["name"], strrpos($imageCover["name"], '.')+1);
  832.               if($filename){
  833.                 $old_image $dos->getImage();
  834.                 if($old_image){
  835.                   exec("rm ".realpath($this->getParameter('kernel.root_dir').'/..')."/public/files/".$dos->getDosId()."/".$dos->getImage()." ");
  836.                 }
  837.                 $fileImNameBig "cover_".$filename.'.'.$extension;
  838.                 $dos->setImage(substr($fileImNameBig0255));
  839.                 exec("cp ".$tmpName."  ".realpath($this->getParameter('kernel.root_dir').'/..')."/public/files/".$dos->getDosId()."/".$fileImNameBig." ");
  840.               }
  841.             }
  842.             //Ajout des fichiers au dossier
  843.             
  844.             if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']["name"][0] != "") {
  845.                 
  846.                 $liste $dos->getDosDocs();
  847.                 foreach ($liste as $docaut) {
  848.                     $dos->getDosDocs()->removeElement($docaut);
  849.                 }
  850.             
  851.                 $dos $this->addFiles($_FILES['fileToUpload'], 0$dos);
  852.             }
  853.             $docs $dos->getDosDocs();
  854.             if (isset($_POST["docDescription"])) {
  855.                 //Un fichier n'a pas été chargé correctement
  856.                 if (count($docs) != count($_POST["docDescription"])) {
  857.                     $nbNewDocs count($_FILES['fileToUpload']['name']);
  858.                     $nbDescriptions count($_POST["docDescription"]);
  859.                     if (count($docs) == $nbNewDocs) {
  860.                         for ($i 0$i $nbNewDocs$i++) {
  861.                             if ($_FILES["fileToUpload"]["error"][$i] !== UPLOAD_ERR_OK) {
  862.                                 //On supprime la description des fichiers non chargés
  863.                                 unset($_POST["docDescription"][$i $nbDescriptions $nbNewDocs]);
  864.                             }
  865.                         }
  866.                     }
  867.                 }
  868.                 $_POST["docDescription"] = array_values($_POST["docDescription"]);
  869.                 //Ajout de la description de chaque document
  870.                 foreach ($docs as $key => $doc) {
  871.                     $doc->setDocDescription(substr($_POST["docDescription"][$key], 0255));
  872.                 }
  873.             }
  874.             $dos $this->saveList($dos);
  875.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  876.         }
  877.         $year = array();
  878.         for ($i date("Y"); $i >=1970 $i--) {
  879.             $year[] = $i;
  880.         }
  881.         //on recupere les auteurs
  882.         $list_aut = array();
  883.         foreach ($dos->getDosCorrespondant() as $i => $auteur) {
  884.             $list_aut[$i]['id'] = $auteur->getAutId();
  885.             $list_aut[$i]['value'] = strtoupper($auteur->getAutNom()) . " " strtolower($auteur->getAutPrenom());
  886.         }
  887.         //on recupere les pays
  888.         $list_pays = array();
  889.         foreach ($dos->getDosPays() as $i => $pays) {
  890.             $list_pays[$i]['id'] = $pays->getPaysId();
  891.             $list_pays[$i]['value'] = strtoupper($pays->getPaysNomFr());
  892.         }
  893.         //on recupere les mots
  894.         $list_mot = array();
  895.         foreach ($dos->getDosMotcle() as $i => $motcle) {
  896.             $list_mot[$i]['id'] = $motcle->getMotcleId();
  897.             $list_mot[$i]['value'] = strtoupper($motcle->getMotcleValue());
  898.         }
  899.         //on recupere les themes
  900.         $list_theme = array();
  901.         foreach ($dos->getDosThematique() as $i => $theme) {
  902.             $list_theme[$i]['id'] = $theme->getThemeId();
  903.             $list_theme[$i]['value'] = strtoupper($theme->getThemeValue());
  904.         }
  905.         //on recupere les fichiers
  906.         $docs $dos->getDosDocs();
  907.         $dataHead $em->getRepository('VcaBundle:DataUserHead')->findBy(array('vcadocId' => $dos->getDosId(), 'affiche' => true), array("id" => "asc"));
  908.         $nbOnglets count($dataHead);
  909.         $upload $em->getRepository('VcaBundle:Upload')->findBy(array('dosId' => $dos->getDosId()));
  910.         
  911.         $retourUpload = array();
  912.         foreach ($upload as $up) {
  913.             if ($up->getUserId() != null) {
  914.                 $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $up->getUserId()));
  915.                 $retourUpload[] = $user->getUserNom()." ".$user->getUserPrenom()." le ".$up->getDate();
  916.             }
  917.             
  918.         }
  919.         //$session->set("ongletDoc", $doc->getId());
  920.         return $this->render('document/editDoc.html.twig', array(
  921.             'user' => $user,
  922.             'thematique' => $thematique,
  923.             'thematiques' => $thematiques,
  924.             'index' => $index,
  925.             'dos' => $dos,
  926.             'docs' => $docs,
  927.             'year' => $year,
  928.             'list_aut' => $list_aut,
  929.             'list_pays' => $list_pays,
  930.             'list_mot' => $list_mot,
  931.             'list_theme' => $list_theme,
  932.             'nbOnglets' => $nbOnglets,
  933.             'retourUpload' => $retourUpload,
  934.             'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
  935.         ));
  936.     }
  937.     /**
  938.      * List of shared DossierUser entities
  939.      *
  940.      * @Route("/admin/documentation", name="admin documentation")
  941.      */
  942.     public function documentationAction(Request $request)
  943.     {
  944.         $em $this->getDoctrine()->getManager();
  945.         $list_theme $em->getRepository('VcaBundle:Thematique')->findAll();
  946.         $doss $em->getRepository('VcaBundle:DossierUser')->findBy(array('dosShare'=>true), array('id'=>'DESC'));
  947.         $docs = array();
  948.         $nbDocs = array();
  949.         foreach ($doss as $key => $dos) {
  950.             $docs[] = $dos->getDosDocs();
  951.             $nbDocs[] = sizeof(end($docs));
  952.         }
  953.         // replace this example code with whatever you need
  954.         return $this->render('document/documentation.html.twig', array(
  955.             'dossiers' => $doss,
  956.             'nbDocs' => $nbDocs,
  957.             'docs' => $docs,
  958.             'list_theme' => $list_theme,
  959.             'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..') . DIRECTORY_SEPARATOR,
  960.         ));
  961.     }
  962.     /**
  963.      * Fetches the DossierUser entities which match the filter
  964.      *
  965.      * @Route("/admin/rechargeDoc", name="admin rechargeDoc")
  966.      */
  967.     public function rechargeDocAction(Request $request)
  968.     {
  969.         $em $this->getDoctrine()->getManager();
  970.         //Fetch only the shared DossierUser entities
  971.         $dossByShare $em->getRepository('VcaBundle:DossierUser')->findSharedDos();
  972.         $dosIdArray = array();
  973.         foreach ($dossByShare as $dossArray){
  974.             $dosIdArray array_merge_recursive($dosIdArray$dossArray);
  975.         }
  976.         $dosIdArray array_unique($dosIdArray["dos_id"]);
  977.         //Fetch the id of the DossierUser entities which match $_POST["text"] and keep the shared ones
  978.         if (isset($_POST["text"])){
  979.             $dossText = array();
  980.             $dossByText $em->getRepository('VcaBundle:DossierUser')->findDosByText($_POST["text"]);
  981.             foreach ($dossByText as $textItem){
  982.                 $dossText array_merge_recursive($dossText$textItem);
  983.             }
  984.             if (sizeof($dossText) > 0) {
  985.                 if (! is_int($dossText["dos_id"])) {
  986.                     $dossText array_unique($dossText["dos_id"]);
  987.                 }
  988.                 $dosIdArray array_intersect($dosIdArray$dossText);
  989.             } else {
  990.                 $dosIdArray = array();
  991.             }
  992.         }
  993.         //Fetch the id of the DossierUser entities which are linked to at least one of the chosen MotCle and keep the ones which match the previous requirements
  994.         if (isset($_POST["mot"])) {
  995.             $dossMots = array();
  996.             $dossByMot = array();
  997.             foreach ($_POST["mot"] as $mot_item) {
  998.                 $dossByMot[] = $em->getRepository('VcaBundle:DossierUser')->findDosByMot($mot_item);
  999.             }
  1000.             foreach ($dossByMot as $dossArray){
  1001.                 foreach ($dossArray as $dossItem){
  1002.                     $dossMots array_merge_recursive($dossMots$dossItem);
  1003.                 }
  1004.             }
  1005.             if (sizeof($dossMots) > 0) {
  1006.                 if (! is_int($dossMots["dos_id"])) {
  1007.                     $dossMots array_unique($dossMots["dos_id"]);
  1008.                 }
  1009.                 $dosIdArray array_intersect($dosIdArray$dossMots);
  1010.             } else {
  1011.                 $dosIdArray = array();
  1012.             }
  1013.         }
  1014.         //Fetch the id of the DossierUser entities which are linked to at least one of the chosen Thematique and keep the ones which match the previous requirements
  1015.         if (isset($_POST["theme"])) {
  1016.             $dossThemes = array();
  1017.             $dossByTheme = array();
  1018.             foreach ($_POST["theme"] as $theme_item) {
  1019.                 $dossByTheme[] = $em->getRepository('VcaBundle:DossierUser')->findDosByTheme($theme_item);
  1020.             }
  1021.             foreach ($dossByTheme as $dossArray){
  1022.                 foreach ($dossArray as $dossItem){
  1023.                     $dossThemes array_merge_recursive($dossThemes$dossItem);
  1024.                 }
  1025.             }
  1026.             if (sizeof($dossByTheme[0])>0) {
  1027.                 if (! is_int($dossThemes["dos_id"])) {
  1028.                     $dossThemes array_unique($dossThemes["dos_id"]);
  1029.                 }
  1030.                 $dosIdArray array_intersect($dosIdArray$dossThemes);
  1031.             } else {
  1032.                 $dosIdArray = array();
  1033.             }
  1034.         }
  1035.         //Fetch the id of the DossierUser entities which are linked to at least one of the chosen Pays and keep the ones which match the previous requirements
  1036.         if (isset($_POST["pays"])) {
  1037.             $dossPays = array();
  1038.             $dossByPays = array();
  1039.             foreach ($_POST["pays"] as $pays_item) {
  1040.                 $dossByPays[] = $em->getRepository('VcaBundle:DossierUser')->findDosByPays($pays_item);
  1041.             }
  1042.             foreach ($dossByPays as $dossArray){
  1043.                 foreach ($dossArray as $dossItem){
  1044.                     $dossPays array_merge_recursive($dossPays$dossItem);
  1045.                 }
  1046.             }
  1047.             if (sizeof($dossByPays[0])>0) {
  1048.                 if (! is_int($dossPays["dos_id"])) {
  1049.                     $dossPays array_unique($dossPays["dos_id"]);
  1050.                 }
  1051.                 $dosIdArray array_intersect($dosIdArray$dossPays);
  1052.             } else {
  1053.                 $dosIdArray = array();
  1054.             }
  1055.         }
  1056.         $doss = array();
  1057.         foreach ($dosIdArray as $dos) {
  1058.             $i count($doss);
  1059.             //Retrieve all the information necessary to display each DossierUser entity
  1060.             $dossier $em->getRepository('VcaBundle:DossierUser')->find($dos);
  1061.             $doss[$i]["dos"]["id"] = $dossier->getDosId();
  1062.             $doss[$i]["dos"]["dosName"] = $dossier->getDosName();
  1063.             $doss[$i]["dos"]["dosDescription"] = $dossier->getDosName();
  1064.             $doss[$i]["docs"] = count($dossier->getDosDocs());
  1065.             //Search for the information about the User who owns each DossierUser
  1066.             $user $em->getRepository('VcaBundle:DossierUser')->find($dos)->getDosUser();
  1067.             $user $em->getRepository('VcaBundle:Users')->find($user);
  1068.             $doss[$i]["user"]["user_nom"] = $user->getUserNom();
  1069.             $doss[$i]["user"]["user_prenom"] = $user->getUserPrenom();
  1070.             $doss[$i]["user"]["user_email"] = $user->getUserEmail();
  1071.             //Search for the Motcle entities linked with each DossierUser
  1072.             $motcles $em->getRepository('VcaBundle:DossierUser')->findMotInDos($dos);
  1073.             $doss[$i]["motcles"] = array();
  1074.             foreach ($motcles as $j=>$mot){
  1075.                 $doss[$i]["motcles"][$j]["motcle_value"] = $em->getRepository('VcaBundle:Motcle')->find($mot["motcle_id"])->getMotcleValue();
  1076.             }
  1077.             //Search for the Thematique entities linked with each DossierUser
  1078.             $thematiques $em->getRepository('VcaBundle:DossierUser')->findThemeInDos($dos);
  1079.             $doss[$i]["thematiques"] = array();
  1080.             foreach ($thematiques as $j=>$theme){
  1081.                 $doss[$i]["thematiques"][$j]["theme_value"] = $em->getRepository('VcaBundle:Thematique')->find($theme["theme_id"])->getThemeValue();
  1082.             }
  1083.         }
  1084.         echo json_encode($doss);
  1085.         exit;
  1086.     }
  1087.     /**
  1088.      * @Route("/admin/rechercheDocs", name="rechercheDocs")
  1089.      */
  1090.     public function rechercheDocs()
  1091.     {
  1092.         $em $this->getDoctrine()->getManager();
  1093.         $docs $em->getRepository('VcaBundle:DossierUser')->find(["id" => $_POST["id"]]);
  1094.         $ds = [];
  1095.         foreach ($docs->getDosDocs() as $doc) {
  1096.           $ds[] = $doc->serialize();
  1097.         }
  1098.         echo json_encode($ds);
  1099.         exit;
  1100.     }
  1101.     /**
  1102.      * Deletes a dossierUser entity.
  1103.      *
  1104.      * @Route("/admin/deleteDos/{id}", name="dos_delete")
  1105.      */
  1106.     public function deleteDosAction(Request $requestDossierUser $dos)
  1107.     {
  1108.         if (!$this->isDossierOwner($dos)){
  1109.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1110.         }
  1111.         //Suppression physique du dossier
  1112.         exec("rm -R  ".realpath($this->getParameter('kernel.root_dir').'/..')."/public/files/".$dos->getDosId());
  1113.         $em $this->getDoctrine()->getManager();
  1114.         $em->remove($dos);
  1115.         //Suppression physique du dossier
  1116.         //$this->rrmdir(realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" .$dos->getDosId()."/");
  1117.         $em->flush();
  1118.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1119.     }
  1120.     
  1121.     /**
  1122.      * Deletes a dossierUser entity.
  1123.      *
  1124.      * @Route("/admin/deleteAllDos/{id}", name="dos_alldelete")
  1125.      */
  1126.     public function deleteAllDosAction(Request $request$id=null)
  1127.     {
  1128.         if ($id == null) {
  1129.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1130.         }
  1131.         $myDos explode(";;"$id);
  1132.         $em $this->getDoctrine()->getManager();
  1133.         foreach ($myDos as $doss) {
  1134.             
  1135.             $dos  $em->getRepository('VcaBundle:DossierUser')->findOneBy(array('id' => $doss));
  1136.             if (!$this->isDossierOwner($dos)){
  1137.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1138.             }
  1139.             //Suppression physique du dossier
  1140.             exec("rm -R  ".realpath($this->getParameter('kernel.root_dir').'/..')."/public/files/".$dos->getDosId());
  1141.             
  1142.             $em->remove($dos);
  1143.             //Suppression physique du dossier
  1144.             //$this->rrmdir(realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" .$dos->getDosId()."/");
  1145.             $em->flush();
  1146.             
  1147.         }
  1148.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1149.     }
  1150.     /**
  1151.      * Shares a DossierUser entity.
  1152.      *
  1153.      * @Route("/admin/shareDos/{id}/{share}", name="dos_share")
  1154.      */
  1155.     public function shareDosAction(Request $requestDossierUser $dos$share)
  1156.     {
  1157.         if (!$this->isDossierOwner($dos)){
  1158.             return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1159.         }
  1160.         $dos->setDosShare($share);
  1161.         $em $this->getDoctrine()->getManager();
  1162.         $em->persist($dos);
  1163.         $em->flush();
  1164.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1165.     }
  1166.     /**
  1167.      * Creates a DossierUser and persists it in the database.
  1168.      */
  1169.     private function createDossier()
  1170.     {
  1171.         $session = new Session();
  1172.         //var_dump($_FILES['fileToUpload']);exit;
  1173.         $em $this->getDoctrine()->getManager();
  1174.         
  1175.         foreach ($_FILES['fileToUpload']["name"] as $key=>$fichier) {
  1176.             $dos = new DossierUser();
  1177.             //$dos->setDosName(substr($fichier, 0, 255));
  1178.             $dos->setDosName(substr($_POST["name"], 0255));
  1179.             $dos->setDosDescription(substr($_POST["description"], 0255));
  1180.             $dos->setDosDate(substr($_POST["datepicker"], 0255));
  1181.             //$dos->setDosSite(substr($_POST["execution"], 0, 255));
  1182.             $dos->setDosShare(true);
  1183.             $dos->setDosPhoto(false);
  1184.             $hidden false;
  1185.             if (isset($_POST["cache"])) {
  1186.                 $hidden $_POST["cache"];
  1187.             }
  1188.             $dos->setDosHidden($hidden);
  1189.             
  1190.             $hidden false;
  1191.             if (isset($_POST["islien"])) {
  1192.                 $hidden $_POST["islien"];
  1193.             }
  1194.             $dos->setDosIslien($hidden);
  1195.             $dos->setDosLien($_POST["lien"]);
  1196.             $userId =$session->get('userIdFairdoc');
  1197.             $user $em->getRepository("VcaBundle:Users")->find($userId);
  1198.             $dos->setDosUser($user);
  1199.             if ( $_POST["theme"] != &&  $_POST["theme"] != null) {
  1200.                 $thematique $em->getRepository('VcaBundle:Thematique')->findOneBy(["id" => $_POST["theme"]]);
  1201.                 $dos->getDosThematique()->add($thematique);
  1202.             }
  1203.             if (isset($_POST["lat"])) {
  1204.                 $dos->setDosLatitude(substr($_POST["lat"], 0100));
  1205.             }
  1206.             if (isset($_POST["lng"])) {
  1207.                 $dos->setDosLongitude(substr($_POST["lng"], 0100));
  1208.             }
  1209.             $em->persist($dos);
  1210.             $em->flush();
  1211.             $dosId $dos->getDosId();
  1212.             //Création d'un répertoire dosId dans web/files
  1213.             mkdir(realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId);
  1214.             //Ajout des fichiers au dossier
  1215.             $dos $this->addFiles($_FILES['fileToUpload'],$key$dos);
  1216.             $docs $dos->getDosDocs();
  1217.             if (isset($_POST["docDescription"])) {
  1218.                 //Un fichier n'a pas été chargé correctement
  1219.                 if (count($docs) != count($_POST["docDescription"])) {
  1220.                     $nbNewDocs count($_FILES['fileToUpload']['name']);
  1221.                     $nbDescriptions count($_POST["docDescription"]);
  1222.                     for ($i 0$i $nbDescriptions$i++) {
  1223.                         if ($_FILES["fileToUpload"]["error"][$i] !== UPLOAD_ERR_OK) {
  1224.                             unset($_POST["docDescription"][$i]);
  1225.                         }
  1226.                     }
  1227.                 }
  1228.                 $_POST["docDescription"] = array_values($_POST["docDescription"]);
  1229.                 foreach ($docs as $key => $doc) {
  1230.                     $doc->setDocDescription(substr($_POST["docDescription"][$key], 0100));
  1231.                 }
  1232.             }
  1233.             $dos $this->saveList($dos);
  1234.             // edition image de couverture
  1235.             if(isset($_FILES['imageCover']) && $_FILES['imageCover']){
  1236.               $imageCover $_FILES['imageCover'];
  1237.               $tmpName  $imageCover['tmp_name'];
  1238.               $filename "";
  1239.               if (isset($imageCover['name'])) {
  1240.                   $basename substr($imageCover['name'], 0strrpos($imageCover['name'], "."));
  1241.                   $filename BlogController::sublimyFile($basename);
  1242.               }
  1243.               $extension substr($imageCover["name"], strrpos($imageCover["name"], '.')+1);
  1244.               $fileImNameBig "cover_".$filename.'.'.$extension;
  1245.               $dos->setImage(substr($fileImNameBig0255));
  1246.               exec("cp ".$tmpName."  ".realpath($this->getParameter('kernel.root_dir').'/..')."/public/files/".$dos->getDosId()."/".$fileImNameBig." ");
  1247.             }
  1248.             $em->flush();
  1249.         }
  1250.         
  1251.         return;
  1252.     }
  1253.     /**
  1254.      * Creates the Doc entities and updates the DossierUser entity
  1255.      *
  1256.      * @param $files : array of files
  1257.      * @param DossierUser $dos : dossier auquel appartiennent les fichiers
  1258.      * @return DossierUser
  1259.      */
  1260.     private function addFiles($files$cle DossierUser $dos)
  1261.     {
  1262.         $em $this->getDoctrine()->getManager();
  1263.         //Transformation de l'array $_FILES pour faciliter la lecture
  1264.         $file_array $this->reArrayFiles($files);
  1265.         $docList = new ArrayCollection();
  1266.         $dosId $dos->getDosId();
  1267.         foreach ($file_array as $key => $file){
  1268.             if ($key == $cle ) {
  1269.                 if ($file['error'] === UPLOAD_ERR_OK) {
  1270.                     $tmpName $file['tmp_name'];
  1271.                     $filename "";
  1272.                     if (isset($file['name'])) {
  1273.                         $basename substr($file['name'], 0strrpos($file['name'], "."));
  1274.                         $filename $this->sublimyFile($basename);
  1275.                     }
  1276.                     $extension substr($file["name"], strrpos($file["name"], '.') + 1);
  1277.                     $inDbb false;
  1278.                     $doc = new Doc();
  1279.                     $doc->setDocName(substr($filename0255));
  1280.                     $doc->setDocType(substr($extension0255));
  1281.                     $doc->setDocIndb($inDbb);
  1282.                     $doc->setDocCreation(date("Y-m-d H:i:s"));
  1283.                     $doc->setDocShare(false);
  1284.                     $doc->setDocSize($file['size']);
  1285.                     $em->persist($doc);
  1286.                     $docList[] = $doc;
  1287.                     $DocIdData $doc->getDocId();
  1288.                     $fileImNameBig $DocIdData '_' $filename '.' $extension;
  1289.                     $doc->setDocFilename(substr($fileImNameBig0255));
  1290.                     exec("cp " $tmpName " " realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId "/" $fileImNameBig " ");
  1291.                     //Sauvegarde du document
  1292.                     $em->flush();
  1293.                 }
  1294.             }
  1295.         }
  1296.         //Mise a jour du dossier avec les tables de jointure
  1297.         if (!$docList->isEmpty()) {
  1298.             foreach ($docList as $doc) {
  1299.                 $docItem $em->getRepository('VcaBundle:Doc')->find($doc->getDocId());
  1300.                 $dos->addDoc($docItem);
  1301.             }
  1302.             $em->flush();
  1303.         }
  1304.         //on convertit les docs en PDF lowriter ou soffice
  1305.         exec("export HOME=/tmp && /usr/bin/soffice --convert-to pdf " realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId "/*.doc --outdir " realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId " ");
  1306.         exec("export HOME=/tmp && /usr/bin/soffice --convert-to pdf " realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId "/*.docx --outdir " realpath($this->getParameter('kernel.root_dir') . '/..') . "/public/files/" $dosId " ");
  1307.         return $dos;
  1308.     }
  1309.     private function saveList(DossierUser $dos)
  1310.     {
  1311.         $em $this->getDoctrine()->getManager();
  1312.         $correspondants = new ArrayCollection();
  1313.         if (isset($_POST["aut_list"])) {
  1314.             foreach ($_POST["aut_list"] as $aut) {
  1315.                 $correspondants[] = $em->getRepository('VcaBundle:Auteur')->find($aut);
  1316.             }
  1317.             $dos->setDosCorrespondant($correspondants);
  1318.         }
  1319.         $payss = new ArrayCollection();
  1320.         if (isset($_POST["pays_list"])) {
  1321.             foreach ($_POST["pays_list"] as $pays) {
  1322.                 $payss[] = $em->getRepository('VcaBundle:Pays')->find($pays);
  1323.             }
  1324.             $dos->setDosPays($payss);
  1325.         }
  1326.         /*
  1327.                 $region = new \Doctrine\Common\Collections\ArrayCollection();
  1328.                 if (isset($_POST["region_list"])) {
  1329.                     foreach ($_POST["region_list"] as $aut) {
  1330.                         $region[] = $em->getRepository('VcaBundle:Region')->findOneBy(array('regionId' => $aut));
  1331.                     }
  1332.                     $doc->setDocRegion($region);
  1333.                 }
  1334.                 $type = new \Doctrine\Common\Collections\ArrayCollection();
  1335.                 if (isset($_POST["type_list"])) {
  1336.                     foreach ($_POST["type_list"] as $aut) {
  1337.                         $type[] = $em->getRepository('VcaBundle:Type')->findOneBy(array('typeId' => $aut));
  1338.                     }
  1339.                     $doc->setDocTypedata($type);
  1340.                 }
  1341.         */
  1342.         $motcles = new ArrayCollection();
  1343.         if (isset($_POST["mot_list"])) {
  1344.             foreach ($_POST["mot_list"] as $motcle) {
  1345.                 $motcles[] = $em->getRepository('VcaBundle:Motcle')->find($motcle);
  1346.             }
  1347.             $dos->setDosMotcle($motcles);
  1348.         }
  1349.         $thematiques = new ArrayCollection();
  1350.         if (isset($_POST["theme_list"])) {
  1351.             foreach ($_POST["theme_list"] as $thematique) {
  1352.                 $thematiques[] = $em->getRepository('VcaBundle:Thematique')->find($thematique);
  1353.             }
  1354.             $dos->setDosThematique($thematiques);
  1355.         }
  1356.         //$dos->setDosDocs($docs);
  1357.         $em->flush();
  1358.         return $dos;
  1359.     }
  1360.     /**
  1361.      * Deletes recursively a directory
  1362.      *
  1363.      * @param $dir directory we want to delete
  1364.      */
  1365.     private function rrmdir($dir){
  1366.         if (is_dir($dir)) {
  1367.             $objects scandir($dir);
  1368.             foreach ($objects as $object) {
  1369.                 if ($object != "." && $object != "..") {
  1370.                     if (is_dir($dir."/".$object))
  1371.                         $this->rrmdir($dir."/".$object);
  1372.                     else
  1373.                         unlink($dir."/".$object);
  1374.                 }
  1375.             }
  1376.             rmdir($dir);
  1377.         }
  1378.     }
  1379.     /**
  1380.      * Rearranges the array file_post to make it easier to use (I often use it for $_FILES when uploading files)
  1381.      *
  1382.      * @param $file_post
  1383.      * @return array
  1384.      */
  1385.     private function reArrayFiles($file_post)
  1386.     {
  1387.         $file_ary = array();
  1388.         $file_count count($file_post['name']);
  1389.         $file_keys array_keys($file_post);
  1390.         for ($i=0$i<$file_count$i++) {
  1391.             foreach ($file_keys as $key) {
  1392.                 $file_ary[$i][$key] = $file_post[$key][$i];
  1393.             }
  1394.         }
  1395.         return $file_ary;
  1396.     }
  1397.     /**
  1398.      * Checks if the current User is the owner of a DossierUser entity
  1399.      *
  1400.      * @param DossierUser $dos
  1401.      * @return bool
  1402.      */
  1403.     private function isDossierOwner(DossierUser $dos){
  1404.         $session = new Session();
  1405.         if ($session->get('isRealAdminFairdoc')){
  1406.             return true;
  1407.         }
  1408.         
  1409.         $userId $session->get('userIdFairdoc');
  1410.         $em $this->getDoctrine()->getManager();
  1411.         $user $em->getRepository('VcaBundle:Users')->findOneBy(array('id' => $userId));
  1412.         if ($user->getUserChefdoc()){
  1413.             $nodess trim($user->getUserThemes());
  1414.             $nodesss substr($nodess0, -1);
  1415.             $nodesId substr($nodesss1);
  1416.             $exp explode(";"$nodesId);
  1417.             
  1418.             $list "";
  1419.             $i 0;
  1420.             foreach ($exp as $n) {
  1421.                 
  1422.                 if ($n != null && $n !== "" && $n != " ") {
  1423.                     if ($i == 0) {
  1424.                         $list .= $this->getTree($n);
  1425.                     } else {
  1426.                         $list .= ','.$this->getTree($n);
  1427.                     }
  1428.                     
  1429.                 }
  1430.                 $i++;
  1431.             }
  1432.             $allKey explode(','$list);
  1433.             $thematiques $dos->getDosThematique();
  1434.             foreach($thematiques as $themes) {
  1435.                 $theme $themes->getThemeId();
  1436.             }
  1437.             if (in_array($theme$allKey)) {
  1438.                 return true;
  1439.             }
  1440.         }
  1441.         return false;
  1442.     }
  1443.     /**
  1444.      * Standardizes a string : converts it to lowercase and deletes all special chars
  1445.      *
  1446.      * @param $path string
  1447.      * @return string
  1448.      */
  1449.     public function sublimyFile($path)
  1450.     {
  1451.         // everything to lower and no spaces begin or end
  1452.         $path strtolower(trim($path));
  1453.         // adding - for spaces and union characters
  1454.         $find = array(' ''&''\r\n''\n''+'',');
  1455.         $path str_replace($find'_'$path);
  1456.         //replaces diacritical e by e
  1457.         $find = array('é''è''ê''ë');
  1458.         $path str_replace($find'e'$path);
  1459.         //delete and replace rest of special chars
  1460.         $find = array('/[^a-z0-9\-<>]/''/[\-]+/''/<[^>]*>/');
  1461.         $repl = array('''-''');
  1462.         $path preg_replace($find$repl$path);
  1463.         return $path;
  1464.     }
  1465.     
  1466.      /**
  1467.      * Lists all user entities.
  1468.      *
  1469.      * @Route("/admin/gestionrep", name="gestionrep")
  1470.      * @Method("GET")
  1471.      */
  1472.     public function gestionrepAction()
  1473.     {
  1474.         $session = new Session();
  1475.         if ($session->get('isRealAdminFairdoc') == false)
  1476.         {
  1477.            return $this->render('users/error.html.twig');
  1478.         }
  1479.         else
  1480.         {
  1481.             $query "select distinct t.theme_id, t.theme_value, 
  1482.                         (select count(dt.dos_id) from dossier_thematique WHERE theme_id = t.theme_id group by t.theme_id) as count, 
  1483.                         (select th.theme_value from thematique th where th.theme_id = t.theme_parent) as parent
  1484.                         from thematique t
  1485.                         LEFT join dossier_thematique dt ON dt.theme_id = t.theme_id where 1=1 
  1486.                         group by t.theme_id";
  1487.         $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  1488.       
  1489.         $themes $db->fetchAll($query);
  1490.             return $this->render('document/gestion.html.twig', array(
  1491.                 'themes' => $themes
  1492.             ));
  1493.         }
  1494.     }
  1495.     
  1496.     /**
  1497.      * Deletes a dossierUser entity.
  1498.      *
  1499.      * @Route("/admin/deletemyrep/{id}", name="deletemyrep")
  1500.      */
  1501.     public function deletemyrepAction(Request $request$id)
  1502.     {
  1503.         $session = new Session();
  1504.         if ($session->get('isRealAdminFairdoc') == false)
  1505.         {
  1506.            return $this->render('users/error.html.twig');
  1507.         }
  1508.         else
  1509.         {
  1510.             $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  1511.             $query "select theme_parent from thematique where theme_id = $id";
  1512.             $themeParent $db->fetchAll($query);
  1513.             
  1514.             $query "select theme_id from thematique where theme_parent = $id";
  1515.             $themesFils $db->fetchAll($query);
  1516.             
  1517.             $query "select dos_id from dossier_thematique where theme_id = $id";
  1518.             $files $db->fetchAll($query);
  1519.             
  1520.             if (isset($themeParent[0]["theme_parent"]) && $themeParent[0]["theme_parent"] != 0) {
  1521.                 foreach($themesFils as $themeFils) {
  1522.                     $query 'update thematique SET theme_parent = '.$themeParent[0]["theme_parent"].' where theme_id = '.$themeFils["theme_id"];
  1523.                     $db->fetchAll($query);
  1524.                 }
  1525.                 foreach($files as $file) {
  1526.                     $query 'update dossier_thematique SET theme_id = '.$themeParent[0]["theme_parent"].' where dos_id = '.$file["dos_id"];
  1527.                     $db->fetchAll($query);
  1528.                 }
  1529.             } else {
  1530.                 foreach($themesFils as $themeFils) {
  1531.                     $query 'update thematique SET theme_parent = null where theme_id = '.$themeFils["theme_id"];
  1532.                     $db->fetchAll($query);
  1533.                 }
  1534.                 foreach($files as $file) {
  1535.                     $query 'delete from dossier_thematique  where dos_id = '.$file["dos_id"];
  1536.                     $db->fetchAll($query);
  1537.                 }
  1538.             }
  1539.             
  1540.             $query "delete from thematique where theme_id = ".$id." ";
  1541.             $db->fetchAll($query);
  1542.         }
  1543.         
  1544.         return $this->redirect($this->getParameter('baseDir').'admin/gestionrep');
  1545.     }
  1546.     
  1547.     /**
  1548.      * Deletes a dossierUser entity.
  1549.      *
  1550.      * @Route("/admin/deletesmyrep/{id}", name="deletesmyrep")
  1551.      */
  1552.     public function deletesmyrepAction(Request $request$id)
  1553.     {
  1554.         $session = new Session();
  1555.         if ($session->get('isRealAdminFairdoc') == false)
  1556.         {
  1557.            return $this->render('users/error.html.twig');
  1558.         }
  1559.         else
  1560.         {
  1561.             $db $this->get('doctrine.dbal.default_connection');//on récupére un objet Doctrine\DBAL\Connection
  1562.             $query "select theme_parent from thematique where theme_id = $id";
  1563.             $themeParent $db->fetchAll($query);
  1564.             
  1565.             $query "select theme_id from thematique where theme_parent = $id";
  1566.             $themesFils $db->fetchAll($query);
  1567.             
  1568.             $query "select dos_id from dossier_thematique where theme_id = $id";
  1569.             $files $db->fetchAll($query);
  1570.             
  1571.             if (isset($themeParent[0]["theme_parent"]) && $themeParent[0]["theme_parent"] != 0) {
  1572.                 foreach($themesFils as $themeFils) {
  1573.                     $query 'update thematique SET theme_parent = '.$themeParent[0]["theme_parent"].' where theme_id = '.$themeFils["theme_id"];
  1574.                     $db->fetchAll($query);
  1575.                 }
  1576.                 foreach($files as $file) {
  1577.                     $query 'update dossier_thematique SET theme_id = '.$themeParent[0]["theme_parent"].' where dos_id = '.$file["dos_id"];
  1578.                     $db->fetchAll($query);
  1579.                 }
  1580.             } else {
  1581.                 foreach($themesFils as $themeFils) {
  1582.                     $query 'update thematique SET theme_parent = null where theme_id = '.$themeFils["theme_id"];
  1583.                     $db->fetchAll($query);
  1584.                 }
  1585.                 foreach($files as $file) {
  1586.                     $query 'delete from dossier_thematique  where dos_id = '.$file["dos_id"];
  1587.                     $db->fetchAll($query);
  1588.                 }
  1589.             }
  1590.             
  1591.             $query "delete from thematique where theme_id = ".$id." ";
  1592.             $db->fetchAll($query);
  1593.         }
  1594.         
  1595.         return $this->redirect($this->getParameter('baseDir').'admin/monedp');
  1596.     }
  1597. }