예제 #1
1
        $searchparams['firstname'] = '%' . $params['firstname'] . '%';
    }
    if (!empty($params['lastname'])) {
        $sqlsearch .= " AND lastname like :lastname ";
        $searchparams['lastname'] = '%' . $params['lastname'] . '%';
    }
    if (!empty($params['email'])) {
        $sqlsearch .= " AND email like :email ";
        $searchparams['email'] = '%' . $params['email'] . '%';
    }
    $userrecords = $DB->get_fieldset_select('user', 'id', $sqlsearch, $searchparams);
} else {
    if (iomad::has_capability('block/iomad_company_admin:editusers', $systemcontext)) {
        // Check if has role edit company users.
        // Get users company association.
        $departmentusers = company::get_recursive_department_users($departmentid);
        if (count($departmentusers) > 0) {
            $departmentids = "";
            foreach ($departmentusers as $departmentuser) {
                if (!empty($departmentids)) {
                    $departmentids .= "," . $departmentuser->userid;
                } else {
                    $departmentids .= $departmentuser->userid;
                }
            }
            if (!empty($showsuspended)) {
                $sqlsearch = " deleted <> 1 AND id in ({$departmentids}) ";
            } else {
                $sqlsearch = " deleted <> 1 AND suspended = 0 AND id in ({$departmentids}) ";
            }
        } else {
if ($format) {
    $fields = array('id' => 'id', 'username' => 'username', 'email' => 'email', 'firstname' => 'firstname', 'lastname' => 'lastname', 'idnumber' => 'idnumber', 'institution' => 'institution', 'department' => 'department', 'phone1' => 'phone1', 'phone2' => 'phone2', 'city' => 'city', 'url' => 'url', 'icq' => 'icq', 'skype' => 'skype', 'aim' => 'aim', 'yahoo' => 'yahoo', 'msn' => 'msn', 'country' => 'country');
    // Get company category.
    if ($category = $DB->get_record_sql('SELECT uic.id, uic.name
                                         FROM {user_info_category} uic, {company} c
                                         WHERE c.id = ' . $companyid . ' AND
                                         c.shortname=uic.name')) {
        if ($extrafields = $DB->get_records('user_info_field', array('categoryid' => $category->id))) {
            foreach ($extrafields as $n => $v) {
                $fields['profile_field_' . $v->shortname] = 'profile_field_' . $v->shortname;
            }
        }
    }
    $params = array('companyid' => $companyid);
    // Get department users.
    $departmentusers = company::get_recursive_department_users($userhierarchylevel);
    if (count($departmentusers) > 0) {
        $departmentids = "";
        foreach ($departmentusers as $departmentuser) {
            if (!empty($departmentids)) {
                $departmentids .= "," . $departmentuser->userid;
            } else {
                $departmentids .= $departmentuser->userid;
            }
        }
        $sqlsearch = " AND userid in ({$departmentids}) ";
    } else {
        $sqlsearch = "AND 1 = 0";
    }
    $userids = $DB->get_records_sql_menu("SELECT userid, userid as id\n        FROM\n            {company_users}\n        WHERE\n            companyid = :companyid\n            " . $sqlsearch, $params);
    switch ($format) {
예제 #3
0
 /**
  * Send an email to all users in a department (and it's subdepartments)
  *
  * @param integer $departmentid id of the department
  * @param string $templatename Name of the template as described in
  *                             the global $email array or overridden
  *                             in the mdl_email_template table
  * @param array $options array of options to pass into each email
  * @return bool Returns true if mail was sent OK and false if there was an error
  */
 public static function send_to_all_users_in_department($departmentid, $templatename, $options = array())
 {
     global $DB;
     $users = company::get_recursive_department_users($departmentid);
     $useroptions = array_map('self::getuseroption', $users);
     $result = self::send($templatename, $options, $useroptions);
     if ($result === true) {
         return true;
     } else {
         return $result == count($useroptions);
     }
 }