public static function call($method, $params, $sessionid = null)
 {
     global $USER_DETAILS;
     // List of methods without params
     $notifications = array('apiinfo.version' => 1);
     //-----
     // list of methods which does not require athentication
     $without_auth = array('apiinfo.version' => 1);
     //-----
     if (is_null($params) && !isset($notifications[$method])) {
         self::$result = array('error' => ZBX_API_ERROR_PARAMETERS);
         return self::$result;
     }
     list($resource, $action) = explode('.', $method);
     if (!isset($without_auth[$method])) {
         // Authentication {{{
         // compatibility mode
         if ($resource == 'user' && $action == 'authenticate') {
             $action = 'login';
         }
         //----------
         if (empty($sessionid) && ($resource != 'user' || $action != 'login')) {
             self::$result = array('error' => ZBX_API_ERROR_NO_AUTH, 'data' => 'Not authorized');
             return self::$result;
         } else {
             if (!empty($sessionid)) {
                 if (!CUser::simpleAuth($sessionid)) {
                     self::$result = array('error' => ZBX_API_ERROR_NO_AUTH, 'data' => 'Not authorized');
                     return self::$result;
                 }
                 $options = array('userids' => $USER_DETAILS['userid'], 'output' => API_OUTPUT_EXTEND, 'get_access' => 1);
                 $users = CUser::get($options);
                 $user = reset($users);
                 if ($user['api_access'] != GROUP_API_ACCESS_ENABLED) {
                     self::$result = array('error' => ZBX_API_ERROR_NO_AUTH, 'data' => 'No API access');
                     return self::$result;
                 }
             }
         }
         // }}} Authentication
     }
     unset($params['nopermissions']);
     if (!method_exists('czbxrpc', $resource)) {
         self::$result = array('error' => ZBX_API_ERROR_PARAMETERS, 'data' => 'Resource (' . $resource . ') does not exist');
         return self::$result;
     }
     $class_name = 'C' . $resource;
     if (!method_exists($class_name, $action)) {
         self::$result = array('error' => ZBX_API_ERROR_PARAMETERS, 'data' => 'Action (' . $action . ') does not exist');
         return self::$result;
     }
     call_user_func(array('czbxrpc', $resource), $action, $params);
     if (self::$result !== false || $action == 'exists') {
         self::$result = array('result' => self::$result);
     } else {
         self::$result = reset(CZBXAPI::$error);
     }
     return self::$result;
 }
 /**
  * Event method
  * 
  * @param string $message  Message
  * @param int    $actor_id Actor id
  * 
  * @return string ACK
  */
 function event($message, $actor_id = null)
 {
     $actor = null;
     $sender_soap = new CSenderSOAP();
     if ($actor_id) {
         $sender_soap->load($actor_id);
     } else {
         $sender_soap->user_id = CUser::get()->_id;
         $sender_soap->loadMatchingObject();
     }
     if ($sender_soap->_id) {
         $actor = $sender_soap;
     }
     // Dispatch EAI
     if (!($acq = CEAIDispatcher::dispatch($message, $actor))) {
         return utf8_encode(CEAIDispatcher::$xml_error);
     }
     return $acq;
 }
Example #3
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::checkAdmin();
$hours = range(0, 23);
$intervals = array("05", "10", "15", "20", "30");
$function = new CFunctions();
$function->group_id = CGroups::loadCurrent()->_id;
$functions = $function->loadMatchingList();
// Création du template
$smarty = new CSmartyDP();
$smarty->assign("hours", $hours);
$smarty->assign("date", CMbDT::date());
$smarty->assign("intervals", $intervals);
$smarty->assign("debut", CMbDT::date("+ 5 YEAR"));
$smarty->assign("limit", "100");
$smarty->assign("praticiens", CMediusers::get()->loadPraticiens());
$smarty->assign("anesths", CMediusers::get()->loadAnesthesistes());
$smarty->assign("functions_id", $functions);
$smarty->assign("user", CUser::get());
$smarty->display("configure.tpl");
Example #4
0
<?php

