/**
  * insert into the table profile_menu for the given profile id and depending
  * of the module $p_module
  * @global type $cn
  * @param type $p_id profile.p_id
  * @param type $p_module menu_ref.me_code
  * @throws Exception 10 : profile absent , 20 module absent , 30 No parent menu
  */
 function insert_profile_menu($p_id = 1, $p_module = 'EXT')
 {
     global $cn;
     //profile exists ?
     $profile = new Profile_sql($cn, $p_id);
     if ($profile->p_id != $p_id) {
         throw new Exception(_('Profil inexistant'), 10);
     }
     // Menu exists
     $module = new Menu_Ref($cn, $p_module);
     if ($module->me_code == null) {
         throw new Exception(_('Module inexistant'), 20);
     }
     // Dependency
     $dep_id = $cn->get_value('select pm_id from profile_menu 
             where
             p_id=$1
             and me_code = $2 ', array($p_id, $p_module));
     // throw an exception if there is no dependency
     if ($dep_id == "") {
         throw new Exception(_('Pas de menu ') . $p_module, 30);
     }
     $profil_menu = new Profile_Menu($cn);
     $profil_menu->me_code = $this->me_code;
     $profil_menu->me_code_dep = $p_module;
     $profil_menu->p_type_display = 'S';
     $profil_menu->p_id = $p_id;
     $profil_menu->pm_id_dep = $dep_id;
     $cnt = $profil_menu->count(' where p_id=$1 and me_code = $2', array($p_id, $this->me_code));
     if ($cnt == 0) {
         $profil_menu->insert();
     }
 }