Exemplo n.º 1
0
 function doStore()
 {
     parent::doStore();
     if (CModule::getActive("dPprescription") && !$this->_old->_id) {
         $p_to_c = new CPrescriptionProtocoleToConcept();
         $count_p_to_c = $p_to_c->countList();
         if ($count_p_to_c > 0) {
             /** @var CExObject $ex_object */
             $ex_object = $this->_obj;
             $all_fields = $ex_object->loadRefExClass()->loadRefsAllFields();
             $bool_concept_ids = array();
             foreach ($all_fields as $_field) {
                 if (strpos($_field->prop, "bool") === 0 && $_field->concept_id && $ex_object->{$_field->name} == "1") {
                     $bool_concept_ids[] = $_field->concept_id;
                 }
             }
             $bool_concept_ids = array_unique($bool_concept_ids);
             $where = array("concept_id" => $p_to_c->getDS()->prepareIn($bool_concept_ids));
             $protocole_ids = array_values(CMbArray::pluck($p_to_c->loadList($where), "protocole_id"));
             if (count($protocole_ids)) {
                 /** @var CSejour $sejour */
                 $sejour = $ex_object->getReferenceObject("CSejour");
                 if ($sejour && $sejour->_id) {
                     $prescription = $sejour->loadRefPrescriptionSejour();
                     if (!$prescription->_id) {
                         $prescription = new CPrescription();
                         $prescription->object_id = $sejour->_id;
                         $prescription->object_class = $sejour->_class;
                         $prescription->type = "sejour";
                         if ($msg = $prescription->store()) {
                             CAppUI::setMsg($msg, UI_MSG_WARNING);
                         }
                     }
                     $ops_ids = implode("-", CMbArray::pluck($sejour->loadRefsOperations(array("annulee" => "= '0'")), "operation_id"));
                     CAppUI::callbackAjax("window.opener.ExObject.checkOpsBeforeProtocole", $protocole_ids, $prescription->_id, $sejour->_id, $ops_ids);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
$callback = CValue::post("callback");
$group = CGroups::loadCurrent();
$patient = new CPatient();
$patient->nom = "anonyme";
$patient->prenom = "anonyme";
$patient->sexe = CAppUI::conf("dPpatients CPatient anonymous_sexe", $group);
$patient->naissance = CAppUI::conf("dPpatients CPatient anonymous_naissance", $group);
$msg = $patient->store();
if ($msg) {
    CAppUI::setMsg($msg, UI_MSG_ERROR);
} else {
    CAppUI::setMsg(CAppUI::tr("CPatient-msg-create"), UI_MSG_OK);
}
echo CAppUI::getMsg();
if ($callback) {
    CAppUI::callbackAjax($callback, $patient->_id, $patient->_view);
}
CApp::rip();
Exemplo n.º 3
0
if ($type == "entree") {
    $consult->motif = CAppUI::conf('soins Other default_motif_observation', CGroups::loadCurrent()->_guid);
}
// Cas des urgences
if ($sejour->type == "urg") {
    // Motif de la consultation
    $consult->motif = "";
    if (CAppUI::conf('dPurgences motif_rpu_view')) {
        $consult->motif .= "RPU: ";
        $sejour->loadRefRPU();
        $consult->motif .= $sejour->_ref_rpu->diag_infirmier;
    }
}
if ($msg = $consult->store()) {
    CAppUI::setMsg($msg, UI_MSG_ERROR);
}
CAppUI::setMsg("CConsultation-msg-create", UI_MSG_OK);
// Redirect final
if ($ajax) {
    echo CAppUI::getMsg();
    if ($callback) {
        CAppUI::callbackAjax($callback, $consult->_id);
    }
    CApp::rip();
}
if ($current_m = CValue::post("_m_redirect")) {
    CAppUI::redirect("m={$current_m}");
} else {
    $current_m = $sejour->type == "urg" ? "dPurgences" : "dPcabinet";
    CAppUI::redirect("m={$current_m}&tab=edit_consultation&selConsult={$consult->consultation_id}&chirSel={$chir->user_id}");
}
Exemplo n.º 4
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkAdmin();
$source_guid = CValue::post("source_guid");
$current_directory = CValue::post("current_directory");
$files = CValue::read($_FILES, "import");
$message = array("result" => "Ajout du fichier", "resultNumber" => 0, "error" => array());
/** @var CSourceFTP $source */
$source = CMbObject::loadFromGuid($source_guid);
foreach ($files["name"] as $index => $_file) {
    if (!$_file) {
        continue;
    }
    try {
        $source->addFile($files["tmp_name"][$index], $_file, $current_directory);
        $message["resultNumber"]++;
    } catch (CMbException $e) {
        $message["error"][] = CAppUI::tr("CExhangeFile-error", $_file);
    }
}
CAppUI::callbackAjax("window.parent.ExchangeSource.closeAfterSubmit", $message);
CApp::rip();
Exemplo n.º 5
0
<?php

/**
 * $Id$
 *  
 * @category CompteRendu
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision$
 * @link     http://www.mediboard.org
 */
$user_id = CValue::post("user_id");
$user_password = CValue::post("user_password");
$form_name = CValue::post("form_name");
$callback = CValue::post("callback");
$user = new CUser();
$user->load($user_id);
if ($user->_id && CUser::checkPassword($user->user_username, $user_password)) {
    CAppUI::callbackAjax($callback, $user_id, $form_name);
} else {
    CAppUI::setMsg("CUser-user_password-nomatch", UI_MSG_ERROR);
    echo CAppUI::getMsg();
}
Exemplo n.º 6
0
    if ($delete) {
        $date_max_delete = CMbDT::date("-6 MONTHS", $date_max);
        $where = array();
        $where["date_echange"] = "< '{$date_max_delete}'";
        $count_delete = $exchange->countList($where);
        CAppUI::stepAjax("{$exchange_class}-msg-delete_count", UI_MSG_OK, $count_delete);
    }
    // comptage des echanges à vider qui ne le sont pas deja
    $where = array();
    $where["date_echange"] = "< '{$date_max}'";
    $where["purge"] = "= '0'";
    $count_purge = $exchange->countList($where);
    CAppUI::stepAjax("{$exchange_class}-msg-purge_count", UI_MSG_OK, max(0, $count_purge - $count_delete));
    return;
}
// suppression effective
if ($delete) {
    $query = "DELETE FROM `{$exchange->_spec->table}`\r\n    WHERE `date_echange` < '{$date_max_delete}'\r\n    LIMIT {$max}";
    $ds->exec($query);
    $count_delete = $ds->affectedRows();
    CAppUI::stepAjax("{$exchange_class}-msg-deleted_count", UI_MSG_OK, $count_delete);
}
// vidage des champs effective
$query = "UPDATE `{$exchange->_spec->table}`\r\n  SET\r\n  `purge` = '1',\r\n  `output` = '',\r\n  `input` = ''\r\n  WHERE `date_echange` < '{$date_max}'\r\n  AND `purge` = '0'\r\n  LIMIT {$max}";
$ds->exec($query);
$count_purge = $ds->affectedRows();
CAppUI::stepAjax("{$exchange_class}-msg-purged_count", UI_MSG_OK, $count_purge);
// on continue si on est en auto
if ($count_purge + $count_delete) {
    CAppUI::callbackAjax("Echange.purge", false, $source_class);
}
Exemplo n.º 7
0
            if ($sejour->sortie_reelle) {
                $sejour->sortie_reelle = CMbDT::dateTime("+4 HOURS", $sejour->entree);
            }
            /* TODO Supprimer ceci après l'ajout des times picker */
            $sejour->_hour_entree_prevue = null;
            $sejour->_min_entree_prevue = null;
            $sejour->_hour_sortie_prevue = null;
            $sejour->_min_sortie_prevue = null;
        } elseif ($sejour->type == "comp") {
            $sejour->sortie_prevue = CMbDT::dateTime("+72 HOURS", $sejour->entree);
            if ($sejour->sortie_reelle) {
                $sejour->sortie_reelle = CMbDT::dateTime("+72 HOURS", $sejour->entree);
            }
            /* TODO Supprimer ceci après l'ajout des times picker */
            $sejour->_hour_entree_prevue = null;
            $sejour->_min_entree_prevue = null;
            $sejour->_hour_sortie_prevue = null;
            $sejour->_min_sortie_prevue = null;
        }
        if ($msg = $sejour->store()) {
            CAppUI::stepAjax($msg, UI_MSG_ERROR);
        }
        break;
    default:
        CAppUI::stepAjax("L'évenement choisit n'est pas supporté", UI_MSG_ERROR);
}
CAppUI::stepAjax("Evenement effectué");
if ($callback) {
    CAppUI::callbackAjax($callback);
}
CApp::rip();
Exemplo n.º 8
0
    $sejour_rpu->_id = null;
    // Pas de génération du NDA, et pas de synchro (handler) du séjour
    $sejour_rpu->_generate_NDA = false;
    $sejour_rpu->_no_synchro = true;
    $msg = $sejour_rpu->store();
    viewMsg($msg, "Séjour reliquat enregistré");
    // Transfert du RPU sur l'ancien séjour
    $rpu->sejour_id = $sejour_rpu->_id;
}
//Cas d'une hospitalisation normale sans collision et sans rattachement
if (!$sejour_id_merge) {
    // Passage en séjour d'hospitalisation
    $sejour->type = "comp";
    $sejour->_en_mutation = $sejour_rpu->_id;
    // La synchronisation était désactivée après la sauvegarde du RPU
    $sejour->_no_synchro = false;
    $msg = $sejour->store();
    viewMsg($msg, "CSejour-title-modify");
}
//Problème sur le séjour, aucune action fait sur le rpu
if ($msg) {
    return;
}
// Modification du RPU
$rpu->mutation_sejour_id = $sejour->_id;
$rpu->sortie_autorisee = "1";
$rpu->gemsa = "4";
$msg = $rpu->store();
viewMsg($msg, "CRPU-title-close");
CAppUI::callbackAjax("Sejour.editModal", $sejour->_id);
Exemplo n.º 9
0
        $mediuser->_user_first_name = trim($_user['firstname']);
        $mediuser->makeUsernamePassword($mediuser->_user_first_name, $mediuser->_user_last_name);
        $where = array();
        $ljoin["users"] = "users_mediboard.user_id = users.user_id";
        $where['users.user_username'] = "******" . $mediuser->_user_username . "'";
        $mediuser->loadObject($where, null, null, $ljoin);
        if ($mediuser->_id) {
            CAppUI::stepAjax("Cabinet_mediuser_prenom%s_nom%s_username%s_already_exist", UI_MSG_WARNING, $mediuser->_user_first_name, $mediuser->_user_last_name, $mediuser->_user_username);
            continue;
        }
        $mediuser->function_id = $cabinet->_id;
        //praticien
        if ($type == "prat") {
            $mediuser->_profile_id = $profile_prat;
            $mediuser->_user_type = 13;
        }
        //secretaire
        if ($type == "sec") {
            $mediuser->_profile_id = $profile_sec;
            $mediuser->_user_type = 10;
        }
        //store
        if ($msg = $mediuser->store()) {
            CAppUI::stepAjax($msg, UI_MSG_WARNING);
            continue;
        }
        CAppUI::stepAjax("Cabinet_user_created_name%s_firstname%s_username%s_with_password_%s", UI_MSG_OK, $mediuser->_user_last_name, $mediuser->_user_first_name, $mediuser->_user_username, $mediuser->_user_password);
    }
}
CAppUI::callbackAjax("changePagePrimaryUsers", $cabinet->_id);
Exemplo n.º 10
0
        if (!isset($line[1])) {
            continue;
        }
        $line = array_map("getValue", $line);
        $etab = new CEtabExterne();
        $etab->finess = getNum($line[0]);
        if ($etab->loadMatchingObject()) {
            continue;
        }
        $etab->siret = getNum($line[1]);
        $etab->ape = $line[2];
        $etab->nom = $line[3];
        $etab->raison_sociale = $line[3];
        $etab->adresse = "{$line['4']}\n{$line['5']}\n{$line['6']}";
        $etab->cp = $line[7];
        $etab->ville = $line[8];
        $etab->tel = getNum($line[9]);
        $etab->fax = getNum($line[10]);
        $etab->repair();
        $type = $etab->_id ? "modify" : "create";
        if ($msg = $etab->store()) {
            CAppUI::setMsg($msg, UI_MSG_WARNING);
        } else {
            CAppUI::setMsg("CEtabExterne-msg-{$type}", UI_MSG_OK);
        }
    }
    fclose($fp);
    unlink($_file);
}
CAppUI::callbackAjax('window.parent.$("systemMsg").show().insert', CAppUI::getMsg());
CApp::rip();
Exemplo n.º 11
0
    $cr->modele_id = $modele->_id;
    $cr->object_class = $object_class;
    $cr->object_id = $object_id;
    $cr->author_id = $user_id;
    $cr->nom = $modele->nom;
    $cr->margin_right = $modele->margin_right;
    $cr->margin_left = $modele->margin_left;
    $cr->margin_top = $modele->margin_top;
    $cr->margin_bottom = $modele->margin_bottom;
    $cr->file_category_id = $modele->file_category_id;
    $cr->font = $modele->font;
    $cr->size = $modele->size;
    $cr->factory = $modele->factory;
    $cr->loadContent(false);
    $cr->_source = $modele->generateDocFromModel();
    $template->applyTemplate($cr);
    $cr->_source = $template->document;
    if ($msg = $cr->store()) {
        CAppUI::setMsg($msg, UI_MSG_ERROR);
    }
    if ($_modele_to_pack === $first) {
        $cr_to_push = $cr;
    }
}
if ($callback && $cr_to_push) {
    $fields = $cr_to_push->getProperties();
    CAppUI::callbackAjax($callback, $cr_to_push->_id, $fields);
}
CAppUI::setMsg(CAppUI::tr("CPack-msg-create"), UI_MSG_OK);
echo CAppUI::getMsg();
CApp::rip();
Exemplo n.º 12
0
    unset($fields["object_id"]);
    if ($root_name == $object_config->_class) {
        $xpath = new CMbXPath($dom);
        $nodeList = $xpath->query("//{$root_name}/*");
        $array_configs = array();
        foreach ($nodeList as $_node) {
            $config = $xpath->getValueAttributNode($_node, "config");
            $value = $xpath->getValueAttributNode($_node, "value");
            $array_configs[$config] = $value;
        }
        if ($count = array_diff_key($array_configs, $fields)) {
            CAppUI::setMsg("Trop de données ('" . count($array_configs) . "') par rapport aux \n        champs de l'objet ('" . count($fields) . "')", UI_MSG_ERROR);
        } else {
            foreach ($array_configs as $key => $value) {
                $object_config->{$key} = $value;
                if ($msg = $object_config->store()) {
                    CAppUI::setMsg("Erreur lors de l'import de la configuration : " . $msg, UI_MSG_ERROR);
                } else {
                    CAppUI::setMsg("Configuration correctement importée");
                }
            }
        }
    } else {
        CAppUI::setMsg("La classe du fichier de configuration importé ('{$root_name}'), ne correspond pas à celle \n      de la configuration choisie ('{$object_config->_class}')", UI_MSG_ERROR);
    }
    CAppUI::callbackAjax('window.parent.uploadCallback', array("message" => CAppUI::getMsg(), "object_id" => $object->_id, "object_configs_guid" => $object_config->_guid));
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("object_config_guid", $object_config_guid);
$smarty->display("import_config.tpl");
    $affectations_enfant = $affectation->loadBackRefs("affectations_enfant");
    foreach ($affectations_enfant as $_affectation_enfant) {
        /** @var CAffectation $_affectation_enfant */
        if (CMbDT::addDateTime("00:{$tolerance}:00", $_affectation_enfant->entree) > $_date_cut) {
            $_affectation = $_affectation_enfant;
        } else {
            $_affectation = new CAffectation();
            $_affectation->entree = $_date_cut;
            $_affectation->sejour_id = $_affectation_enfant->sejour_id;
            $_affectation->sortie = $_affectation_enfant->sortie;
            $_affectation->uf_hebergement_id = $_affectation_enfant->uf_hebergement_id;
            $_affectation->uf_medicale_id = $_affectation_enfant->uf_medicale_id;
            $_affectation->uf_soins_id = $_affectation_enfant->uf_soins_id;
            $_affectation_enfant->sortie = $_date_cut;
        }
        $_affectation->lit_id = $lit_id ? $lit_id : $_affectation_enfant->lit_id;
        $_affectation->parent_affectation_id = $affectation_cut->_id;
        if ($msg = $_affectation_enfant->store()) {
            CAppUI::setMsg($msg, UI_MSG_ERROR);
        }
        if ($msg = $_affectation->store()) {
            CAppUI::setMsg($msg, UI_MSG_ERROR);
        }
    }
}
if ($callback) {
    $fields = $affectation_cut->getProperties();
    CAppUI::callbackAjax($callback, $affectation_cut->_id, $fields);
}
echo CAppUI::getMsg();
CApp::rip();
Exemplo n.º 14
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Cabinet
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
$codeacte = CValue::getOrSession("code");
$callback = CValue::getOrSession("callback");
// Chargement du code
$code = CDatedCodeCCAM::get($codeacte);
if (!$code->code) {
    $tarif = 0;
    CAppUI::stepAjax("{$codeacte}: code inconnu", UI_MSG_ERROR);
}
// si le code CCAM est complet (activite + phase), on selectionne le tarif correspondant
if ($code->_activite != "" && $code->_phase != "") {
    $tarif = $code->activites[$code->_activite]->phases[$code->_phase]->tarif;
} else {
    $tarif = $code->_default;
}
CAppUI::callbackAjax($callback, $tarif);
CAppUI::stepAjax("{$codeacte}: {$tarif}");
Exemplo n.º 15
0
                CAppUI::stepAjax($msg, UI_MSG_ERROR);
            }
            continue;
        }
    }
    foreach ($dests as $_dest) {
        $destinataire = new CUserMessageDest();
        $destinataire->user_message_id = $usermessage->_id;
        $destinataire->from_user_id = $usermessage->creator_id;
        $destinataire->to_user_id = $_dest;
        $destinataire->loadMatchingObject();
        if ($send_it) {
            $destinataire->datetime_sent = $date;
        }
        if ($msg = $destinataire->store()) {
            CAppUI::stepAjax($msg, UI_MSG_ERROR);
        }
    }
    $msg = $_POST["usermessage_id"] ? 'CUserMessage-msg-modify' : 'CUserMessage-msg-create';
    if ($send_it) {
        $msg = 'CUserMessage-msg-sent';
    }
}
CAppUI::setMsg($msg, UI_MSG_OK);
$smarty = new CSmartyDP();
$messages = CAppUI::getMsg();
$smarty->assign('messages', $messages);
$smarty->display('inc_callback_modal.tpl');
if ($callback) {
    CAppUI::callbackAjax($callback, 'internal', $message_id);
}
 /**
  * Make JavaScript callback
  *
  * @return void
  */
 function doCallback()
 {
     $messages = CAppUI::$instance->messages;
     echo CAppUI::getMsg();
     $fields = $this->_obj->getProperties();
     $fields["_guid"] = $this->_obj->_guid;
     $fields["_class"] = $this->_obj->_class;
     foreach ($messages as &$_level) {
         $_keys = array_map("utf8_encode", array_keys($_level));
         $_values = array_map("utf8_encode", array_values($_level));
         $_level = array_combine($_keys, $_values);
     }
     $fields["_ui_messages"] = $messages;
     $id = $this->_obj->_id ? $this->_obj->_id : 0;
     if ($this->callBack) {
         CAppUI::callbackAjax($this->callBack, $id, $fields);
     } else {
         $guid = "{$this->className}-{$id}";
         CAppUI::callbackAjax("Form.onSubmitComplete", $guid, $fields);
     }
     if (!CAppUI::$mobile) {
         CApp::rip();
     }
 }
