diff --git a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql index fdebccb3..949a0a76 100644 --- a/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql +++ b/src/ninegate-1.0/src/Cadoles/CoreBundle/Command/data/core-init-01.sql @@ -8,7 +8,7 @@ INSERT IGNORE INTO `niveau01` (`id`, `label`, `siren`) VALUES (-100, 'DRAAF', '130007107'); INSERT IGNORE INTO `user` (`id`, `niveau01_id`, `username`, `firstname`, `lastname`, `password`, `email`, `avatar`, `role`,`siren`,`authlevel`) VALUES -(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}hTAPycxp8kXFhZIjteFA4fsB2CQcIenW +(-100, -100, 'admin', 'Administrateur', 'draaf', '{SSHA}Kvz21GjhkryG4l7EKniMJzVfwDufa+eI ', 'admin@ldapbundle.ac-arno.fr', 'admin.jpg', 'ROLE_ADMIN', '130007107', 'simple'); diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php index 216cdd32..a4e56586 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Command/InitDataCommand.php @@ -51,6 +51,7 @@ class InitDataCommand extends ContainerAwareCommand $activate_widmindmaps = $this->getContainer()->getParameter('activate_widmindmaps'); $activate_widmoodle = $this->getContainer()->getParameter('activate_widmoodle'); $activate_widnextcloud = $this->getContainer()->getParameter('activate_widnextcloud'); + $activate_widonlyoffice = $this->getContainer()->getParameter('activate_widonlyoffice'); $activate_widopensondage = $this->getContainer()->getParameter('activate_widopensondage'); $activate_widphpldapadmin = $this->getContainer()->getParameter('activate_widphpldapadmin'); $activate_widpiwik = $this->getContainer()->getParameter('activate_widpiwik'); @@ -58,6 +59,8 @@ class InitDataCommand extends ContainerAwareCommand $activate_widsacoche = $this->getContainer()->getParameter('activate_widsacoche'); $activate_widwordpress = $this->getContainer()->getParameter('activate_widwordpress'); $activate_websocket = $this->getContainer()->getParameter('websocket_activate'); + + $widonlyoffice_sync = $this->getContainer()->getParameter('widonlyoffice_sync'); $output->writeln('PORTAL = Default Data'); @@ -530,7 +533,29 @@ class InitDataCommand extends ContainerAwareCommand $entityItem->setUrl($widnextcloud_url); $em->persist($entityItem); } - + + // Item Onlyoffice + if($activate_widonlyoffice) { + $widonlyoffice_url =$this->getContainer()->getParameter('widonlyoffice_url'); + $entityItem = $em->getRepository('CadolesPortalBundle:Item')->find(-1000); + if(!$entityItem) { + $entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_onlyoffice.png"]); + + $entityItem = new Item(); + $entityItem->setId(-1000); + $entityItem->setRowOrder(0); + $entityItem->setTitle('Onlyoffice'); + $entityItem->SetSubtitle("Application Bureautique"); + $entityItem->setIcon($entityicon); + $entityItem->setTarget("_blank"); + $entityItem->setItemcategory($entityItemcategoryapp); + $entityItem->setEssential(true); + $entityItem->addGroup($groupall); + } + $entityItem->setUrl($widonlyoffice_url); + $em->persist($entityItem); + } + // Item Opensondage if($activate_widopensondage) { $widopensondage_url =$this->getContainer()->getParameter('widopensondage_url'); @@ -1059,6 +1084,30 @@ class InitDataCommand extends ContainerAwareCommand $entityWidget->setParameter($parameter); $em->persist($entityWidget); + // Onlyoffice document + $entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1810); + if($widonlyoffice_sync) { + if(!$entityWidget) $entityWidget = new Widget(); + $entityicon = $em->getRepository('CadolesPortalBundle:Icon')->findoneby(["label"=>"uploads/icon/icon_onlyoffice.png"]); + $entityWidget->setId(-1810); + $entityWidget->setRoworder(2); + $entityWidget->setIcon($entityicon); + $entityWidget->setName('Documents Onlyoffice'); + $entityWidget->setDescription("Les documents associés à votre groupe"); + $entityWidget->setRouteview("cadoles_portal_config_panelwidget_view_onlydoc"); + $entityWidget->setHeight("630"); + $entityWidget->setAutoajust(true); + $entityWidget->setBorder(false); + $entityWidget->setOpened(true); + $entityWidget->setAccess(["config","group"]); + $parameter = json_decode('{"fields": []}'); + $entityWidget->setParameter($parameter); + $em->persist($entityWidget); + } + elseif($entityWidget) { + $em->remove($entityWidget); + } + // Widget Séparateur $entityWidget = $em->getRepository('CadolesPortalBundle:Widget')->find(-1600); if(!$entityWidget) $entityWidget = new Widget(); diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php index 187e21f7..7000cd55 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Controller/PagewidgetController.php @@ -2107,7 +2107,41 @@ class PagewidgetController extends Controller 'nbarticle' => $nbarticle, ]); - } + } + + public function viewOnlydocAction(Request $request,$id,$access="config") { + $usage=$request->query->get('usage'); + $group=$request->query->get('group'); + $user=$this->getUser(); + + $em = $this->getDoctrine()->getManager(); + $entity = $em->getRepository($this->labelentity)->find($id); + if (!$entity) throw $this->createNotFoundException('Unable to find entity.'); + + // Permissions + if($access=="config") { + $canupdate = true; + } + else { + // On s'assure que l'utilisateur à la permission de voir + $page=$entity->getPage(); + $em->getRepository("CadolesPortalBundle:Page")->getPermission($this->getUser(),$page,$cansee,$canupdate); + if(!$cansee) throw $this->createNotFoundException('Permission denied'); + } + $onlyservice = $this->container->get('cadoles.portal.service.only'); + $files=$onlyservice->getDocument($group, $folders, $firstfolder); + + // Render + return $this->render($this->labelentity.':viewonlydoc.html.twig', [ + 'entity' => $entity, + 'canadd' => $canupdate, + 'canupdate' => $canupdate, + 'firstfolder' => $firstfolder, + 'folders' => $folders, + 'files' => $files, + 'access' => $access, + ]); + } } diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml index 7d56b011..6e2c5af4 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/routing.yml @@ -795,6 +795,10 @@ cadoles_portal_config_panelwidget_view_groupmessage: path: /config/pagewidget/view/groupmessage/{id} defaults: { _controller: CadolesPortalBundle:Pagewidget:viewgroupmessage, access: config } +cadoles_portal_config_panelwidget_view_onlydoc: + path: /config/pagewidget/view/onlydoc/{id} + defaults: { _controller: CadolesPortalBundle:Pagewidget:viewonlydoc, access: config } + #-- Access user cadoles_portal_user_pagewidget_widget_sumbit: path: /user/pagewidget/submit/{idpage}/{idwidgettype} @@ -904,3 +908,7 @@ cadoles_portal_user_panelwidget_view_groupmessage: path: /pagewidget/view/groupmessage/{id} defaults: { _controller: CadolesPortalBundle:Pagewidget:viewgroupmessage, access: user } +cadoles_portal_user_panelwidget_view_onlydoc: + path: /pagewidget/view/onlydoc/{id} + defaults: { _controller: CadolesPortalBundle:Pagewidget:viewonlydoc, access: user } + diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/services.yml b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/services.yml index 56f25a36..b24f48a7 100644 --- a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/services.yml +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/config/services.yml @@ -4,3 +4,8 @@ services: arguments: ['@service_container'] tags: - { name: form.type } + + cadoles.portal.service.only: + public: true + class: Cadoles\PortalBundle\Service\onlyService + arguments: ['@service_container','@doctrine.orm.entity_manager'] diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewonlydoc.html.twig b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewonlydoc.html.twig new file mode 100644 index 00000000..a49bc642 --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Resources/views/Pagewidget/viewonlydoc.html.twig @@ -0,0 +1,117 @@ +{% set theme = app.session.get('theme') %} +{% if theme is not empty %} + {{ include('@Theme/'~theme~'/function.html.twig') }} +{% endif %} + +{% import "@CadolesPortal/Pagewidget/constants.twig" as constants %} + +{% set stylewidget = constants.mystylewidget(entity) %} +{% set stylewidgetmenu = constants.mystylewidgetmenu(entity) %} +{% set stylewidgetheader = constants.mystylewidgetheader(entity) %} +{% set stylewidgetbody = constants.mystylewidgetbody(entity) %} +{% set stylewidgetbodyreverse = constants.mystylewidgetbodyreverse(entity) %} + +{% set color = app.session.get('color') %} + +{% set colorbodyback = entity.colorbodyback %} +{% if colorbodyback is null %} + {% set colorbodyback = color['main'] %} +{% endif %} + + +{% set colorbodyfont = entity.colorbodyfont %} +{% if colorbodyfont is null %} + {% set colorbodyfont = color['fontcolorhover'] %} +{% endif %} + +
+ {% if canupdate or canadd %} +
+ {% if canupdate %} + + + {% endif %} + + {% if canadd %} + + {% endif %} +
+ {% endif %} + + +
+ {% if entity.icon %} + + {% else %} + + {% endif %} + {{ entity.name }} +
+ + {% if files|length >= 1 or canupdate %} +
+
+ {% if canupdate %} +
+
+ {% endif %} + + {% for file in files|sort %} + {% if loop.index==1 and not canupdate%} +
+
+ {% endif %} + +
+
+ {% if canadd %} + + + + {% endif %} + + {% if file.minefamily=="text" or file.minefamily=="image" or file.minetype == "application/pdf" %} + + {% else %} + + {% endif %} + + +
+
+ {% endfor %} + + {% if canadd %} +
+
+ +
+
+ {% endif %} +
+
+ {% endif %} +
+ + + diff --git a/src/ninegate-1.0/src/Cadoles/PortalBundle/Service/onlyService.php b/src/ninegate-1.0/src/Cadoles/PortalBundle/Service/onlyService.php new file mode 100644 index 00000000..0558b75a --- /dev/null +++ b/src/ninegate-1.0/src/Cadoles/PortalBundle/Service/onlyService.php @@ -0,0 +1,124 @@ +container = $container; + $this->em = $em; + + $this->only_activate = $this->container->getParameter('activate_widonlyoffice'); + if($this->only_activate) { + $this->only_activate=$this->container->getParameter('widonlyoffice_sync'); + if($this->only_activate) { + $this->only_url = $this->container->getParameter('widonlyoffice_url')."/api/2.0/"; + $this->only_user = $this->container->getParameter('widonlyoffice_user'); + $this->only_password = $this->container->getParameter('widonlyoffice_password'); + $this->only_host = str_replace("https://","",str_replace("http://","",$this->container->getParameter("widonlyoffice_url"))); + } + } + } + + public function getDocument($idproject,&$folders,&$firstfolder) { + $files=[]; + $folders=[]; + + if($this->only_activate) { + if($this->authOnly()) { + $response = \Unirest\Request::get($this->only_url.'/project/'.$idproject,$this->headers); + if($this->koresponse($response)) return false; + $firstfolder=$response->body->response->projectFolder;; + + $response = \Unirest\Request::get($this->only_url.'/project/'.$idproject.'/files',$this->headers); + if($this->koresponse($response)) return 0; + foreach($response->body->response->files as $fileonly) { + array_push($files,$fileonly); + } + foreach($response->body->response->folders as $folderonly) { + $folders[$folderonly->id]=$folderonly; + $subfolder=$this->scanfolder($folderonly->id,$folders,$this->headers); + foreach($subfolder as $file) { + array_push($files,$file); + } + } + } + } + + return $files; + } + + private function authOnly() { + // Only Office est-il dans le domaine + if(stripos($this->only_url,"/")===0) + $this->only_url="https://".$this->container->getParameter("weburl").$this->only_url; + $indomaine = (stripos($this->only_url,$this->container->getParameter("weburl"))!==false); + + // Si hors domaine on utilise le proxy si proxy il y a + if(!$indomaine) { + $PROXYactivate = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYactivate")->getValue(); + if($PROXYactivate) { + $PROXYserver = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYserver")->getValue(); + $PROXYport = $this->em->getRepository("CadolesCoreBundle:Config")->find("PROXYport")->getValue(); + \Unirest\Request::proxy($PROXYserver, $PROXYport, CURLPROXY_HTTP, true); + } + } + + \Unirest\Request::verifyPeer(false); + \Unirest\Request::verifyHost(false); + \Unirest\Request::timeout(5); + $this->headers = ['Host' => $this->only_host, 'Accept' => 'application/json','Content-Type'=>'application/json','Retry-After'=>'5']; + $query = array('userName' => $this->only_user, 'password' => $this->only_password); + $body = \Unirest\Request\Body::json($query); + + $response = \Unirest\Request::post($this->only_url.'/authentication',$this->headers,$body); + if($this->koresponse($response)) return false; + $token=$response->body->response->token; + $this->headers["Authorization"]=$token; + return true; + } + + private function koresponse($response) { + if($response->code>=Response::HTTP_BAD_REQUEST) { + $this->mydebug("ERREUR ".$response->code); + if(property_exists($response,"body") && property_exists($response->body,"error")) $this->mydebug("ERREUR ".$response->body->error->message);; + return true; + } + + return false; + } + + private function scanfolder($folderid,&$folders,$headers) { + $files=[]; + $response = \Unirest\Request::get($this->only_url.'/files/'.$folderid,$headers); + if($this->koresponse($response)) return 0; + foreach($response->body->response->files as $fileonly) { + array_push($files,$fileonly); + } + foreach($response->body->response->folders as $folderonly) { + $folders['"'.$folderonly->id.'"']=$folderonly; + $subfolder=$this->scanfolder($folderonly->id,$folders,$headers); + foreach($subfolder as $file) { + array_push($files,$file); + } + } + + return $files; + } + +} diff --git a/src/ninegate-1.0/web/uploads/icon/icon_onlyoffice.png b/src/ninegate-1.0/web/uploads/icon/icon_onlyoffice.png new file mode 100644 index 00000000..1579862e Binary files /dev/null and b/src/ninegate-1.0/web/uploads/icon/icon_onlyoffice.png differ