/**
 * $Id: vw_functional_perms.php 24154 2014-07-24 14:17:58Z kgrisel $
 *
 * @package    Mediboard
 * @subpackage admin
 * @version    $Revision: 24154 $
 * @author     SARL OpenXtrem
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 */
CCanDo::checkEdit();
$user_id = CCanDo::edit() ? CValue::getOrSession("user_id", "default") : null;
$user = CUser::get($user_id);
$prof = $user->profile_id ? CUser::get($user->profile_id) : new CUser();
if ($user_id == "default") {
    $user->_id = null;
}
$prefvalues = array("default" => CPreferences::get(null, true), "template" => $user->profile_id ? CPreferences::get($user->profile_id, true) : array(), "user" => $user->_id !== "" ? CPreferences::get($user->_id, true) : array());
// common sera toujours au debut
$prefs = array("common" => array());
// Classement par module et par permission fonctionnelle
CPreferences::loadModules(true);
foreach (CPreferences::$modules as $modname => $prefnames) {
    $module = CModule::getActive($modname);
    $canRead = $module ? CPermModule::getPermModule($module->_id, PERM_READ, $user_id) : false;
    if ($modname == "common" || $user_id == "default" || $canRead) {
        $prefs[$modname] = array();
        foreach ($prefnames as $prefname) {
            $prefs[$modname][$prefname] = array("default" => CMbArray::extract($prefvalues["default"], $prefname), "template" => CMbArray::extract($prefvalues["template"], $prefname), "user" => CMbArray::extract($prefvalues["user"], $prefname));
        }
/**
 * $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;
    }
}
Example #6
0
/**
 * $Id: $
 *
 * @category Admin
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision: 18541 $
 * @link     http://www.mediboard.org
 */
$old_pwd = CValue::post("old_pwd");
$new_pwd1 = CValue::post("new_pwd1");
$new_pwd2 = CValue::post("new_pwd2");
$callback = CValue::post("callback");
// Vérification du mot de passe actuel de l'utilisateur courant
$user = CUser::checkPassword(CUser::get()->user_username, $old_pwd, true);
// Mot de passe actuel correct
if (!$user->_id) {
    CAppUI::stepAjax("CUser-user_password-nomatch", UI_MSG_ERROR);
}
if (!$user->canChangePassword()) {
    CAppUI::stepAjax("CUser-password_change_forbidden", UI_MSG_ERROR);
}
$allow_change_password = CAppUI::conf("admin LDAP allow_change_password");
$ldap_linked = $user->isLDAPLinked();
// Si utilisateur associé au LDAP et modif de mot de passe non autorisée: ERROR
if (!$allow_change_password && $ldap_linked) {
    CAppUI::stepAjax("CUser_associate-ldap-no-password-change", UI_MSG_ERROR);
}
// Mots de passe différents
if ($new_pwd1 != $new_pwd2) {
Example #7
0
$filterForm->addItemToBottomRow(new CButton("filter_set", S_FILTER));
$filterForm->addItemToBottomRow($reset);
$alerts_wdgt->addFlicker($filterForm, CProfile::get('web.auditacts.filter.state', 1));
$scroll_div = new CDiv();
$scroll_div->setAttribute('id', 'scrollbar_cntr');
$alerts_wdgt->addFlicker($scroll_div, CProfile::get('web.auditacts.filter.state', 1));
//-------
$table = new CTableInfo(S_NO_ACTIONS_FOUND);
$table->setHeader(array(is_show_all_nodes() ? S_NODES : null, S_TIME, S_TYPE, S_STATUS, S_RETRIES_LEFT, S_RECIPIENTS, S_MESSAGE, S_ERROR));
$effectiveperiod = navigation_bar_calc('web.auditacts.timeline', 0, true);
$bstime = $_REQUEST['stime'];
$from = zbxDateToTime($_REQUEST['stime']);
$till = $from + $effectiveperiod;
$options = array('time_from' => $from, 'time_till' => $till, 'output' => API_OUTPUT_EXTEND, 'select_mediatypes' => API_OUTPUT_EXTEND, 'sortfield' => 'alertid', 'sortorder' => ZBX_SORT_DOWN, 'limit' => $config['search_limit'] + 1);
if ($_REQUEST['alias']) {
    $users = CUser::get(array('filter' => array('alias' => $_REQUEST['alias'])));
    $options['userids'] = zbx_objectValues($users, 'userid');
}
$alerts = CAlert::get($options);
// get first event for selected filters, to get starttime for timeline bar
unset($options['userids']);
unset($options['time_from']);
unset($options['time_till']);
unset($options['select_mediatypes']);
$options['limit'] = 1;
$options['sortorder'] = ZBX_SORT_UP;
$firstAlert = CAlert::get($options);
$firstAlert = reset($firstAlert);
$starttime = $firstAlert ? $firstAlert['clock'] : time() - 3600;
$paging = getPagingLine($alerts);
foreach ($alerts as $num => $row) {
    if ($ex_object->_ref_object->_id) {
        $rel_patient = $ex_object->_ref_object->loadRelPatient();
        $rel_patient->loadIPP();
    } else {
        $rel_patient = new CPatient();
        if ($preview) {
            $rel_patient->_view = "Patient exemple";
            $rel_patient->_IPP = "0123456";
            $ex_object->_ref_object->_view = CAppUI::tr($ex_object->_ref_object->_class) . " test";
        }
    }
    $ex_object->_rel_patient = $rel_patient;
}
$can_delete = false;
if ($ex_object->_id) {
    $can_delete = $ex_object->owner_id == CUser::get()->_id;
}
$can_delete = $can_delete || CModule::getInstalled("forms")->canAdmin();
// Load IPP and NDA
$ref_objects = array($ex_object->_ref_object, $ex_object->_ref_reference_object_1, $ex_object->_ref_reference_object_2);
foreach ($ref_objects as $_object) {
    if ($_object instanceof CPatient) {
        $_object->loadIPP();
        continue;
    }
    if ($_object instanceof CSejour) {
        $_object->loadNDA();
        $_object->loadRefCurrAffectation($creation_date);
        continue;
    }
}
Example #9
0
 /**
  * Build preferences for connected user, with the default/profile/user strategy
  *
  * @return void
  */
 static function buildPrefs()
 {
     // Default
     self::loadPrefs();
     // Profile
     $user = CUser::get();
     if ($user->profile_id) {
         self::loadPrefs($user->profile_id);
     }
     // User
     self::loadPrefs($user->_id);
 }
Example #10
0
<?php

/**
 * dPboard
 *
 * @category Board
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  SVN: $Id:$
 * @link     http://www.mediboard.org
 */
// Récupération des paramètres
$login = CUser::get()->user_username;
$prat_id = CUser::get()->_id;
$url = CAppUI::conf("base_url") . "/index.php?";
$param = array();
$param["m"] = "dPboard";
$param["a"] = "export_ical";
$param["suppressHeaders"] = "1";
$url .= http_build_query($param, null, "&");
// Variables de templates
$smarty = new CSmartyDP();
$smarty->assign("prat_id", $prat_id);
$smarty->assign("login", $login);
$smarty->assign("url", $url);
$smarty->display("vw_agenda.tpl");
Example #11
0
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CModule::getCanDo("soins")->needsEdit();
$transmission_id = CValue::get("transmission_id");
$data_id = CValue::get("data_id");
$action_id = CValue::get("action_id");
$result_id = CValue::get("result_id");
$sejour_id = CValue::get("sejour_id");
$object_id = CValue::get("object_id");
$object_class = CValue::get("object_class");
$libelle_ATC = CValue::get("libelle_ATC");
$refreshTrans = CValue::get("refreshTrans", 0);
$update_plan_soin = CValue::get("update_plan_soin", 0);
$user_id = CUser::get()->_id;
$transmission = new CTransmissionMedicale();
if ($transmission_id) {
    $transmission->load($transmission_id);
} else {
    if ($data_id || $action_id || $result_id) {
        $transmission->sejour_id = $sejour_id;
        // Multi-transmissions
        if ($data_id) {
            $trans = new CTransmissionMedicale();
            $trans->load($data_id);
            $trans->canEdit();
            $transmission->_text_data = $trans->text;
            $transmission->user_id = $trans->user_id;
            $transmission->date = $trans->date;
            $transmission->degre = $trans->degre;
Example #12
0
function getUserForm($userid, $profile = 0)
{
    global $ZBX_LOCALES;
    global $USER_DETAILS;
    $config = select_config();
    $frm_title = S_USER;
    if (isset($userid)) {
        /*			if(bccomp($userid,$USER_DETAILS['userid'])==0) $profile = 1;*/
        $options = array('userids' => $userid, 'output' => API_OUTPUT_EXTEND);
        if ($profile) {
            $options['nodeids'] = id2nodeid($userid);
        }
        $users = CUser::get($options);
        $user = reset($users);
        $frm_title = S_USER . ' "' . $user['alias'] . '"';
    }
    if (isset($userid) && (!isset($_REQUEST['form_refresh']) || isset($_REQUEST['register']))) {
        $alias = $user['alias'];
        $name = $user['name'];
        $surname = $user['surname'];
        $password = null;
        $password1 = null;
        $password2 = null;
        $url = $user['url'];
        $autologin = $user['autologin'];
        $autologout = $user['autologout'];
        $lang = $user['lang'];
        $theme = $user['theme'];
        $refresh = $user['refresh'];
        $rows_per_page = $user['rows_per_page'];
        $user_type = $user['type'];
        if ($autologout > 0) {
            $_REQUEST['autologout'] = $autologout;
        }
        $user_groups = array();
        $user_medias = array();
        $options = array('userids' => $userid, 'output' => API_OUTPUT_SHORTEN);
        $user_groups = CUserGroup::get($options);
        $user_groups = zbx_objectValues($user_groups, 'usrgrpid');
        $user_groups = zbx_toHash($user_groups);
        $db_medias = DBselect('SELECT m.* FROM media m WHERE m.userid=' . $userid);
        while ($db_media = DBfetch($db_medias)) {
            $user_medias[] = array('mediaid' => $db_media['mediaid'], 'mediatypeid' => $db_media['mediatypeid'], 'period' => $db_media['period'], 'sendto' => $db_media['sendto'], 'severity' => $db_media['severity'], 'active' => $db_media['active']);
        }
        $messages = getMessageSettings();
    } else {
        $alias = get_request('alias', '');
        $name = get_request('name', '');
        $surname = get_request('surname', '');
        $password = null;
        $password1 = get_request('password1', '');
        $password2 = get_request('password2', '');
        $url = get_request('url', '');
        $autologin = get_request('autologin', 0);
        $autologout = get_request('autologout', 90);
        $lang = get_request('lang', 'en_gb');
        $theme = get_request('theme', 'default.css');
        $refresh = get_request('refresh', 30);
        $rows_per_page = get_request('rows_per_page', 50);
        $user_type = get_request('user_type', USER_TYPE_ZABBIX_USER);
        $user_groups = get_request('user_groups', array());
        $change_password = get_request('change_password', null);
        $user_medias = get_request('user_medias', array());
        $messages = get_request('messages', array());
        if (!isset($messages['enabled'])) {
            $messages['enabled'] = 0;
        }
        if (!isset($messages['sounds.recovery'])) {
            $messages['sounds.recovery'] = 0;
        }
        if (!isset($messages['triggers.recovery'])) {
            $messages['triggers.recovery'] = 0;
        }
        if (!isset($messages['triggers.severities'])) {
            $messages['triggers.severities'] = array();
        }
        $pMsgs = getMessageSettings();
        $messages = array_merge($pMsgs, $messages);
    }
    if ($autologin || !isset($_REQUEST['autologout'])) {
        $autologout = 0;
    } else {
        if (isset($_REQUEST['autologout']) && $autologout < 90) {
            $autologout = 90;
        }
    }
    $perm_details = get_request('perm_details', 0);
    $media_types = array();
    $media_type_ids = array();
    foreach ($user_medias as $one_media) {
        $media_type_ids[$one_media['mediatypeid']] = 1;
    }
    if (count($media_type_ids) > 0) {
        $sql = 'SELECT mt.mediatypeid, mt.description ' . ' FROM media_type mt ' . ' WHERE mt.mediatypeid IN (' . implode(',', array_keys($media_type_ids)) . ')';
        $db_media_types = DBselect($sql);
        while ($db_media_type = DBfetch($db_media_types)) {
            $media_types[$db_media_type['mediatypeid']] = $db_media_type['description'];
        }
    }
    $frmUser = new CFormTable($frm_title);
    $frmUser->setName('user_form');
    $frmUser->setHelp('web.users.php');
    $frmUser->addVar('config', get_request('config', 0));
    if (isset($userid)) {
        $frmUser->addVar('userid', $userid);
    }
    if ($profile == 0) {
        $frmUser->addRow(S_ALIAS, new CTextBox('alias', $alias, 40));
        $frmUser->addRow(S_NAME, new CTextBox('name', $name, 40));
        $frmUser->addRow(S_SURNAME, new CTextBox('surname', $surname, 40));
    }
    $auth_type = isset($userid) ? get_user_system_auth($userid) : $config['authentication_type'];
    if (ZBX_AUTH_INTERNAL == $auth_type) {
        if (!isset($userid) || isset($change_password)) {
            $frmUser->addRow(S_PASSWORD, new CPassBox('password1', $password1, 20));
            $frmUser->addRow(S_PASSWORD_ONCE_AGAIN, new CPassBox('password2', $password2, 20));
            if (isset($change_password)) {
                $frmUser->addVar('change_password', $change_password);
            }
        } else {
            $passwd_but = new CButton('change_password', S_CHANGE_PASSWORD);
            if ($alias == ZBX_GUEST_USER) {
                $passwd_but->setAttribute('disabled', 'disabled');
            }
            $frmUser->addRow(S_PASSWORD, $passwd_but);
        }
    }
    if ($profile == 0) {
        $frmUser->addVar('user_groups', $user_groups);
        if (isset($userid) && bccomp($USER_DETAILS['userid'], $userid) == 0) {
            $frmUser->addVar('user_type', $user_type);
        } else {
            $cmbUserType = new CComboBox('user_type', $user_type, $perm_details ? 'submit();' : null);
            $cmbUserType->addItem(USER_TYPE_ZABBIX_USER, user_type2str(USER_TYPE_ZABBIX_USER));
            $cmbUserType->addItem(USER_TYPE_ZABBIX_ADMIN, user_type2str(USER_TYPE_ZABBIX_ADMIN));
            $cmbUserType->addItem(USER_TYPE_SUPER_ADMIN, user_type2str(USER_TYPE_SUPER_ADMIN));
            $frmUser->addRow(S_USER_TYPE, $cmbUserType);
        }
        $lstGroups = new CListBox('user_groups_to_del[]', null, 10);
        $lstGroups->attributes['style'] = 'width: 320px';
        $options = array('usrgrpids' => $user_groups, 'output' => API_OUTPUT_EXTEND);
        $groups = CUserGroup::get($options);
        order_result($groups, 'name');
        foreach ($groups as $num => $group) {
            $lstGroups->addItem($group['usrgrpid'], $group['name']);
        }
        $frmUser->addRow(S_GROUPS, array($lstGroups, BR(), new CButton('add_group', S_ADD, 'return PopUp("popup_usrgrp.php?dstfrm=' . $frmUser->getName() . '&list_name=user_groups_to_del[]&var_name=user_groups",450, 450);'), SPACE, count($user_groups) > 0 ? new CButton('del_user_group', S_DELETE_SELECTED) : null));
    }
    $cmbLang = new CComboBox('lang', $lang);
    foreach ($ZBX_LOCALES as $loc_id => $loc_name) {
        $cmbLang->addItem($loc_id, $loc_name);
    }
    $frmUser->addRow(S_LANGUAGE, $cmbLang);
    $cmbTheme = new CComboBox('theme', $theme);
    $cmbTheme->addItem(ZBX_DEFAULT_CSS, S_SYSTEM_DEFAULT);
    $cmbTheme->addItem('css_ob.css', S_ORIGINAL_BLUE);
    $cmbTheme->addItem('css_bb.css', S_BLACK_AND_BLUE);
    $cmbTheme->addItem('css_od.css', S_DARK_ORANGE);
    $frmUser->addRow(S_THEME, $cmbTheme);
    $script = "javascript:\n\t\t\tvar autologout_visible = document.getElementById('autologout_visible');\n\t\t\tvar autologout = document.getElementById('autologout');\n\t\t\tif(this.checked){\n\t\t\t\tif(autologout_visible.checked){\n\t\t\t\t\tautologout_visible.checked = false;\n\t\t\t\t\tautologout_visible.onclick();\n\t\t\t\t}\n\t\t\t\tautologout_visible.disabled = true;\n\t\t\t}\n\t\t\telse{\n\t\t\t\tautologout_visible.disabled = false;\n\t\t\t}";
    $chkbx_autologin = new CCheckBox("autologin", $autologin, $script, 1);
    $chkbx_autologin->setAttribute('autocomplete', 'off');
    $frmUser->addRow(S_AUTO_LOGIN, $chkbx_autologin);
    $script = "javascript: var autologout = document.getElementById('autologout');\n\t\t\t\t\tif(this.checked) autologout.disabled = false;\n\t\t\t\t\telse autologout.disabled = true;";
    $autologoutCheckBox = new CCheckBox('autologout_visible', $autologout == 0 ? 'no' : 'yes', $script);
    $autologoutTextBox = new CNumericBox("autologout", $autologout == 0 ? '90' : $autologout, 4);
    // if autologout is disabled
    if ($autologout == 0) {
        $autologoutTextBox->setAttribute('disabled', 'disabled');
    }
    if ($autologin != 0) {
        $autologoutCheckBox->setAttribute('disabled', 'disabled');
    }
    $frmUser->addRow(S_AUTO_LOGOUT, array($autologoutCheckBox, $autologoutTextBox));
    $frmUser->addRow(S_SCREEN_REFRESH, new CNumericBox('refresh', $refresh, 4));
    $frmUser->addRow(S_ROWS_PER_PAGE, new CNumericBox('rows_per_page', $rows_per_page, 6));
    $frmUser->addRow(S_URL_AFTER_LOGIN, new CTextBox("url", $url, 50));
    //view Media Settings for users above "User" +++
    if (uint_in_array($USER_DETAILS['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN))) {
        $frmUser->addVar('user_medias', $user_medias);
        $media_table = new CTableInfo(S_NO_MEDIA_DEFINED);
        foreach ($user_medias as $id => $one_media) {
            if (!isset($one_media['active']) || $one_media['active'] == 0) {
                $status = new CLink(S_ENABLED, '#', 'enabled');
                $status->onClick('return create_var("' . $frmUser->getName() . '","disable_media",' . $id . ', true);');
            } else {
                $status = new CLink(S_DISABLED, '#', 'disabled');
                $status->onClick('return create_var("' . $frmUser->getName() . '","enable_media",' . $id . ', true);');
            }
            $media_url = '?dstfrm=' . $frmUser->getName() . '&media=' . $id . '&mediatypeid=' . $one_media['mediatypeid'] . '&sendto=' . urlencode($one_media['sendto']) . '&period=' . $one_media['period'] . '&severity=' . $one_media['severity'] . '&active=' . $one_media['active'];
            $media_table->addRow(array(new CCheckBox('user_medias_to_del[' . $id . ']', null, null, $id), new CSpan($media_types[$one_media['mediatypeid']], 'nowrap'), new CSpan($one_media['sendto'], 'nowrap'), new CSpan($one_media['period'], 'nowrap'), media_severity2str($one_media['severity']), $status, new CButton('edit_media', S_EDIT, 'javascript: return PopUp("popup_media.php' . $media_url . '",550,400);')));
        }
        $frmUser->addRow(S_MEDIA, array($media_table, new CButton('add_media', S_ADD, 'javascript: return PopUp("popup_media.php?dstfrm=' . $frmUser->getName() . '",550,400);'), SPACE, count($user_medias) > 0 ? new CButton('del_user_media', S_DELETE_SELECTED) : null));
    }
    if (0 == $profile) {
        $frmUser->addVar('perm_details', $perm_details);
        $link = new CSpan($perm_details ? S_HIDE : S_SHOW, 'link');
        $link->onClick("return create_var('" . $frmUser->getName() . "','perm_details'," . ($perm_details ? 0 : 1) . ", true);");
        $resources_list = array(S_RIGHTS_OF_RESOURCES, SPACE . '(', $link, ')');
        $frmUser->addSpanRow($resources_list, 'right_header');
        if ($perm_details) {
            $group_ids = array_values($user_groups);
            if (count($group_ids) == 0) {
                $group_ids = array(-1);
            }
            $db_rights = DBselect('SELECT * FROM rights r WHERE ' . DBcondition('r.groupid', $group_ids));
            $tmp_perm = array();
            while ($db_right = DBfetch($db_rights)) {
                if (isset($tmp_perm[$db_right['id']])) {
                    $tmp_perm[$db_right['id']] = min($tmp_perm[$db_right['id']], $db_right['permission']);
                } else {
                    $tmp_perm[$db_right['id']] = $db_right['permission'];
                }
            }
            $user_rights = array();
            foreach ($tmp_perm as $id => $perm) {
                array_push($user_rights, array('id' => $id, 'permission' => $perm));
            }
            //SDI($user_rights);
            //SDI($user_type);
            $frmUser->addSpanRow(get_rights_of_elements_table($user_rights, $user_type));
        }
    }
    if ($profile) {
        $msgVisibility = array('1' => array('messages[timeout]', 'messages[sounds.repeat]', 'messages[sounds.recovery]', 'messages[triggers.recovery]', 'timeout_row', 'repeat_row', 'triggers_row'));
        $frmUser->addRow(S_GUI_MESSAGING, new CCheckBox('messages[enabled]', $messages['enabled'], null, 1));
        $newRow = $frmUser->addRow(S_MESSAGE_TIMEOUT . SPACE . '(' . S_SECONDS_SMALL . ')', new CNumericBox("messages[timeout]", $messages['timeout'], 5));
        $newRow->setAttribute('id', 'timeout_row');
        $repeatSound = new CComboBox('messages[sounds.repeat]', $messages['sounds.repeat'], 'javascript: if(IE) submit();');
        $repeatSound->setAttribute('id', 'messages[sounds.repeat]');
        $repeatSound->addItem(1, S_ONCE);
        $repeatSound->addItem(10, '10 ' . S_SECONDS);
        $repeatSound->addItem(-1, S_MESSAGE_TIMEOUT);
        $newRow = $frmUser->addRow(S_PLAY_SOUND, $repeatSound);
        $newRow->setAttribute('id', 'repeat_row');
        // trigger sounds
        $severities = array(TRIGGER_SEVERITY_NOT_CLASSIFIED, TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER);
        $zbxSounds = getSounds();
        $triggers = new CTable('', 'invisible');
        $soundList = new CComboBox('messages[sounds.recovery]', $messages['sounds.recovery']);
        foreach ($zbxSounds as $filename => $file) {
            $soundList->addItem($file, $filename);
        }
        $resolved = array(new CCheckBox('messages[triggers.recovery]', $messages['triggers.recovery'], null, 1), S_RECOVERY, $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds.recovery]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false));
        $triggers->addRow($resolved);
        foreach ($severities as $snum => $severity) {
            $soundList = new CComboBox('messages[sounds.' . $severity . ']', $messages['sounds.' . $severity]);
            foreach ($zbxSounds as $filename => $file) {
                $soundList->addItem($file, $filename);
            }
            $triggers->addRow(array(new CCheckBox('messages[triggers.severities][' . $severity . ']', isset($messages['triggers.severities'][$severity]), null, 1), getSeverityCaption($severity), $soundList, new CButton('start', S_PLAY, "javascript: testUserSound('messages[sounds." . $severity . "]');", false), new CButton('stop', S_STOP, 'javascript: AudioList.stopAll();', false)));
            zbx_subarray_push($msgVisibility, 1, 'messages[triggers.severities][' . $severity . ']');
            zbx_subarray_push($msgVisibility, 1, 'messages[sounds.' . $severity . ']');
        }
        $newRow = $frmUser->addRow(S_TRIGGER_SEVERITY, $triggers);
        $newRow->setAttribute('id', 'triggers_row');
        zbx_add_post_js("var userMessageSwitcher = new CViewSwitcher('messages[enabled]', 'click', " . zbx_jsvalue($msgVisibility, true) . ");");
    }
    $frmUser->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($userid) && $profile == 0) {
        $frmUser->addItemToBottomRow(SPACE);
        $delete_b = new CButtonDelete(S_DELETE_SELECTED_USER_Q, url_param("form") . url_param("config") . url_param("userid"));
        if (bccomp($USER_DETAILS['userid'], $userid) == 0) {
            $delete_b->setAttribute('disabled', 'disabled');
        }
        $frmUser->addItemToBottomRow($delete_b);
    }
    $frmUser->addItemToBottomRow(SPACE);
    $frmUser->addItemToBottomRow(new CButtonCancel(url_param("config")));
    return $frmUser;
}
<?php

/**
 * $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
 */
CCanDo::checkEdit();
// Récuperation de l'utilisateur sélectionné
$user_id = CValue::getOrSession("user_id");
$user = $user_id == "0" ? new CUser() : CUser::get($user_id);
// Récuperation des utilisateurs recherchés
$user_username = CValue::getOrSession("user_username");
$user_last_name = CValue::getOrSession("user_last_name");
$user_first_name = CValue::getOrSession("user_first_name");
$user_type = CValue::getOrSession("user_type");
$template = CValue::getOrSession("template");
// Where clause
$where = null;
if ($user_last_name) {
    $where["user_last_name"] = "LIKE '{$user_last_name}%'";
}
if ($user_first_name) {
    $where["user_first_name"] = "LIKE '{$user_first_name}%'";
}
if ($user_username) {
 /**
  * Get Media types data
  *
  * {@source}
  * @access public
  * @static
  * @since 1.8
  * @version 1
  *
  * @param _array $options
  * @param array $options['nodeids'] filter by Node IDs
  * @param array $options['mediatypeids'] filter by Mediatype IDs
  * @param boolean $options['type'] filter by Mediatype type [ USER_TYPE_ZABBIX_USER: 1, USER_TYPE_ZABBIX_ADMIN: 2, USER_TYPE_SUPER_ADMIN: 3 ]
  * @param boolean $options['output'] output only Mediatype IDs if not set.
  * @param boolean $options['count'] output only count of objects in result. ( result returned in property 'rowscount' )
  * @param string $options['pattern'] filter by Host name containing only give pattern
  * @param int $options['limit'] output will be limited to given number
  * @param string $options['sortfield'] output will be sorted by given property [ 'mediatypeid', 'alias' ]
  * @param string $options['sortorder'] output will be sorted in given order [ 'ASC', 'DESC' ]
  * @return array
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $result = array();
     $nodeCheck = false;
     $user_type = $USER_DETAILS['type'];
     $userid = $USER_DETAILS['userid'];
     $sort_columns = array('mediatypeid');
     // allowed columns for sorting
     $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     // allowed output options for [ select_* ] params
     $sql_parts = array('select' => array('media_type' => 'mt.mediatypeid'), 'from' => array('media_type' => 'media_type mt'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('nodeids' => null, 'mediatypeids' => null, 'mediaids' => null, 'userids' => null, 'editable' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'extendoutput' => null, 'output' => API_OUTPUT_REFER, 'select_users' => null, 'select_medias' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($def_options, $options);
     if (!is_null($options['extendoutput'])) {
         $options['output'] = API_OUTPUT_EXTEND;
         if (!is_null($options['select_users'])) {
             $options['select_users'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_medias'])) {
             $options['select_medias'] = API_OUTPUT_EXTEND;
         }
     }
     // PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $user_type) {
     } else {
         if (is_null($options['editable']) && $USER_DETAILS['type'] == USER_TYPE_ZABBIX_ADMIN) {
         } else {
             if (!is_null($options['editable']) || $USER_DETAILS['type'] != USER_TYPE_SUPER_ADMIN) {
                 return array();
             }
         }
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // mediatypeids
     if (!is_null($options['mediatypeids'])) {
         zbx_value2array($options['mediatypeids']);
         $sql_parts['where'][] = DBcondition('mt.mediatypeid', $options['mediatypeids']);
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('mt.mediatypeid', $nodeids);
         }
     }
     // mediaids
     if (!is_null($options['mediaids'])) {
         zbx_value2array($options['mediaids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['mediaid'] = 'm.mediaid';
         }
         $sql_parts['from']['medias'] = 'medias m';
         $sql_parts['where'][] = DBcondition('m.mediaid', $options['mediaids']);
         $sql_parts['where']['mmt'] = 'm.mediatypeid=mt.mediatypeid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('m.mediaid', $nodeids);
         }
     }
     // userids
     if (!is_null($options['userids'])) {
         zbx_value2array($options['userids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['userid'] = 'm.userid';
         }
         $sql_parts['from']['medias'] = 'medias m';
         $sql_parts['where'][] = DBcondition('m.userid', $options['userids']);
         $sql_parts['where']['mmt'] = 'm.mediatypeid=mt.mediatypeid';
         if (!$nodeCheck) {
             $nodeCheck = true;
             $sql_parts['where'][] = DBin_node('m.userid', $nodeids);
         }
     }
     // node check !!!!!
     // should last, after all ****IDS checks
     if (!$nodeCheck) {
         $nodeCheck = true;
         $sql_parts['where'][] = DBin_node('mt.mediatypeid', $nodeids);
     }
     // filter
     if (is_array($options['filter'])) {
         zbx_db_filter('media_type mt', $options, $sql_parts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('media_type mt', $options, $sql_parts);
     }
     // extendoutput
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sql_parts['select']['media_type'] = 'mt.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sql_parts['select'] = array('count(DISTINCT mt.mediatypeid) as rowscount');
         //groupCount
         if (!is_null($options['groupCount'])) {
             foreach ($sql_parts['group'] as $key => $fields) {
                 $sql_parts['select'][$key] = $fields;
             }
         }
     }
     // order
     // restrict not allowed columns for sorting
     $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
     if (!zbx_empty($options['sortfield'])) {
         $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
         $sql_parts['order'][] = 'mt.' . $options['sortfield'] . ' ' . $sortorder;
         if (!str_in_array('mt.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('mt.*', $sql_parts['select'])) {
             $sql_parts['select'][] = 'mt.' . $options['sortfield'];
         }
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     //-------
     $mediatypeids = array();
     $sql_parts['select'] = array_unique($sql_parts['select']);
     $sql_parts['from'] = array_unique($sql_parts['from']);
     $sql_parts['where'] = array_unique($sql_parts['where']);
     $sql_parts['group'] = array_unique($sql_parts['group']);
     $sql_parts['order'] = array_unique($sql_parts['order']);
     $sql_select = '';
     $sql_from = '';
     $sql_where = '';
     $sql_group = '';
     $sql_order = '';
     if (!empty($sql_parts['select'])) {
         $sql_select .= implode(',', $sql_parts['select']);
     }
     if (!empty($sql_parts['from'])) {
         $sql_from .= implode(',', $sql_parts['from']);
     }
     if (!empty($sql_parts['where'])) {
         $sql_where .= implode(' AND ', $sql_parts['where']);
     }
     if (!empty($sql_parts['group'])) {
         $sql_where .= ' GROUP BY ' . implode(',', $sql_parts['group']);
     }
     if (!empty($sql_parts['order'])) {
         $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
     }
     $sql_limit = $sql_parts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . $sql_where . $sql_group . $sql_order;
     $res = DBselect($sql, $sql_limit);
     while ($mediatype = DBfetch($res)) {
         if (!is_null($options['countOutput'])) {
             if (!is_null($options['groupCount'])) {
                 $result[] = $mediatype;
             } else {
                 $result = $mediatype['rowscount'];
             }
         } else {
             $mediatypeids[$mediatype['mediatypeid']] = $mediatype['mediatypeid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$mediatype['mediatypeid']] = array('mediatypeid' => $mediatype['mediatypeid']);
             } else {
                 if (!isset($result[$mediatype['mediatypeid']])) {
                     $result[$mediatype['mediatypeid']] = array();
                 }
                 // mediaids
                 if (isset($mediatype['mediaid']) && is_null($options['select_medias'])) {
                     if (!isset($result[$mediatype['mediatypeid']]['medias'])) {
                         $result[$mediatype['mediatypeid']]['medias'] = array();
                     }
                     $result[$mediatype['mediatypeid']]['medias'][] = array('mediaid' => $mediatype['mediaid']);
                     unset($mediatype['mediaid']);
                 }
                 // userids
                 if (isset($mediatype['userid']) && is_null($options['select_users'])) {
                     if (!isset($result[$mediatype['mediatypeid']]['users'])) {
                         $result[$mediatype['mediatypeid']]['users'] = array();
                     }
                     $result[$mediatype['mediatypeid']]['users'][] = array('userid' => $mediatype['userid']);
                     unset($mediatype['userid']);
                 }
                 $result[$mediatype['mediatypeid']] += $mediatype;
             }
         }
     }
     Copt::memoryPick();
     if (!is_null($options['countOutput'])) {
         if (is_null($options['preservekeys'])) {
             $result = zbx_cleanHashes($result);
         }
         return $result;
     }
     // Adding Objects
     // Adding users
     if (!is_null($options['select_users']) && str_in_array($options['select_users'], $subselects_allowed_outputs)) {
         $obj_params = array('output' => $options['select_users'], 'mediatypeids' => $mediatypeids, 'preservekeys' => 1);
         $users = CUser::get($obj_params);
         foreach ($users as $userid => $user) {
             $umediatypes = $user['mediatypes'];
             unset($user['mediatypes']);
             foreach ($umediatypes as $num => $mediatype) {
                 $result[$mediatype['mediatypeid']]['users'][] = $user;
             }
         }
     }
     // TODO
     // Adding medias (need media class)
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Example #15
0
 * $Id$
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkRead();
// Minute courante
$time = CMbDT::time();
$minute = intval(CMbDT::transform($time, null, "%M"));
$hour = intval(CMbDT::transform($time, null, "%H"));
// Opératue de l'envoi
$user = new CUser();
$user->user_username = CValue::get("username", CUser::get()->user_username);
$user->user_password = CValue::get("password");
if (!$user->user_password) {
    CAppUI::stepMessage(UI_MSG_WARNING, "CViewSender-send-no-password");
}
// Chargement des senders
$sender = new CViewSender();
$where = array("active" => "= '1'");
/** @var CViewSender[] $senders */
$senders = $sender->loadList($where, "name");
// Envoi de vues
foreach ($senders as $_sender) {
    $_sender->makeUrl($user);
    if (!$_sender->getActive($minute, $hour)) {
        unset($senders[$_sender->_id]);
        continue;
Example #16
0
 /**
  * Gets the permission on the module
  *
  * @param CStoredObject $object        Object to load the permissions of
  * @param int           $permType      Permission level
  * @param CStoredObject $defaultObject Default object to load the permissions from
  * @param int           $user_id       User ID
  *
  * @return bool
  */
 static function getPermObject(CStoredObject $object, $permType, $defaultObject = null, $user_id = null)
 {
     $user = CUser::get($user_id);
     // Shorteners
     $class = $object->_class;
     $id = $object->_id;
     // Use permission query cache when available
     if (isset(self::$users_cache[$user->_id][$class][$id])) {
         return self::$users_cache[$user->_id][$class][$id] >= $permType;
     }
     // New cached permissions system : DO NOT REMOVE
     if (is_array(self::$users_perms)) {
         self::buildUser($user->_id);
         $perms = self::$users_perms[$user->_id];
         // Object specific, or Class specific, or Module generic
         $perm = isset($perms[$class][$id]) ? $perms[$class][$id] : (isset($perms[$class]["all"]) ? $perms[$class]["all"] : "module");
         // In case of module check, first build module cache, then get value from cache
         if ($perm == "module") {
             $mod_id = $object->_ref_module->_id;
             CPermModule::getPermModule($mod_id, $permType, $user->_id);
             $perm = CPermModule::$users_cache[$user->_id][$mod_id]["permission"];
         }
         self::$users_cache[$user->_id][$class][$id] = $perm;
         return $perm >= $permType;
     }
     global $userPermsObjects;
     $object_class = $object->_class;
     $object_id = $object->_id;
     if (isset($userPermsObjects[$object_class][$object_id])) {
         return $userPermsObjects[$object_class][$object_id]->permission >= $permType;
     }
     if (isset($userPermsObjects[$object_class][0])) {
         return $userPermsObjects[$object_class][0]->permission >= $permType;
     }
     return $defaultObject != null ? $defaultObject->getPerm($permType) : $object->_ref_module->getPerm($permType);
 }
    /**
     * Get UserGroups
     *
     * {@source}
     * @access public
     * @static
     * @since 1.8
     * @version 1
     *
     * @param _array $options
     * @param array $options['nodeids'] Node IDs
     * @param array $options['usrgrpids'] UserGroup IDs
     * @param array $options['userids'] User IDs
     * @param boolean $options['status']
     * @param boolean $options['with_gui_access']
     * @param boolean $options['with_api_access']
     * @param boolean $options['select_users']
     * @param int $options['extendoutput']
     * @param int $options['count']
     * @param string $options['pattern']
     * @param int $options['limit'] limit selection
     * @param string $options['order']
     * @return array
     */
    public static function get($options = array())
    {
        global $USER_DETAILS;
        $result = array();
        $user_type = $USER_DETAILS['type'];
        $userid = $USER_DETAILS['userid'];
        $sort_columns = array('usrgrpid', 'name');
        // allowed columns for sorting
        $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
        // allowed output options for [ select_* ] params
        $sql_parts = array('select' => array('usrgrp' => 'g.usrgrpid'), 'from' => array('usrgrp' => 'usrgrp g'), 'where' => array(), 'order' => array(), 'limit' => null);
        $def_options = array('nodeids' => null, 'usrgrpids' => null, 'userids' => null, 'status' => null, 'with_gui_access' => null, 'with_api_access' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'extendoutput' => null, 'editable' => null, 'output' => API_OUTPUT_REFER, 'select_users' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
        $options = zbx_array_merge($def_options, $options);
        if (!is_null($options['extendoutput'])) {
            $options['output'] = API_OUTPUT_EXTEND;
            if (!is_null($options['select_users'])) {
                $options['select_users'] = API_OUTPUT_EXTEND;
            }
        }
        // PERMISSION CHECK
        if (USER_TYPE_SUPER_ADMIN == $user_type) {
        } else {
            if (is_null($options['editable']) && $USER_DETAILS['type'] == USER_TYPE_ZABBIX_ADMIN) {
                $sql_parts['where'][] = 'g.usrgrpid IN (' . ' SELECT uug.usrgrpid' . ' FROM users_groups uug' . ' WHERE uug.userid=' . $USER_DETAILS['userid'] . ' )';
            } else {
                if (!is_null($options['editable']) && $USER_DETAILS['type'] != USER_TYPE_SUPER_ADMIN) {
                    return array();
                }
            }
        }
        // nodeids
        $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
        // usrgrpids
        if (!is_null($options['usrgrpids'])) {
            zbx_value2array($options['usrgrpids']);
            $sql_parts['where'][] = DBcondition('g.usrgrpid', $options['usrgrpids']);
        }
        // userids
        if (!is_null($options['userids'])) {
            zbx_value2array($options['userids']);
            if ($options['output'] != API_OUTPUT_SHORTEN) {
                $sql_parts['select']['userid'] = 'ug.userid';
            }
            $sql_parts['from']['users_groups'] = 'users_groups ug';
            $sql_parts['where'][] = DBcondition('ug.userid', $options['userids']);
            $sql_parts['where']['gug'] = 'g.usrgrpid=ug.usrgrpid';
        }
        // status
        if (!is_null($options['status'])) {
            $sql_parts['where'][] = 'g.users_status=' . $options['status'];
        }
        // with_gui_access
        if (!is_null($options['with_gui_access'])) {
            $sql_parts['where'][] = 'g.gui_access=' . GROUP_GUI_ACCESS_ENABLED;
        }
        // with_api_access
        if (!is_null($options['with_api_access'])) {
            $sql_parts['where'][] = 'g.api_access=' . GROUP_API_ACCESS_ENABLED;
        }
        // extendoutput
        if ($options['output'] == API_OUTPUT_EXTEND) {
            $sql_parts['select']['usrgrp'] = 'g.*';
        }
        // countOutput
        if (!is_null($options['countOutput'])) {
            $options['sortfield'] = '';
            $sql_parts['select'] = array('count(g.usrgrpid) as rowscount');
        }
        // filter
        if (is_array($options['filter'])) {
            zbx_db_filter('usrgrp g', $options, $sql_parts);
        }
        // search
        if (is_array($options['search'])) {
            zbx_db_search('usrgrp g', $options, $sql_parts);
        }
        // order
        // restrict not allowed columns for sorting
        $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
        if (!zbx_empty($options['sortfield'])) {
            $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
            $sql_parts['order'][] = 'g.' . $options['sortfield'] . ' ' . $sortorder;
            if (!str_in_array('g.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('g.*', $sql_parts['select'])) {
                $sql_parts['select'][] = 'g.' . $options['sortfield'];
            }
        }
        // limit
        if (zbx_ctype_digit($options['limit']) && $options['limit']) {
            $sql_parts['limit'] = $options['limit'];
        }
        //-------
        $usrgrpids = array();
        $sql_parts['select'] = array_unique($sql_parts['select']);
        $sql_parts['from'] = array_unique($sql_parts['from']);
        $sql_parts['where'] = array_unique($sql_parts['where']);
        $sql_parts['order'] = array_unique($sql_parts['order']);
        $sql_select = '';
        $sql_from = '';
        $sql_where = '';
        $sql_order = '';
        if (!empty($sql_parts['select'])) {
            $sql_select .= implode(',', $sql_parts['select']);
        }
        if (!empty($sql_parts['from'])) {
            $sql_from .= implode(',', $sql_parts['from']);
        }
        if (!empty($sql_parts['where'])) {
            $sql_where .= ' AND ' . implode(' AND ', $sql_parts['where']);
        }
        if (!empty($sql_parts['order'])) {
            $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
        }
        $sql_limit = $sql_parts['limit'];
        $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . '
				FROM ' . $sql_from . '
				WHERE ' . DBin_node('g.usrgrpid', $nodeids) . $sql_where . $sql_order;
        //SDI($sql);
        $res = DBselect($sql, $sql_limit);
        while ($usrgrp = DBfetch($res)) {
            if ($options['countOutput']) {
                $result = $usrgrp['rowscount'];
            } else {
                $usrgrpids[$usrgrp['usrgrpid']] = $usrgrp['usrgrpid'];
                if ($options['output'] == API_OUTPUT_SHORTEN) {
                    $result[$usrgrp['usrgrpid']] = array('usrgrpid' => $usrgrp['usrgrpid']);
                } else {
                    if (!isset($result[$usrgrp['usrgrpid']])) {
                        $result[$usrgrp['usrgrpid']] = array();
                    }
                    if (!is_null($options['select_users']) && !isset($result[$usrgrp['usrgrpid']]['users'])) {
                        $result[$usrgrp['usrgrpid']]['users'] = array();
                    }
                    // groupids
                    if (isset($usrgrp['userid']) && is_null($options['select_users'])) {
                        if (!isset($result[$usrgrp['usrgrpid']]['users'])) {
                            $result[$usrgrp['usrgrpid']]['users'] = array();
                        }
                        $result[$usrgrp['usrgrpid']]['users'][] = array('userid' => $usrgrp['userid']);
                        unset($usrgrp['userid']);
                    }
                    $result[$usrgrp['usrgrpid']] += $usrgrp;
                }
            }
        }
        if (!is_null($options['countOutput'])) {
            if (is_null($options['preservekeys'])) {
                $result = zbx_cleanHashes($result);
            }
            return $result;
        }
        // Adding Objects
        // Adding users
        if (!is_null($options['select_users']) && str_in_array($options['select_users'], $subselects_allowed_outputs)) {
            $obj_params = array('output' => $options['select_users'], 'usrgrpids' => $usrgrpids, 'get_access' => $options['select_users'] == API_OUTPUT_EXTEND ? true : null, 'preservekeys' => 1);
            $users = CUser::get($obj_params);
            foreach ($users as $userid => $user) {
                $uusrgrps = $user['usrgrps'];
                unset($user['usrgrps']);
                foreach ($uusrgrps as $num => $usrgrp) {
                    $result[$usrgrp['usrgrpid']]['users'][] = $user;
                }
            }
        }
        // removing keys (hash -> array)
        if (is_null($options['preservekeys'])) {
            $result = zbx_cleanHashes($result);
        }
        return $result;
    }
 /**
  * Gets the specifed access
  *
  * @param string $field    The type of acces to get information about
  * @param int    $mod_id   Module ID
  * @param int    $permType Permission level
  * @param int    $user_id  User ID
  *
  * @return bool
  */
 static function getInfoModule($field, $mod_id, $permType = null, $user_id = null)
 {
     $user = CUser::get($user_id);
     // Use permission query cache when available
     if (isset(self::$users_cache[$user->_id][$mod_id])) {
         return self::$users_cache[$user->_id][$mod_id][$field] >= $permType;
     }
     // New cached permissions system : DO NOT REMOVE
     if (is_array(self::$users_perms)) {
         self::buildUser($user->_id);
         $perms = self::$users_perms[$user->_id];
         // Module specific, or All modules, or DENY
         $perm = isset($perms[$mod_id]) ? $perms[$mod_id] : (isset($perms["all"]) ? $perms["all"] : self::$pair_deny);
         // Register cache
         self::$users_cache[$user->_id][$mod_id] = $perm;
         return $permType === null ? $perm[$field] : $perm[$field] >= $permType;
     }
     // Old permission system
     global $userPermsModules;
     $result = PERM_DENY;
     if ($user_id !== null) {
         $perms = CPermModule::loadUserPerms($user_id);
     } else {
         $perms =& $userPermsModules;
     }
     if (isset($perms[0])) {
         $result = $perms[0]->{$field};
     }
     if (isset($perms[$mod_id])) {
         if (!$mod_id) {
             $result = $perms[0]->{$field};
         } else {
             $result = $perms[$mod_id]->{$field};
         }
     }
     return $result >= $permType;
 }
Example #19
0
/**
 * User log by user stats
 * (Create, Update / Delete)
 *
 * @param string $startx   Datetime where the search starts
 * @param string $endx     Datetime where the search ends
 * @param string $interval Type of interval (day, week, 8 weeks, year, 4 years, 20 years)
 * @param int    $user_id  User identifier
 *
 * @return array
 */
function graphUserLog($startx, $endx, $interval, $user_id)
{
    switch ($interval) {
        case "one-day":
            $step = "+1 HOUR";
            $period_format = "%Hh";
            break;
        case "one-week":
            $step = "+1 HOUR";
            $period_format = "%d %H";
            break;
        case "height-weeks":
            $step = "+1 DAY";
            $period_format = "%d/%m";
            break;
        case "one-year":
            $step = "+1 WEEK";
            $period_format = "%U";
            break;
        case "four-years":
            $step = "+1 MONTH";
            $period_format = "%m/%Y";
            break;
        case "twenty-years":
            $step = "+1 YEAR";
            $period_format = "%Y";
            break;
        default:
            $step = "+1 HOUR";
            $period_format = "%Hh";
            break;
    }
    $endx = $interval == "day" ? CMbDT::date($endx) : CMbDT::dateTime($endx);
    $datax = array();
    $i = 0;
    for ($d = $startx; $d <= $endx; $d = CMbDT::dateTime($step, $d)) {
        $period = CMbDT::format($d, $period_format);
        $datax[$period] = array($i, $period);
        $i++;
    }
    // Series data
    $hits = array();
    // Series initialisation
    foreach ($datax as $x) {
        $hits[$x[0]] = array($x[0], 0);
    }
    // Load query
    $log = new CUserLog();
    $ds = $log->_spec->ds;
    $query = "\r\n    SELECT \r\n      DATE_FORMAT(date, '{$period_format}') AS period,\r\n      COUNT(user_log_id) AS total\r\n    FROM `user_log`\r\n    USE INDEX (date)\r\n    WHERE date BETWEEN '{$startx}' AND '{$endx}'";
    $query .= $user_id ? "AND user_id = '{$user_id}'" : "";
    $query .= "\r\n    GROUP BY period \r\n    ORDER BY period\r\n  ";
    foreach ($results = $ds->loadHashList($query) as $_period => $_result) {
        $index = $datax[$_period][0];
        $hits[$index][1] = $_result;
    }
    $datax = array_values($datax);
    $title = "Bilan d'utilisation";
    $user = CUser::get($user_id);
    $subtitle = $user_id ? "Pour {$user->_view}" : "Tous les utilisateurs";
    $options = array("title" => utf8_encode($title), "subtitle" => utf8_encode($subtitle), "xaxis" => array("labelsAngle" => 45, "ticks" => $datax), "yaxis" => array("min" => 0, "title" => "Actions", "autoscaleMargin" => 1), "grid" => array("verticalLines" => false), "HtmlText" => false, "spreadsheet" => array("show" => true, "csvFileSeparator" => ";", "decimalSeparator" => ","));
    // Right axis (before in order the lines to be on top)
    $series[] = array("label" => "Actions utilisateur", "data" => $hits, "bars" => array("show" => true), "yaxis" => 1);
    return array("series" => $series, "options" => $options);
}
Example #20
0
 }
 $form->addItem(array(S_USER_GROUP . SPACE, $cmbUGrp));
 $numrows = new CDiv();
 $numrows->setAttribute('name', 'numrows');
 $user_wdgt->addHeader(S_USERS_BIG, $form);
 $user_wdgt->addHeader($numrows);
 $form = new CForm(null, 'post');
 $form->setName('users');
 $table = new CTableInfo(S_NO_USERS_DEFINED);
 $table->setHeader(array(new CCheckBox('all_users', NULL, "checkAll('" . $form->getName() . "','all_users','group_userid');"), make_sorting_header(S_ALIAS, 'alias'), make_sorting_header(S_NAME, 'name'), make_sorting_header(S_SURNAME, 'surname'), make_sorting_header(S_USER_TYPE, 'type'), S_GROUPS, S_IS_ONLINE_Q, S_LOGIN, S_GUI_ACCESS, S_API_ACCESS, S_DEBUG_MODE, S_STATUS));
 // User table
 $options = array('output' => API_OUTPUT_EXTEND, 'select_usrgrps' => API_OUTPUT_EXTEND, 'get_access' => 1, 'limit' => $config['search_limit'] + 1);
 if ($_REQUEST['filter_usrgrpid'] > 0) {
     $options['usrgrpids'] = $_REQUEST['filter_usrgrpid'];
 }
 $users = CUser::get($options);
 // sorting
 order_result($users, getPageSortField('alias'), getPageSortOrder());
 $paging = getPagingLine($users);
 //---------
 // set default lastaccess time to 0.
 foreach ($users as $unum => $user) {
     $usessions[$user['userid']] = array('lastaccess' => 0);
 }
 $userids = zbx_objectValues($users, 'userid');
 $sql = 'SELECT s.userid, MAX(s.lastaccess) as lastaccess, s.status ' . ' FROM sessions s' . ' WHERE ' . DBcondition('s.userid', $userids) . ' GROUP BY s.userid, s.status';
 $db_sessions = DBselect($sql);
 while ($session = DBfetch($db_sessions)) {
     if ($usessions[$session['userid']]['lastaccess'] < $session['lastaccess']) {
         $usessions[$session['userid']] = $session;
     }
Example #21
0
function validate_operation($operation)
{
    if (isset($operation['esc_period']) && ($operation['esc_period'] > 0 && $operation['esc_period'] < 60)) {
        error(S_INCORRECT_ESCALATION_PERIOD);
        return false;
    }
    switch ($operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            switch ($operation['object']) {
                case OPERATION_OBJECT_USER:
                    $users = CUser::get(array('userids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND));
                    if (empty($users)) {
                        error(S_INCORRECT_USER);
                        return false;
                    }
                    break;
                case OPERATION_OBJECT_GROUP:
                    $usrgrps = CUserGroup::get(array('usrgrpids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND));
                    if (empty($usrgrps)) {
                        error(S_INCORRECT_GROUP);
                        return false;
                    }
                    break;
                default:
                    error(S_INCORRECT_OBJECT_TYPE);
                    return false;
            }
            break;
        case OPERATION_TYPE_COMMAND:
            return validate_commands($operation['longdata']);
        case OPERATION_TYPE_HOST_ADD:
        case OPERATION_TYPE_HOST_REMOVE:
        case OPERATION_TYPE_HOST_ENABLE:
        case OPERATION_TYPE_HOST_DISABLE:
            break;
        case OPERATION_TYPE_GROUP_ADD:
        case OPERATION_TYPE_GROUP_REMOVE:
            $groups = CHostGroup::get(array('groupids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1));
            if (empty($groups)) {
                error(S_INCORRECT_GROUP);
                return false;
            }
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            $tpls = CTemplate::get(array('templateids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1));
            if (empty($tpls)) {
                error(S_INCORRECT_HOST);
                return false;
            }
            break;
        default:
            error(S_INCORRECT_OPERATION_TYPE);
            return false;
    }
    return true;
}
Example #22
0
<?php

/**
 * $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
 */
CCanDo::checkEdit();
$user = CUser::get(CValue::getOrSession("user_id"));
$user_id = CValue::getOrSession("user_id", $user->_id);
if (!$user_id) {
    CAppUI::setMsg("Vous devez sélectionner un utilisateur");
    CAppUI::redirect("m=admin&tab=vw_edit_users");
}
$modulesInstalled = CModule::getInstalled();
$isAdminPermSet = false;
$profile = new CUser();
if ($user->profile_id) {
    $where["user_id"] = "= '{$user->profile_id}'";
    $profile->loadObject($where);
}
$order = "mod_id";
//Droit de l'utilisateur sur les modules
$whereUser = array();
$whereUser["user_id"] = "= '{$user->user_id}'";
$whereProfil = array();
Example #23
0
 /**
  * Initializes a unique request ID to identify current request
  *
  * @return string
  */
 private static function initRequestUID()
 {
     $user_id = CUser::get()->_id;
     $uid = uniqid("", true);
     $address = get_remote_address();
     $ip = $address["remote"];
     // MD5 is enough as it doesn't have to be crypto proof
     self::$requestUID = md5("{$user_id}/{$uid}/{$ip}");
 }
Example #24
0
 /**
  * Get Alerts data
  *
  * @param _array $options
  * @param array $options['itemids']
  * @param array $options['hostids']
  * @param array $options['groupids']
  * @param array $options['alertids']
  * @param array $options['applicationids']
  * @param array $options['status']
  * @param array $options['editable']
  * @param array $options['extendoutput']
  * @param array $options['count']
  * @param array $options['pattern']
  * @param array $options['limit']
  * @param array $options['order']
  * @return array|int item data as array or false if error
  */
 public static function get($options = array())
 {
     global $USER_DETAILS;
     $result = array();
     $user_type = $USER_DETAILS['type'];
     $userid = $USER_DETAILS['userid'];
     $sort_columns = array('alertid', 'clock', 'eventid', 'status');
     // allowed columns for sorting
     $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND, API_OUTPUT_CUSTOM);
     // allowed output options for [ select_* ] params
     $sql_parts = array('select' => array('alerts' => 'a.alertid'), 'from' => array('alerts' => 'alerts a'), 'where' => array(), 'order' => array(), 'limit' => null);
     $def_options = array('nodeids' => null, 'groupids' => null, 'hostids' => null, 'alertids' => null, 'triggerids' => null, 'eventids' => null, 'actionids' => null, 'mediatypeids' => null, 'userids' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'time_from' => null, 'time_till' => null, 'extendoutput' => null, 'output' => API_OUTPUT_REFER, 'select_mediatypes' => null, 'select_users' => null, 'select_hosts' => null, 'countOutput' => null, 'preservekeys' => null, 'editable' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($def_options, $options);
     if (!is_null($options['extendoutput'])) {
         $options['output'] = API_OUTPUT_EXTEND;
         if (!is_null($options['select_mediatypes'])) {
             $options['select_mediatypes'] = API_OUTPUT_EXTEND;
         }
         if (!is_null($options['select_users'])) {
             $options['select_users'] = API_OUTPUT_EXTEND;
         }
     }
     if (is_array($options['output'])) {
         unset($sql_parts['select']['alerts']);
         $sql_parts['select']['alertid'] = ' a.alertid';
         foreach ($options['output'] as $key => $field) {
             $sql_parts['select'][$field] = ' a.' . $field;
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // editable + PERMISSION CHECK
     if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) {
     } else {
         $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY;
         $sql_parts['from']['events'] = 'events e';
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['from']['hosts_groups'] = 'hosts_groups hg';
         $sql_parts['from']['rights'] = 'rights r';
         $sql_parts['from']['users_groups'] = 'users_groups ug';
         $sql_parts['from']['functions'] = 'functions f';
         $sql_parts['where']['ae'] = 'a.eventid=e.eventid';
         $sql_parts['where']['e'] = 'e.object=' . EVENT_OBJECT_TRIGGER;
         $sql_parts['where']['ef'] = 'e.objectid=f.triggerid';
         $sql_parts['where']['fi'] = 'f.itemid=i.itemid';
         $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid';
         $sql_parts['where'][] = 'r.id=hg.groupid ';
         $sql_parts['where'][] = 'r.groupid=ug.usrgrpid';
         $sql_parts['where'][] = 'ug.userid=' . $userid;
         $sql_parts['where'][] = 'r.permission>=' . $permission;
         $sql_parts['where'][] = 'NOT EXISTS( ' . ' SELECT ff.triggerid ' . ' FROM functions ff, items ii ' . ' WHERE ff.triggerid=e.objectid ' . ' AND ff.itemid=ii.itemid ' . ' AND EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups gg ' . ' WHERE hgg.hostid=ii.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=gg.usrgrpid ' . ' AND gg.userid=' . $userid . ' AND rr.permission<' . $permission . '))';
     }
     // nodeids
     $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid();
     // groupids
     if (!is_null($options['groupids'])) {
         zbx_value2array($options['groupids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['groupid'] = 'hg.groupid';
         }
         $sql_parts['from']['functions'] = 'functions f';
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['from']['hosts_groups'] = 'hosts_groups hg';
         $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid';
         $sql_parts['where']['e'] = 'e.object=' . EVENT_OBJECT_TRIGGER;
         $sql_parts['where']['ef'] = 'e.objectid=f.triggerid';
         $sql_parts['where']['fi'] = 'f.itemid=i.itemid';
         $sql_parts['where']['hg'] = DBcondition('hg.groupid', $options['groupids']);
     }
     // hostids
     if (!is_null($options['hostids'])) {
         zbx_value2array($options['hostids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['hostid'] = 'i.hostid';
         }
         $sql_parts['from']['functions'] = 'functions f';
         $sql_parts['from']['items'] = 'items i';
         $sql_parts['where']['i'] = DBcondition('i.hostid', $options['hostids']);
         $sql_parts['where']['e'] = 'e.object=' . EVENT_OBJECT_TRIGGER;
         $sql_parts['where']['ef'] = 'e.objectid=f.triggerid';
         $sql_parts['where']['fi'] = 'f.itemid=i.itemid';
     }
     // alertids
     if (!is_null($options['alertids'])) {
         zbx_value2array($options['alertids']);
         $sql_parts['where'][] = DBcondition('a.alertid', $options['alertids']);
     }
     // triggerids
     if (!is_null($options['triggerids'])) {
         zbx_value2array($options['triggerids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['actionid'] = 'a.actionid';
         }
         $sql_parts['where']['ae'] = 'a.eventid=e.eventid';
         $sql_parts['where']['e'] = 'e.object=' . EVENT_OBJECT_TRIGGER;
         $sql_parts['where'][] = DBcondition('e.objectid', $options['triggerids']);
     }
     // eventids
     if (!is_null($options['eventids'])) {
         zbx_value2array($options['eventids']);
         $sql_parts['where'][] = DBcondition('a.eventid', $options['eventids']);
     }
     // actionids
     if (!is_null($options['actionids'])) {
         zbx_value2array($options['actionids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['actionid'] = 'a.actionid';
         }
         $sql_parts['where'][] = DBcondition('a.actionid', $options['actionids']);
     }
     // userids
     if (!is_null($options['userids'])) {
         zbx_value2array($options['userids']);
         // if(is_null($options['extendoutput'])){
         // $sql_parts['select']['userid'] = 'a.userid';
         // }
         $field = 'a.userid';
         if (!is_null($options['time_from']) || !is_null($options['time_till'])) {
             $field = '(a.userid+0)';
         }
         $sql_parts['where'][] = DBcondition($field, $options['userids']);
     }
     // mediatypeids
     if (!is_null($options['mediatypeids'])) {
         zbx_value2array($options['mediatypeids']);
         if ($options['output'] != API_OUTPUT_SHORTEN) {
             $sql_parts['select']['mediatypeid'] = 'a.mediatypeid';
         }
         $sql_parts['where'][] = DBcondition('a.mediatypeid', $options['mediatypeids']);
     }
     // filter
     if (is_array($options['filter'])) {
         zbx_db_filter('alerts a', $options, $sql_parts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('alerts a', $options, $sql_parts);
     }
     // time_from
     if (!is_null($options['time_from'])) {
         $sql_parts['where'][] = 'a.clock>' . $options['time_from'];
     }
     // time_till
     if (!is_null($options['time_till'])) {
         $sql_parts['where'][] = 'a.clock<' . $options['time_till'];
     }
     // extendoutput
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sql_parts['select']['alerts'] = 'a.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sql_parts['select'] = array('COUNT(DISTINCT a.alertid) as rowscount');
     }
     // order
     // restrict not allowed columns for sorting
     $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : '';
     if (!zbx_empty($options['sortfield'])) {
         $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP;
         $sql_parts['order'][] = 'a.' . $options['sortfield'] . ' ' . $sortorder;
         if (!str_in_array('a.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('a.*', $sql_parts['select'])) {
             $sql_parts['select'][] = 'a.' . $options['sortfield'];
         }
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sql_parts['limit'] = $options['limit'];
     }
     //---------------
     $alertids = array();
     $userids = array();
     $hostids = array();
     $mediatypeids = array();
     $sql_parts['select'] = array_unique($sql_parts['select']);
     $sql_parts['from'] = array_unique($sql_parts['from']);
     $sql_parts['where'] = array_unique($sql_parts['where']);
     $sql_parts['order'] = array_unique($sql_parts['order']);
     $sql_select = '';
     $sql_from = '';
     $sql_where = '';
     $sql_order = '';
     if (!empty($sql_parts['select'])) {
         $sql_select .= implode(',', $sql_parts['select']);
     }
     if (!empty($sql_parts['from'])) {
         $sql_from .= implode(',', $sql_parts['from']);
     }
     if (!empty($sql_parts['where'])) {
         $sql_where .= ' AND ' . implode(' AND ', $sql_parts['where']);
     }
     if (!empty($sql_parts['order'])) {
         $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']);
     }
     $sql_limit = $sql_parts['limit'];
     $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . DBin_node('a.alertid', $nodeids) . $sql_where . $sql_order;
     $db_res = DBselect($sql, $sql_limit);
     while ($alert = DBfetch($db_res)) {
         if ($options['countOutput']) {
             $result = $alert['rowscount'];
         } else {
             $alertids[$alert['alertid']] = $alert['alertid'];
             if (isset($alert['userid'])) {
                 $userids[$alert['userid']] = $alert['userid'];
             }
             if (isset($alert['hostid'])) {
                 $hostids[$alert['hostid']] = $alert['hostid'];
             }
             if (isset($alert['mediatypeid'])) {
                 $mediatypeids[$alert['mediatypeid']] = $alert['mediatypeid'];
             }
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$alert['alertid']] = array('alertid' => $alert['alertid']);
             } else {
                 if (!isset($result[$alert['alertid']])) {
                     $result[$alert['alertid']] = array();
                 }
                 if (!is_null($options['select_mediatypes']) && !isset($result[$alert['alertid']]['mediatypes'])) {
                     $result[$alert['alertid']]['mediatypes'] = array();
                 }
                 if (!is_null($options['select_users']) && !isset($result[$alert['alertid']]['users'])) {
                     $result[$alert['alertid']]['users'] = array();
                 }
                 // hostids
                 if (isset($alert['hostid']) && is_null($options['select_hosts'])) {
                     if (!isset($result[$alert['alertid']]['hosts'])) {
                         $result[$alert['alertid']]['hosts'] = array();
                     }
                     $result[$alert['alertid']]['hosts'][] = array('hostid' => $alert['hostid']);
                     //						unset($alert['hostid']);
                 }
                 // userids
                 if (isset($alert['userid']) && is_null($options['select_users'])) {
                     if (!isset($result[$alert['alertid']]['users'])) {
                         $result[$alert['alertid']]['users'] = array();
                     }
                     $result[$alert['alertid']]['users'][] = array('userid' => $alert['userid']);
                 }
                 // mediatypeids
                 if (isset($alert['mediatypeid']) && is_null($options['select_mediatypes'])) {
                     if (!isset($result[$alert['alertid']]['mediatypes'])) {
                         $result[$alert['alertid']]['mediatypes'] = array();
                     }
                     $result[$alert['alertid']]['mediatypes'][] = array('mediatypeid' => $alert['mediatypeid']);
                 }
                 $result[$alert['alertid']] += $alert;
             }
         }
     }
     COpt::memoryPick();
     if (!is_null($options['countOutput'])) {
         if (is_null($options['preservekeys'])) {
             $result = zbx_cleanHashes($result);
         }
         return $result;
     }
     // Adding Objects
     $hosts = array();
     $users = array();
     $mediatypes = array();
     // Adding hosts
     if (!is_null($options['select_hosts']) && str_in_array($options['select_hosts'], $subselects_allowed_outputs)) {
         $obj_params = array('output' => $options['select_hosts'], 'hostids' => $hostids, 'preservekeys' => 1);
         $hosts = CHost::get($obj_params);
     }
     // Adding Users
     if (!is_null($options['select_users']) && str_in_array($options['select_users'], $subselects_allowed_outputs)) {
         $obj_params = array('output' => $options['select_users'], 'userids' => $userids, 'preservekeys' => 1);
         $users = CUser::get($obj_params);
     }
     // Adding MediaTypes
     if (!is_null($options['select_mediatypes']) && str_in_array($options['select_mediatypes'], $subselects_allowed_outputs)) {
         $sql = 'SELECT mt.* FROM media_type mt WHERE ' . DBcondition('mt.mediatypeid', $mediatypeids);
         $res = DBselect($sql);
         while ($media = DBfetch($res)) {
             $mediatypes[$media['mediatypeid']] = $media;
         }
     }
     foreach ($result as $alertid => $alert) {
         if (isset($alert['hostid']) && isset($hosts[$alert['hostid']])) {
             $result[$alertid]['hosts'][] = $hosts[$alert['hostid']];
         }
         if (isset($mediatypes[$alert['mediatypeid']])) {
             $result[$alertid]['mediatypes'][] = $mediatypes[$alert['mediatypeid']];
         }
         if (isset($users[$alert['userid']])) {
             $result[$alertid]['users'][] = $users[$alert['userid']];
         }
     }
     COpt::memoryPick();
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
try {
    $ftp->connect();
} catch (CMbException $e) {
    CAppUI::stepAjax($e->getMessage(), UI_MSG_WARNING);
}
$list = array();
try {
    $list = $ftp->getListFiles($ftp->fileprefix);
} catch (CMbException $e) {
    CAppUI::stepAjax($e->getMessage(), UI_MSG_WARNING);
}
if (empty($list)) {
    CAppUI::stepAjax("Le répertoire ne contient aucun fichier", UI_MSG_ERROR);
}
$sender_ftp = new CSenderFTP();
$sender_ftp->user_id = CUser::get()->_id;
$sender_ftp->loadMatchingObject();
$count = CAppUI::conf("eai max_files_to_process");
$list = array_slice($list, 0, $count);
foreach ($list as $filepath) {
    if (substr($filepath, -strlen($extension)) == $extension) {
        $filename = basename($filepath);
        $hprimFile = $ftp->getFile($filepath, "tmp/hprim21/{$filename}");
        // Création de l'échange
        $echg_hprim21 = new CEchangeHprim21();
        $echg_hprim21->group_id = CGroups::loadCurrent()->_id;
        $echg_hprim21->sender_class = $sender_ftp->_class;
        $echg_hprim21->sender_id = $sender_ftp->_id;
        $echg_hprim21->date_production = CMbDT::dateTime();
        $echg_hprim21->store();
        $hprimReader = new CHPrim21Reader();
 /**
  * Create a CFile attachment to given CMbObject
  * @return string store-like message, null if successful
  */
 function addFile(CMbObject $object)
 {
     $user = CUser::get();
     $this->saveFile();
     $file = new CFile();
     $file->object_id = $object->_id;
     $file->object_class = $object->_class;
     $file->file_name = "{$object->_guid}.xml";
     $file->file_type = "text/xml";
     $file->doc_size = filesize($this->documentfilename);
     $file->file_date = CMbDT::dateTime();
     $file->file_real_filename = uniqid(rand());
     $file->author_id = $user->_id;
     $file->private = 0;
     if (!$file->moveFile($this->documentfilename)) {
         return "error-CFile-move-file";
     }
     return $file->store();
 }
Example #27
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage Urgences
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
$rpu_id = CValue::get("rpu_id");
$rpu = new CRPU();
$rpu->load($rpu_id);
// Si accès au module PMSI : peut modifier le diagnostic principal
$access_pmsi = 0;
if (CModule::exists("dPpmsi")) {
    $module = new CModule();
    $module->mod_name = "dPpmsi";
    $module->loadMatchingObject();
    $access_pmsi = $module->getPerm(PERM_EDIT);
}
// Si praticien : peut modifier le CCMU, GEMSA et diagnostic principal
$is_praticien = CUser::get()->loadRefMediuser()->isPraticien();
$smarty = new CSmartyDP();
$smarty->assign("rpu", $rpu);
$smarty->assign("is_praticien", $is_praticien);
$smarty->assign("access_pmsi", $access_pmsi);
$smarty->display("inc_edit_fields_rpu.tpl");
Example #28
0
<?php

/**
 * $Id: ajax_login_as.php 20443 2013-09-23 13:48:21Z phenxdesign $
 *
 * @category Admin
 * @package  Mediboard
 * @author   SARL OpenXtrem <*****@*****.**>
 * @license  GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version  $Revision: 20443 $
 * @link     http://www.mediboard.org
 */
$user = CUser::get();
$username = trim(CValue::post('username'));
$password = trim(CValue::post('password'));
// If substitution happens when a session is locked
$is_locked = CValue::get("is_locked");
if ($is_locked) {
    $_SESSION['locked'] = false;
}
$ldap_connection = CAppUI::conf("admin LDAP ldap_connection");
$allow_login_as_ldap = CAppUI::conf("admin LDAP allow_login_as_admin");
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) {
Example #29
0
 foreach ($allowed_operations as $oper) {
     $cmbOpType->addItem($oper, operation_type2str($oper));
 }
 $tblNewOperation->addRow(array(S_OPERATION_TYPE, $cmbOpType));
 switch ($new_operation['operationtype']) {
     case OPERATION_TYPE_MESSAGE:
         if ($new_operation['object'] == OPERATION_OBJECT_GROUP) {
             $object_srctbl = 'usrgrp';
             $object_srcfld1 = 'usrgrpid';
             $object_name = CUserGroup::get(array('usrgrpids' => $new_operation['objectid'], 'output' => API_OUTPUT_EXTEND));
             $object_name = reset($object_name);
             $display_name = 'name';
         } else {
             $object_srctbl = 'users';
             $object_srcfld1 = 'userid';
             $object_name = CUser::get(array('userids' => $new_operation['objectid'], 'output' => API_OUTPUT_EXTEND));
             $object_name = reset($object_name);
             $display_name = 'alias';
         }
         $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
         if ($object_name) {
             $object_name = $object_name[$display_name];
         }
         $cmbObject = new CComboBox('new_operation[object]', $new_operation['object'], 'submit()');
         $cmbObject->addItem(OPERATION_OBJECT_USER, S_SINGLE_USER);
         $cmbObject->addItem(OPERATION_OBJECT_GROUP, S_USER_GROUP);
         $tblNewOperation->addRow(array(S_SEND_MESSAGE_TO, array($cmbObject, new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D' . '&dstfld2=object_name' . '&srctbl=' . $object_srctbl . '&srcfld1=' . $object_srcfld1 . '&srcfld2=' . $display_name . '&submit=1' . '",450,450)', 'T'))));
         $cmbMediaType = new CComboBox('new_operation[mediatypeid]', $new_operation['mediatypeid'], 'submit()');
         $cmbMediaType->addItem(0, S_MINUS_ALL_MINUS);
         if (OPERATION_OBJECT_USER == $new_operation['object']) {
             $sql = 'SELECT DISTINCT mt.mediatypeid,mt.description,m.userid ' . ' FROM media_type mt, media m ' . ' WHERE ' . DBin_node('mt.mediatypeid') . ' AND m.mediatypeid=mt.mediatypeid ' . ' AND m.userid=' . $new_operation['objectid'] . ' AND m.active=' . ACTION_STATUS_ENABLED . ' ORDER BY mt.description';