Exemplo n.º 17
0
    if ($root_name == $format_config->_class) {
        $xpath = new CMbXPath($dom);
        $nodeList = $xpath->query("//{$root_name}/*");
        $array_configs = array();
        foreach ($nodeList as $_node) {
            $config = $xpath->getValueAttributNode($_node, "config");
            $value = $xpath->getValueAttributNode($_node, "value");
            $array_configs[$config] = $value;
        }
        if ($count = array_diff_key($array_configs, $fields)) {
            CAppUI::setMsg("Trop de données ('" . count($array_configs) . "') par rapport aux \n        champs de l'objet ('" . count($fields) . "')", UI_MSG_ERROR);
        } else {
            foreach ($array_configs as $key => $value) {
                $format_config->{$key} = $value;
                if ($msg = $format_config->store()) {
                    CAppUI::setMsg("Erreur lors de l'import de la configuration : " . $msg, UI_MSG_ERROR);
                } else {
                    CAppUI::setMsg("Configuration correctement importée");
                }
            }
        }
    } else {
        CAppUI::setMsg("La classe du fichier de configuration importé ('{$root_name}'), ne correspond pas à celle \n      de la configuration choisie ('{$format_config->_class}')", UI_MSG_ERROR);
    }
    CAppUI::callbackAjax('window.parent.uploadCallback', array("message" => CAppUI::getMsg(), "sender" => array("sender_class" => $actor->_class, "sender_id" => $actor->_id)));
}
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("actor_guid", $actor_guid);
$smarty->assign("format_config_guid", $format_config_guid);
$smarty->display("import_config.tpl");
/**
 * $Id$
 *
 * @category Admin
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision$
 * @link     http://www.mediboard.org
 */
