$currUser->load($user->_id);
$currUser->isAnesth();
$currUser->isPraticien();
$salle = new CSalle();
$salle->load($salle_id);
$bloc = new CBlocOperatoire();
$bloc->load($bloc_id);
// Vérification de la check list journalière
$daily_check_lists = array();
$daily_check_list_types = array();
$require_check_list = CAppUI::conf("dPsalleOp CDailyCheckList active", CGroups::loadCurrent()) && $date >= CMbDT::date() && !$currUser->_is_praticien;
if ($require_check_list) {
    if ($bloc->_id) {
        list($check_list_not_validated, $daily_check_list_types, $daily_check_lists) = CDailyCheckList::getCheckLists($bloc, $date, $type);
    } else {
        list($check_list_not_validated, $daily_check_list_types, $daily_check_lists) = CDailyCheckList::getCheckLists($salle, $date, $type);
    }
    if ($check_list_not_validated == 0) {
        $require_check_list = false;
    }
}
// Chargement des praticiens
$listAnesths = new CMediusers();
$listAnesths = $listAnesths->loadAnesthesistes(PERM_DENY);
$listChirs = new CMediusers();
$listChirs = $listChirs->loadPraticiens(PERM_DENY);
$type_personnel = array("op", "op_panseuse", "iade", "sagefemme", "manipulateur");
if (count($daily_check_list_types) && $require_check_list) {
    $type_personnel = array();
    foreach ($daily_check_list_types as $check_list_type) {
        $validateurs = explode("|", $check_list_type->type_validateur);
 /**
  * Get categories tree
  *
  * @param bool $operation see operations
  *
  * @return array
  */
 static function getCategoriesTree($operation = false)
 {
     $object = new self();
     $target_classes = CDailyCheckList::getNonHASClasses($operation);
     $targets = array();
     $by_class = array();
     foreach ($target_classes as $_class) {
         if ($_class != "COperation") {
             /** @var CSalle|CBlocOperatoire $_object */
             $_object = new $_class();
             //$_targets = $_object->loadGroupList();
             $_targets = $_object->loadList();
             array_unshift($_targets, $_object);
             $targets[$_class] = array_combine(CMbArray::pluck($_targets, "_id"), $_targets);
         }
         $where = array("target_class" => "= '{$_class}'");
         if ($_class == "COperation") {
             $where["list_type_id"] = ' IS NOT NULL';
         }
         /** @var CDailyCheckItemCategory[] $_list */
         $_list = $object->loadList($where, "target_id+0, title");
         // target_id+0 to have NULL at the beginning
         $by_object = array();
         foreach ($_list as $_category) {
             $_key = $_category->target_id ? $_category->target_id : "all";
             $by_object[$_key][$_category->_id] = $_category;
         }
         $by_class[$_class] = $by_object;
     }
     return array($targets, $by_class);
 }
<?php

/**
 * $Id: vw_daily_check_list_preview.php 25685 2014-11-03 15:34:02Z aurelie17 $
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 25685 $
 */
CCanDo::checkEdit();
$object_class = CValue::get("object_class");
$object_id = CValue::get("object_id");
$type = CValue::get("type", "ouverture_salle");
$object = CMbObject::loadFromGuid("{$object_class}-{$object_id}");
// Vérification de la check list journalière
$daily_check_lists = array();
$daily_check_list_types = array();
list($check_list_not_validated, $daily_check_list_types, $daily_check_lists) = CDailyCheckList::getCheckLists($object, "1970-01-01", $type);
$validateur = new CPersonnel();
$validateur->_ref_user = new CMediusers();
$validateur->_ref_user->_view = "Validateur test";
$listValidateurs = array($validateur);
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("daily_check_lists", $daily_check_lists);
$smarty->assign("listValidateurs", $listValidateurs);
$smarty->display("vw_daily_check_list_preview.tpl");
<?php

/**
 * $Id: httpreq_vw_check_list.php 25957 2014-11-20 09:00:54Z aurelie17 $
 *
 * @package    Mediboard
 * @subpackage SalleOp
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 25957 $
 */
CCanDo::checkRead();
$check_list_id = CValue::get("check_list_id");
$check_list = new CDailyCheckList();
$check_list->load($check_list_id);
$check_list->loadItemTypes();
$check_list->loadRefsFwd();
$check_list->loadBackRefs('items');
$check_list->loadRefListType();
$anesth_id = null;
if ($check_list->object_class == "COperation") {
    $check_list->_ref_object->loadRefChir();
    $anesth_id = $check_list->_ref_object->anesth_id;
}
$anesth = new CMediusers();
$anesth->load($anesth_id);
$type_personnel = array("op", "op_panseuse");
if (!$check_list->validator_id && $check_list->_id) {
    $validateurs = explode("|", $check_list->_ref_list_type->type_validateur);
    $type_personnel = array();
    foreach ($validateurs as $valid) {
} else {
    $validateurs = array();
}
$object = CMbObject::loadFromGuid($object_guid);
// Chargement des 3 check lists de l'OMS
$check_lists = array();
$check_item_categories = array();
$check_list = new CDailyCheckList();
$cat = new CDailyCheckItemCategory();
$cat->target_class = $object->_class;
// Pre-anesth, pre-op, post-op
foreach ($check_list->_specs["type"]->_list as $_type) {
    if (CDailyCheckList::$types[$_type] != $type_group) {
        continue;
    }
    $list = CDailyCheckList::getList($object, null, $_type);
    $list->loadItemTypes();
    $list->loadRefsFwd();
    $list->loadBackRefs('items');
    $list->isReadonly();
    if ($list->_ref_object instanceof COperation) {
        $list->_ref_object->loadRefPraticien();
    }
    $check_lists[$_type] = $list;
    $cat->type = $_type;
    $check_item_categories[$_type] = $cat->loadMatchingList("title");
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("object", $object);
$smarty->assign("check_item_categories", $check_item_categories);
 $type_checklist = $type == "reveil" ? "ouverture_sspi" : "ouverture_preop";
 $type_close = $type == "reveil" ? "fermeture_sspi" : "fermeture_preop";
 if ($require_check_list) {
     list($check_list_not_validated, $daily_check_list_types, $daily_check_lists) = CDailyCheckList::getCheckLists($bloc, $date, $type_checklist);
     if ($check_list_not_validated == 0) {
         $require_check_list = false;
     }
 }
 if ($require_check_list_close) {
     list($check_list_not_validated_close, $daily_check_list_types_close, $daily_check_lists_close) = CDailyCheckList::getCheckLists($bloc, $date, $type_close);
     if ($check_list_not_validated_close == 0) {
         $require_check_list_close = false;
     }
 }
 $date_close_checklist = CDailyCheckList::getDateLastChecklist($bloc, $type_close);
 $date_open_checklist = CDailyCheckList::getDateLastChecklist($bloc, $type_checklist);
 if ($require_check_list) {
     // Chargement de la liste du personnel pour le reveil
     if (CModule::getActive("dPpersonnel")) {
         $type_personnel = array("reveil");
         if (count($daily_check_list_types)) {
             $type_personnel = array();
             foreach ($daily_check_list_types as $check_list_type) {
                 $validateurs = explode("|", $check_list_type->type_validateur);
                 foreach ($validateurs as $validateur) {
                     $type_personnel[] = $validateur;
                 }
             }
         }
         $personnel = new CPersonnel();
         $personnels = $personnel->loadListPers(array_unique(array_values($type_personnel)));
 /**
  * Get the lists related to an object
  *
  * @param CMbObject $object Object to get the check lists of
  * @param string    $date   The reference date
  * @param string    $type   type de checklist
  *
  * @return array
  */
 static function getCheckLists(CMbObject $object, $date, $type = "ouverture_salle")
 {
     $daily_check_list_type = new CDailyCheckListType();
     $where = array("daily_check_list_type_link.object_class" => "= '{$object->_class}'", "daily_check_list_type_link.object_id IS NULL\r\n      OR\r\n     daily_check_list_type_link.object_id = '{$object->_id}'");
     $where["type"] = " = '{$type}'";
     $ljoin = array("daily_check_list_type_link" => "daily_check_list_type_link.list_type_id = daily_check_list_type.daily_check_list_type_id");
     /** @var CDailyCheckListType[] $daily_check_list_types  */
     $daily_check_list_types = $daily_check_list_type->loadGroupList($where, "title", null, "daily_check_list_type_id", $ljoin);
     /** @var CDailyCheckList[] $daily_check_lists  */
     $daily_check_lists = array();
     $check_list_not_validated = 0;
     foreach ($daily_check_list_types as $_list_type) {
         $_list_type->loadRefsCategories();
         $daily_check_list = CDailyCheckList::getList($object, $date, null, $_list_type->_id);
         $daily_check_list->loadItemTypes();
         $daily_check_list->loadBackRefs('items');
         $daily_check_list->loadRefListType();
         if (!$daily_check_list->_id || !$daily_check_list->validator_id) {
             $check_list_not_validated++;
         }
         $daily_check_lists[] = $daily_check_list;
     }
     return array($check_list_not_validated, $daily_check_list_types, $daily_check_lists);
 }
 // Pre-anesth, pre-op, post-op
 foreach ($operation_check_list->_specs["type"]->_list as $type) {
     $list = CDailyCheckList::getList($selOp, null, $type);
     $list->loadItemTypes();
     $list->loadRefsFwd();
     $list->loadBackRefs('items');
     $list->isReadonly();
     $list->_ref_object->loadRefPraticien();
     $operation_check_lists[$type] = $list;
     $where_cat["type"] = " = '{$type}'";
     $operation_check_item_categories[$type] = $cat->loadList($where_cat, "title");
 }
 $type_personnel_no_has = array();
 foreach (CDailyCheckListGroup::loadChecklistGroup() as $_checklist_group) {
     foreach ($_checklist_group->_ref_check_liste_types as $_checklist_type) {
         $list = CDailyCheckList::getList($selOp, null, null, $_checklist_type->_id);
         $list->loadItemTypes();
         $list->loadRefsFwd();
         $list->loadBackRefs('items');
         $list->isReadonly();
         $list->_ref_object->loadRefPraticien();
         $check_lists_no_has[$_checklist_type->_id] = $list;
         $where_cat = array();
         $where_cat["target_class"] = " = 'COperation'";
         $where_cat["list_type_id"] = " = '{$_checklist_type->_id}'";
         $check_items_no_has_categories[$_checklist_type->_id] = $cat->loadList($where_cat, "title");
     }
     $validateurs = explode("|", $list->loadRefListType()->type_validateur);
     foreach ($validateurs as $validateur) {
         $type_personnel_no_has[] = $validateur;
     }
if ($date_min) {
    $where[] = "date >= '{$date_min}'";
}
if ($date_max) {
    $where[] = "date <= '{$date_max}'";
}
/** @var CDailyCheckList[] $list_check_lists */
$list_check_lists = $check_list->loadList($where, 'date DESC, date_validate DESC, object_class, object_id, type', "{$start},40", null, $ljoin);
$count_check_lists = $check_list->countList($where, null, $ljoin);
foreach ($list_check_lists as $_check_list) {
    $_check_list->loadRefListType();
    if ($_check_list->_ref_object) {
        $_check_list->_ref_object->loadRefsFwd();
    }
}
$check_list_filter = new CDailyCheckList();
$check_list_filter->object_class = $object_class;
$check_list_filter->object_id = $object_id;
$check_list_filter->_date_min = $date_min;
$check_list_filter->_date_max = $date_max;
$check_list_filter->_type = $_type;
$check_list_filter->type = $type;
$check_list_filter->loadRefsFwd();
$list_rooms = CDailyCheckList::getRooms();
$empty = new COperation();
$empty->updateFormFields();
$list_rooms["COperation"] = array($empty);
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("list_check_lists", $list_check_lists);
$smarty->assign("count_check_lists", $count_check_lists);
    $selectPlages = "(plagesop.chir_id = %1 OR plagesop.spec_id = %2\n    OR plagesop.spec_id " . CSQLDataSource::prepareIn(array_keys($secondary_functions)) . ")";
    $where[] = $ds->prepare($selectPlages, $urgence->chir_id, $urgence->_ref_chir->function_id);
    $where["date"] = "= '{$date}'";
    $where["salle_id"] = CSQLDataSource::prepareIn(array_keys($listSalles));
    $order = "salle_id, debut";
    $urgence->_alternate_plages = $plage->loadList($where, $order);
    foreach ($urgence->_alternate_plages as $curr_plage) {
        $curr_plage->loadRefsFwd();
    }
}
$anesth = new CMediusers();
$anesths = $anesth->loadAnesthesistes(PERM_READ);
$date_last_checklist = array();
foreach ($listSalles as $salle) {
    if ($salle->cheklist_man) {
        $checklist = new CDailyCheckList();
        $checklist->object_class = $salle->_class;
        $checklist->object_id = $salle->_id;
        $checklist->loadMatchingObject("date DESC");
        if ($checklist->_id) {
            $log = new CUserLog();
            $log->object_id = $checklist->_id;
            $log->object_class = $checklist->_class;
            $log->loadMatchingObject("date DESC");
            $date_last_checklist[$salle->_id] = $log->date;
        } elseif ($checklist->date) {
            $date_last_checklist[$salle->_id] = $checklist->date;
        } else {
            $date_last_checklist[$salle->_id] = "";
        }
    }
    }
}
$date_last_checklist = null;
if ($salle->cheklist_man) {
    $date_last_checklist = CDailyCheckList::getDateLastChecklist($salle, "ouverture_salle");
}
// Checklist_fermeture bloc
$date_close_checklist = null;
$currUser = CMediusers::get();
$require_check_list = CAppUI::conf("dPsalleOp CDailyCheckList active", $group) && $date >= CMbDT::date() && !$currUser->isPraticien() ? 1 : 0;
if ($require_check_list) {
    list($check_list_not_validated, $daily_check_list_types, $daily_check_lists) = CDailyCheckList::getCheckLists($salle, $date, "fermeture_salle");
    if ($check_list_not_validated == 0) {
        $require_check_list = false;
    }
    $date_close_checklist = CDailyCheckList::getDateLastChecklist($salle, "fermeture_salle");
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("default_salle_id", $default_salle_id);
$smarty->assign("group_id", $group_id);
$smarty->assign("vueReduite", false);
$smarty->assign("salle", $salle);
$smarty->assign("hide_finished", $hide_finished);
$smarty->assign("praticien_id", null);
$smarty->assign("listBlocs", $listBlocs);
$smarty->assign("listAnesths", $listAnesths);
$smarty->assign("date", $date);
$smarty->assign("operation_id", $operation_id);
$smarty->assign("date_last_checklist", $date_last_checklist);
$smarty->assign("require_check_list_close", $require_check_list);