Beispiel #1
0
         $company_id = fn_update_company($_REQUEST['company_data']);
         if (!empty($company_id)) {
             $suffix = ".update?company_id={$company_id}";
             if (isset($_REQUEST['company_data']['is_create_vendor_admin']) && $_REQUEST['company_data']['is_create_vendor_admin'] == 'Y') {
                 if (db_get_field("SELECT COUNT(*) FROM ?:users WHERE email = ?s", $_REQUEST['company_data']['email']) > 0) {
                     fn_set_notification('E', __('error'), __('error_admin_not_created_email_already_used'));
                 } else {
                     // Add company's administrator
                     if (fn_is_restricted_admin($_REQUEST) == true) {
                         return array(CONTROLLER_STATUS_DENIED);
                     }
                     $company_data = $_REQUEST['company_data'];
                     $company_data['company_id'] = $company_id;
                     $company_data['is_root'] = 'N';
                     $fields = isset($_REQUEST['user_data']['fields']) ? $_REQUEST['user_data']['fields'] : '';
                     $user_data = fn_create_company_admin($company_data, $fields, true);
                 }
             }
         } else {
             fn_save_post_data('company_data', 'update');
         }
     }
 } else {
     $company_id = fn_update_company($_REQUEST['company_data']);
 }
 if (!empty($company_id)) {
     if (fn_allowed_for('ULTIMATE') && !empty($_REQUEST['update'])) {
         fn_ult_set_company_settings_information($_REQUEST['update'], $company_id);
     }
     $suffix = ".update?company_id={$company_id}";
     $redirect_url = empty($_REQUEST['redirect_url']) ? 'companies' . $suffix : $_REQUEST['redirect_url'];
Beispiel #2
0
/**
 * Fucntion changes company status. Allowed statuses are A(ctive) and D(isabled)
 *
 * @param int $company_id
 * @param string $status_to A or D
 * @param string $reason The reason of the change
 * @param string $status_from Previous status
 * @param boolean $skip_query By default false. Update query might be skipped if status is already changed.
 * @return boolean True on success or false on failure
 */
function fn_change_company_status($company_id, $status_to, $reason = '', &$status_from = '', $skip_query = false, $notify = true)
{
    /**
     * Actions before change company status
     *
     * @param int    $company_id  Company ID
     * @param string $status_to   Status to letter
     * @param string $reason      Reason text
     * @param string $status_from Status from letter
     * @param bool   $skip_query  Skip query flag
     * @param bool   $notify      Notify flag
     */
    fn_set_hook('change_company_status_pre', $company_id, $status_to, $reason, $status_from, $skip_query, $notify);
    if (empty($status_from)) {
        $status_from = db_get_field("SELECT status FROM ?:companies WHERE company_id = ?i", $company_id);
    }
    if (!in_array($status_to, array('A', 'P', 'D')) || $status_from == $status_to) {
        return false;
    }
    $result = $skip_query ? true : db_query("UPDATE ?:companies SET status = ?s WHERE company_id = ?i", $status_to, $company_id);
    if (!$result) {
        return false;
    }
    $company_data = fn_get_company_data($company_id);
    $account = $username = '';
    if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
        if (Registry::get('settings.Vendors.create_vendor_administrator_account') == 'Y') {
            if (!empty($company_data['request_user_id'])) {
                $password_change_timestamp = db_get_field("SELECT password_change_timestamp FROM ?:users WHERE user_id = ?i", $company_data['request_user_id']);
                $_set = '';
                if (empty($password_change_timestamp)) {
                    $_set = ", password_change_timestamp = 1 ";
                }
                db_query("UPDATE ?:users SET company_id = ?i, user_type = 'V'{$_set} WHERE user_id = ?i", $company_id, $company_data['request_user_id']);
                $username = fn_get_user_name($company_data['request_user_id']);
                $account = 'updated';
                $msg = __('new_administrator_account_created') . '<a href="' . fn_url('profiles.update?user_id=' . $company_data['request_user_id']) . '">' . __('you_can_edit_account_details') . '</a>';
                fn_set_notification('N', __('notice'), $msg, 'K');
            } else {
                $_company_data = $company_data + unserialize($company_data['request_account_data']);
                $_company_data['status'] = 'A';
                if (!empty($_company_data['request_account_name'])) {
                    $_company_data['admin_username'] = $_company_data['request_account_name'];
                }
                $user_data = fn_create_company_admin($_company_data, $_company_data['fields'], false);
                if (!empty($user_data['user_id'])) {
                    $username = $user_data['user_login'];
                    $account = 'new';
                }
            }
        }
    }
    if (empty($user_data)) {
        $user_id = db_get_field("SELECT user_id FROM ?:users WHERE company_id = ?i AND is_root = 'Y' AND user_type = 'V'", $company_id);
        $user_data = fn_get_user_info($user_id);
    }
    /**
     * Actions between change company status and send mail
     *
     * @param int    $company_id   Company ID
     * @param string $status_to    Status to letter
     * @param string $reason       Reason text
     * @param string $status_from  Status from letter
     * @param bool   $skip_query   Skip query flag
     * @param bool   $notify       Notify flag
     * @param array  $company_data Company data
     * @param array  $user_data    User data
     * @param bool   $result       Updated flag
     */
    fn_set_hook('change_company_status_before_mail', $company_id, $status_to, $reason, $status_from, $skip_query, $notify, $company_data, $user_data, $result);
    if ($notify && !empty($company_data['email'])) {
        $e_username = '';
        $e_account = '';
        $e_password = '';
        if ($status_from == 'N' && ($status_to == 'A' || $status_to == 'P')) {
            $e_username = $username;
            $e_account = $account;
            if ($account == 'new') {
                $e_password = $user_data['password1'];
            }
        }
        $mail_template = fn_strtolower($status_from . '_' . $status_to);
        Mailer::sendMail(array('to' => $company_data['email'], 'from' => 'default_company_support_department', 'data' => array('user_data' => $user_data, 'reason' => $reason, 'status' => __($status_to == 'A' ? 'active' : 'disabled'), 'e_username' => $e_username, 'e_account' => $e_account, 'e_password' => $e_password), 'company_id' => $company_id, 'tpl' => 'companies/status_' . $mail_template . '_notification.tpl'), 'A');
    }
    return $result;
}