/**
  * Load parent catalog
  *
  * @return void
  */
 function loadParent()
 {
     if (!$this->_ref_pere) {
         $this->_ref_pere = new CCatalogueLabo();
         $this->_ref_pere->load($this->pere_id);
     }
 }
 /**
  * Load complete catalogue classification
  */
 function loadClassification()
 {
     $this->loadCatalogue();
     $catalogue = $this->_ref_catalogue_labo;
     $catalogues = array();
     $catalogues[$catalogue->_id] = $catalogue;
     while ($parent_id = $catalogue->pere_id) {
         $catalogue = new CCatalogueLabo();
         $catalogue->load($parent_id);
         $catalogues[$catalogue->_id] = $catalogue;
     }
     $level = count($catalogues);
     foreach ($catalogues as &$catalogue) {
         $catalogue->_level = --$level;
     }
     $this->_ref_catalogues = array_reverse($catalogues, true);
 }
 * @subpackage Labo
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
// Fonction de l'utilisateur courant
$user = CMediusers::get();
$function_id = $user->function_id;
// Liste des fonctions disponibles
$functions = new CFunctions();
$order = "text";
$functions = $functions->loadListWithPerms(PERM_EDIT, null, $order);
// Chargement du catalogue demandé
$catalogue = new CCatalogueLabo();
$catalogue->load(CValue::getOrSession("catalogue_labo_id"));
if ($catalogue->_id && $catalogue->getPerm(PERM_EDIT)) {
    $catalogue->loadRefs();
    $function_id = $catalogue->function_id;
} else {
    $catalogue = new CCatalogueLabo();
}
// Chargement de tous les catalogues
$where = array();
$where["pere_id"] = "IS NULL";
$where[] = "function_id IS NULL OR function_id " . CSQLDataSource::prepareIn(array_keys($functions));
$order = "identifiant";
$listCatalogues = $catalogue->loadList($where, $order);
foreach ($listCatalogues as &$_catalogue) {
    $_catalogue->loadRefsDeep();
}
    CValue::setSession("examen_labo_id");
}
if ($examen_labo_id) {
    $examen->load($examen_labo_id);
    $examen->loadRefs();
    $examen->getSiblings();
    $examen->getRootCatalogue();
    foreach ($examen->_ref_siblings as &$_sibling) {
        $_sibling->loadClassification();
    }
    $examen->loadClassification();
    $catalogue =& $examen->_ref_catalogue_labo;
} else {
    $catalogue_labo_id = CValue::getOrSession("catalogue_labo_id");
    $catalogue = new CCatalogueLabo();
    $catalogue->load($catalogue_labo_id);
    $examen->catalogue_labo_id = $catalogue->_id;
}
$catalogue->loadRefs();
$groups = CGroups::loadGroups();
foreach ($groups as &$group) {
    $group->loadFunctions(null);
    foreach ($group->_ref_functions as $keyFunc => &$function) {
        if ($function->getPerm(PERM_EDIT)) {
            $function->loadRefsUsers();
        } else {
            unset($group->_ref_functions[$keyFunc]);
        }
    }
}
// Liste des fonctions disponibles
 /**
  * Load minimal catalogue classification to cover the prescription analyses
  */
 function loadClassification()
 {
     $catalogues = array();
     // Load needed catalogues
     foreach ($this->_ref_examens as $examen) {
         $catalogue_id = $examen->catalogue_labo_id;
         if (!array_key_exists($catalogue_id, $catalogues)) {
             $catalogue = new CCatalogueLabo();
             $catalogue->load($catalogue_id);
             $catalogue->_ref_catalogues_labo = array();
             $catalogues[$catalogue->_id] = $catalogue;
         }
     }
     // Complete catalogue hierarchy
     foreach ($catalogues as $_catalogue) {
         $child_catalogue = $_catalogue;
         while ($child_catalogue->pere_id && !array_key_exists($child_catalogue->pere_id, $catalogues)) {
             $catalogue = new CCatalogueLabo();
             $catalogue->load($child_catalogue->pere_id);
             $catalogues[$catalogue->_id] = $catalogue;
             $child_catalogue = $catalogue;
         }
     }
     // Prepare catalogues collections
     foreach ($catalogues as &$ref_catalogue) {
         $ref_catalogue->_ref_catalogues_labo = array();
         $ref_catalogue->_ref_prescription_items = array();
     }
     // Feed prescription items
     foreach ($this->_ref_prescription_items as $_item) {
         $catalogue_id = $_item->_ref_examen_labo->catalogue_labo_id;
         $catalogues[$catalogue_id]->_ref_prescription_items[$_item->_id] = $_item;
     }
     // Link catalogue hierarchy
     foreach ($catalogues as &$link_catalogue) {
         if ($parent_id = $link_catalogue->pere_id) {
             $parent_catalogue =& $catalogues[$parent_id];
             $parent_catalogue->_ref_catalogues_labo[$link_catalogue->_id] =& $link_catalogue;
             $link_catalogue->_ref_pere =& $parent_catalogue;
         }
     }
     // Find classifications roots
     foreach ($catalogues as &$root_catalogue) {
         if ($root_catalogue->computeLevel() == 0) {
             $this->_ref_classification_roots[$root_catalogue->_id] =& $root_catalogue;
         }
     }
 }