cfgplugin : activate plugin with simple click not confirmation needed
This commit is contained in:
parent
372b83e104
commit
018b727c7c
5 changed files with 141 additions and 50 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
58
include/ajax/ajax_activate_plugin.php
Normal file
58
include/ajax/ajax_activate_plugin.php
Normal file
|
|
@ -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';
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue