noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 04/09: cfgplugin : activate plugin with simpl


From: dwm
Subject: [Noalyss-commit] [noalyss] 04/09: cfgplugin : activate plugin with simple click not confirmation needed
Date: Fri, 9 Aug 2024 15:18:15 -0400 (EDT)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit 018b727c7cbc7a8548e0239a34fdcb742c8f006c
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Fri Aug 9 14:02:03 2024 +0200

    cfgplugin : activate plugin with simple click not confirmation needed
---
 html/ajax_misc.php                    |  2 +
 html/js/noalyss_script.js             | 43 +++++++++++++++++++++-
 include/ajax/ajax_activate_plugin.php | 58 +++++++++++++++++++++++++++++
 include/cfgplugin.inc.php             | 69 +++++++++++------------------------
 include/class/extension.class.php     | 19 +++++++++-
 5 files changed, 141 insertions(+), 50 deletions(-)

diff --git a/html/ajax_misc.php b/html/ajax_misc.php
index a7da58929..c4dbce961 100644
--- a/html/ajax_misc.php
+++ b/html/ajax_misc.php
@@ -352,6 +352,8 @@ $path = array(
     "tax_detail"=>"ajax_tax_detail"
     // card category definition : from CCARD
     ,"category_card_definition"=>"ajax_category_card_definition"
+    // activate plugin for a profile
+    ,'activate_plugin'=>'ajax_activate_plugin'
 ) ;
 
 if (array_key_exists($op, $path)) {
diff --git a/html/js/noalyss_script.js b/html/js/noalyss_script.js
index 2265b3aa5..6d36b9ca2 100644
--- a/html/js/noalyss_script.js
+++ b/html/js/noalyss_script.js
@@ -4280,5 +4280,46 @@ function check_password_strength(p_pass_domid, 
p_result_domid, details) {
 }
 
 /**
- * @brief
+ * activate a plugin , must comes from CFGPLUGIN
+ * @param elt {string}  DOMID of the element, must have the attribute 
gDossier, plugin and pr_id (for the profile)
+ * @test
  */
+function activate_plugin(elt)
+{
+       try
+               {
+                waiting_box();
+              var queryString =  {
+                       op:'activate_plugin',
+                       gDossier:elt.getAttribute('gDossier'),
+                       mecode:elt.getAttribute('me_code'),
+                       prid:elt.getAttribute('pr_id'),
+                       dep:elt.getAttribute('dep'),
+                       ord:elt.getAttribute('order'),
+                        activate:elt.checked
+                   };
+               var action = new Ajax.Request(
+                                         "ajax_misc.php" ,
+                                         {
+                                             method:'GET',
+                                             parameters:queryString,
+                                             onFailure:ajax_misc_failure,
+                                             onSuccess:function(req){
+                                                       remove_waiting_box();
+                               if (req.responseText == 'NOCONX') {
+                                   reconnect();
+                                   return;
+                               }
+
+                                  if (req.responseText != 'OK') {
+                                      smoke.alert(req.responseText)
+                                      elt.checked=false;
+                                  }
+                                             }
+                                         }
+                     );
+               }catch( e)
+               {
+                       alert_box(e.message);
+               }
+}
diff --git a/include/ajax/ajax_activate_plugin.php 
b/include/ajax/ajax_activate_plugin.php
new file mode 100644
index 000000000..f943a314c
--- /dev/null
+++ b/include/ajax/ajax_activate_plugin.php
@@ -0,0 +1,58 @@
+<?php
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   NOALYSS is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   NOALYSS is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with NOALYSS; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+// Copyright Author Dany De Bontridder danydb@aevalys.eu 9/08/24
+/*! 
+ * \file
+ * \brief activate a javascript for a PROFILE  , receive mecode 
(menu_ref.me_code) , prid , (profile.p_id)
+ * and activate(true/false)
+ */
+
+if (!defined('ALLOWED'))
+    die('Appel direct ne sont pas permis');
+
+global $g_user;
+
+if ($g_user->check_module('CFGPLUGIN') == 0) die();
+
+try {
+    $me_code = $http->get("mecode");
+    $pr_id = $http->get("prid", "number");
+    $activate = $http->get("activate");
+    $depend = $http->get("dep",'string','EXT');
+    $order = $http->get("ord",'number',0);
+} catch (\Exception $e) {
+    echo $e->getMessage();
+}
+
+$extension=new \Extension($cn,$me_code);
+if ( $activate=='true') {
+    // if depend does not exist then message error
+    try {
+        $extension->depend=$depend;
+        $extension->order=$order;
+        $extension->insert_profile_menu($pr_id);
+        echo 'OK';
+
+    } catch (\Exception $e) {
+        echo $e->getMessage();
+    }
+} elseif ($activate=='false') {
+    $extension->remove_from_profile_menu($pr_id);
+    echo 'OK';
+}
diff --git a/include/cfgplugin.inc.php b/include/cfgplugin.inc.php
index 1887ff9f5..578f73736 100644
--- a/include/cfgplugin.inc.php
+++ b/include/cfgplugin.inc.php
@@ -26,7 +26,7 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
  */
 global $cn;
 global $http;
-
+$dossier_id=Dossier::id();
 /******************************************************************************
  * Scan the plugin folder and file in each subfolder a property file and
  * store them into an array a_plugin
@@ -44,6 +44,13 @@ for ($e=0;$e<$nb_dirscan;$e++) {
             for ($i=0;$i<count($extension);$i++)
             {
                 $a_plugin[]=clone $extension[$i];
+                try {
+                    $extension[$i]->save_plugin();
+
+                } catch (\Exception $e) {
+                    echo_warning($e->getMessage());
+                }
+
             }
             
         }
@@ -56,47 +63,7 @@ $nb_plugin=count($a_plugin);
  */
 $a_profile=$cn->get_array('select p_id,p_name from profile where p_id > 0 
order by p_name');
 $nb_profile=count($a_profile);
-/******************************************************************************
- * save 
- 
******************************************************************************/
-if ( isset ($_POST['save_plugin'])){
-    // retrieve array of plugin
-    $plugin=$http->post('plugin', "string",array());
-    // for each extension
-    for ($i=0;$i<$nb_plugin;$i++) {
-        
-        $code=$a_plugin[$i]->me_code;
-        // for each profile
-        for ($e=0;$e<$nb_profile;$e++)
-        {
-            $profile=$a_profile[$e]['p_id'];
-            if ( isset ($plugin[$code][$profile])) {
-                // insert or update into db
-                $count = $cn->get_value("select count(*) from menu_ref where 
me_code=$1", array($code));
-                if ( $count == 0 ) {
-                    $a_plugin[$i]->insert();
-                }
-                try
-                {
-                    $a_plugin[$i]->insert_profile_menu($profile);
-                }
-                catch (Exception $exc)
-                {
-                    record_log($exc->getMessage()." 
trace:".$exc->getTraceAsString());
-                    $profile_name=$cn->get_value('select profile.p_name from 
profile where p_id=$1'
-                            ,array($profile));
-                    echo '<p class="notice">';
-                    echo "code $code"," profile $profile_name 
",$exc->getMessage();
-                    echo '</p>';
-                }
 
-            } else {
-                // delete
-                $a_plugin[$i]->remove_from_profile_menu ($profile);
-            }
-    }
-    }
-}
 /******************************************************************************
  * Display the Plugin and for each profile were it is installed or not
  
******************************************************************************/
@@ -105,7 +72,7 @@ if ( isset ($_POST['save_plugin'])){
 ?>
 <div class="content">
     <?php echo _('Nombre de plugins trouvés')." ".$nb_plugin; ?>
-    <form method="post">
+
     <?php echo _('Filtre');echo " ";echo 
HtmlInput::filter_table("plugin_install_tb", '0,1,2,3', 1);?>
     <table id="plugin_install_tb" class="result">
         <tr>
@@ -153,9 +120,18 @@ if ( isset ($_POST['save_plugin'])){
                     <span style="display:block">
                     
                     <?php
-                        $a=new 
ICheckBox('plugin['.$a_plugin[$e]->me_code.']['.$a_profile[$w]['p_id'].']');
-                        if ($a_profile[$w]['cnt']>0) $a->selected=true;
-                        echo $a->input();
+                        // $a=new 
ICheckBox('plugin['.$a_plugin[$e]->me_code.']['.$a_profile[$w]['p_id'].']');
+                        $name=uniqid($a_plugin[$e]->me_code);
+                        $ckpl=new ICheckBox($name);
+
+                        $ckpl->set_attribute("gDossier", $dossier_id);
+                        $ckpl->set_attribute("me_code", 
$a_plugin[$e]->me_code);
+                        $ckpl->set_attribute("pr_id", $a_profile[$w]['p_id']);
+                        $ckpl->set_attribute("dep", $a_plugin[$e]->depend);
+                        $ckpl->set_attribute("order", $a_plugin[$e]->order);
+                        $ckpl->javascript=' onchange="activate_plugin(this)"';
+                        if ($a_profile[$w]['cnt']>0) $ckpl->selected=true;
+                        echo $ckpl->input();
                         echo $a_profile[$w]['p_name'];
                  ?>
                     </span>
@@ -167,7 +143,6 @@ if ( isset ($_POST['save_plugin'])){
         
         <?php endfor; ?>
     </table>
-        <?php echo HtmlInput::submit('save_plugin', _('Valider')); ?>
-   </form>
+
 </div>
 
diff --git a/include/class/extension.class.php 
b/include/class/extension.class.php
index 12d4871f5..58253f276 100644
--- a/include/class/extension.class.php
+++ b/include/class/extension.class.php
@@ -162,7 +162,9 @@ class Extension extends Menu_Ref_sql
         // throw an exception if there is no dependency
         if (empty($dep_id))
         {
-            throw new Exception(_('Pas de menu ').$p_module, 30);
+            $msg = sprintf(_("Le menu %s dont dépend %s doit être crée ou %s 
doit être ajouté depuis le menu CFGPRO"),
+            $p_module,$this->me_code,$this->me_code);
+            throw new Exception($msg, 30);
         }
         $nb_dep=count($dep_id);
 
@@ -196,7 +198,20 @@ class Extension extends Menu_Ref_sql
     }
 
     /**
-     * Insert a plugin into the given profile, by default always insert into 
EXT
+     * @brief save a plugin into MENU_REF , calls insert_plugin or 
update_plugin if it already exists
+     * @return void
+     */
+    function save_plugin()
+    {
+        if ( $this->cn->get_value("select count(*) from menu_ref where 
me_code=$1",[$this->me_code]) > 0) {
+            $this->update_plugin();
+        } else {
+            $this->insert_plugin();
+
+        }
+    }
+    /**
+     * @brief Insert a plugin into the given profile, by default always insert 
into EXT
      * 
      * @param type $p_id profile.p_id
      * @throws Exception if duplicate or error db



reply via email to

[Prev in Thread] Current Thread [Next in Thread]