$password = trim(CValue::post('password'));
$lock = CValue::post('lock');
if ($lock) {
    $_SESSION['locked'] = true;
    return;
} else {
    if (!$password) {
        CAppUI::setMsg("Auth-failed-nopassword", UI_MSG_ERROR);
    }
    if (!CUser::checkPassword(CUser::get()->user_username, $password)) {
        CAppUI::setMsg("Auth-failed-combination", UI_MSG_ERROR);
    }
    if ($msg = CAppUI::getMsg()) {
        echo $msg;
        return;
    } else {
        CAppUI::callbackAjax('Session.unlock');
        $_SESSION['locked'] = false;
    }
}
                    $totaux["impute"]["dates"]["{$reglement->date}"] = array("count" => 0, "total" => 0.0);
                }
                $totaux["impute"]["dates"]["{$reglement->date}"]["count"]++;
                $totaux["impute"]["dates"]["{$reglement->date}"]["total"] += $reglement->montant;
            }
            if ($facture->_du_restant_patient - $reglement->montant > 0) {
                $results[$i]["warning"][] = "Paiement partiel";
            }
            // Dry run to check references
            if ($dryrun) {
                continue;
            }
            // Creation
            $existing = $reglement->_id;
            if ($msg = $reglement->store()) {
                CAppUI::setMsg($msg, UI_MSG_ERROR);
                $results[$i]["errors"][] = $msg;
                continue;
            }
            CAppUI::setMsg($existing ? "CReglement-msg-modify" : "CReglement-msg-create", UI_MSG_OK);
        }
    }
    fclose($fp);
}
CAppUI::callbackAjax('$("systemMsg").insert', CAppUI::getMsg());
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("results", $results);
$smarty->assign("totaux", $totaux);
$smarty->assign("facture_class", $facture_class);
$smarty->display("vw_rapprochement_banc.tpl");
Exemplo n.º 20
0
if (!$username) {
    CAppUI::setMsg("Auth-failed-nousername", UI_MSG_ERROR);
} else {
    if ($user->user_type == 1 && (!$ldap_connection || $allow_login_as_ldap)) {
        // If admin: no need to give a password
        $_REQUEST['loginas'] = $username;
        CAppUI::login();
    } else {
        if (!$password) {
            CAppUI::setMsg("Auth-failed-nopassword", UI_MSG_ERROR);
        } else {
            $_REQUEST['loginas'] = $username;
            if (CAppUI::conf("admin LDAP ldap_connection")) {
                $_REQUEST['passwordas'] = $password;
                CAppUI::login(true);
            } else {
                if (!CUser::checkPassword($username, $password)) {
                    CAppUI::setMsg("Auth-failed-combination", UI_MSG_ERROR);
                } else {
                    CAppUI::login(true);
                }
            }
        }
    }
}
if ($msg = CAppUI::getMsg()) {
    echo $msg;
    return;
} else {
    CAppUI::callbackAjax('UserSwitch.reload');
}
<?php

/**
 * $Id: do_duplicate_antecedent_aed.php 27291 2015-02-24 13:10:50Z aurelie17 $
 *
 * @category Patients
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision: 27291 $
 * @link     http://www.mediboard.org
 */
CCanDo::checkRead();
$antecedent_id = CValue::post("antecedent_id");
$callback = CValue::post("reload");
$antecedent = new CAntecedent();
$antecedent->load($antecedent_id);
$antecedent->annule = 1;
if ($msg = $antecedent->store()) {
    CAppUI::stepAjax($msg, UI_MSG_WARNING);
}
$atcd_new = $antecedent;
$atcd_new->_id = null;
$atcd_new->annule = 0;
if ($msg = $atcd_new->store()) {
    CAppUI::stepAjax($msg, UI_MSG_WARNING);
}
$dossier_medical = $atcd_new->loadRefDossierMedical();
CAppUI::callbackAjax("Antecedent.editAntecedents", $dossier_medical->object_id, '', $callback, $atcd_new->_id);
echo CAppUI::getMsg();
CApp::rip();