/**
 * $Id$
 * 
 * @package    Mediboard
 * @subpackage reservation
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkEdit();
$commentaire_id = CValue::get("commentaire_id");
$clone = CValue::get("clone", false);
$date = CValue::get("date");
$hour = CValue::get("hour");
$salle_id = CValue::get("salle_id");
$callback = CValue::get("callback");
$commentaire = new CCommentairePlanning();
$commentaire->load($commentaire_id);
if (!$commentaire->_id) {
    $commentaire->debut = "{$date} {$hour}:00:00";
    $commentaire->fin = "{$date} " . ($hour + 1) . ":00:00";
    $commentaire->salle_id = $salle_id;
}
if ($clone) {
    $commentaire->_id = null;
}
$smarty = new CSmartyDP();
$smarty->assign("commentaire", $commentaire);
$smarty->assign("clone", $clone);
$smarty->assign("callback", $callback);
$smarty->display("inc_edit_commentaire.tpl");
CStoredObject::massLoadFwdRef($prats, "function_id");
CStoredObject::massLoadFwdRef($operations, "plageop_id");
CStoredObject::massLoadFwdRef($operations, "salle_id");
CStoredObject::massLoadFwdRef($operations, "anesth_id");
CStoredObject::massLoadFwdRef($operations, "chir_2_id");
CStoredObject::massLoadFwdRef($operations, "chir_3_id");
CStoredObject::massLoadFwdRef($operations, "chir_4_id");
CStoredObject::massLoadBackRefs($operations, "workflow");
$sejours = CStoredObject::massLoadFwdRef($operations, "sejour_id");
$affectations = CStoredObject::massLoadBackRefs($sejours, "affectations");
CStoredObject::massLoadFwdRef($affectations, "lit_id");
$patients = CStoredObject::massLoadFwdRef($sejours, "patient_id");
$dossiers = CStoredObject::massLoadBackRefs($patients, "dossier_medical");
CDossierMedical::massCountAllergies($dossiers);
// Récupération des commentaires
$commentaire = new CCommentairePlanning();
$where = array();
$where["debut"] = " <= '{$date_planning} 23:59:59'";
$where["fin"] = " >= '{$date_planning} 00:00:00'";
$where["salle_id"] = CSQLDataSource::prepareIn($salles_ids);
$commentaires = $commentaire->loadListWithPerms(PERM_READ, $where);
// Récupération des plages opératoires
$plageop = new CPlageOp();
$where = array();
$where["date"] = " = '{$date_planning}'";
$where["salle_id"] = CSQLDataSource::prepareIn($salles_ids);
$plages = $plageop->loadListWithPerms(PERM_READ, $where);
// Création du planning
$planning = new CPlanningWeek(0, 0, count($salles), count($salles), false, "auto");
$planning->title = "Planning du " . CMbDT::format($date_planning, CAppUI::conf("longdate"));
//load the current bloc