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 @@ +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;$isave_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 '

'; - echo "code $code"," profile $profile_name ",$exc->getMessage(); - echo '

'; - } - } 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'])){ ?>
-
+ @@ -153,9 +120,18 @@ if ( isset ($_POST['save_plugin'])){ 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']; ?> @@ -167,7 +143,6 @@ if ( isset ($_POST['save_plugin'])){
- -
+
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