Beispiel #1
0
/**
 * Get HTML component select all users
 *
 * @return string HTML component select
 */
function credit_html_select_user()
{
    global $user_config;
    if (auth_isadmin()) {
        $admins = user_getallwithstatus(2);
        $users = user_getallwithstatus(3);
    }
    $subusers = user_getsubuserbyuid($user_config['uid']);
    if (count($admins) > 0) {
        $option_user .= '<optgroup label="' . _('Administrators') . '">';
        foreach ($admins as $admin) {
            $option_user .= '<option value="' . $admin['uid'] . '">' . $admin['name'] . ' (' . $admin['username'] . ') - ' . _('Administrator') . '</option>';
        }
        $option_user .= '</optgroup>';
    }
    if (count($users) > 0) {
        $option_user .= '<optgroup label="' . _('Users') . '">';
        foreach ($users as $user) {
            $option_user .= '<option value="' . $user['uid'] . '">' . $user['name'] . ' (' . $user['username'] . ') - ' . _('User') . '</option>';
        }
        $option_user .= '</optgroup>';
    }
    if (count($subusers) > 0) {
        $option_user .= '<optgroup label="' . _('Subusers') . '">';
        foreach ($subusers as $subuser) {
            $option_user .= '<option value="' . $subuser['uid'] . '">' . $subuser['name'] . ' (' . $subuser['username'] . ') - ' . _('Subuser') . '</option>';
        }
        $option_user .= '</optgroup>';
    }
    $select_user = '******' . $option_user . '</select>';
    return $select_user;
}
     $keywords = $data['keywords'];
     $description = $data['description'];
     $c_members = count(inboxgroup_getmembers($rid));
     $c_members = "<a href='index.php?app=menu&inc=feature_inboxgroup&route=members&op=members&rid=" . $rid . "'>" . $c_members . "</a>";
     $c_catchall = count(inboxgroup_getcatchall($rid));
     $c_catchall = "<a href='index.php?app=menu&inc=feature_inboxgroup&route=catchall&op=catchall&rid=" . $rid . "'>" . $c_catchall . "</a>";
     $c_status = $data['status'] ? "<font color='green'>" . _('enabled') . "</font>" : "<font color='red'>" . _('disabled') . "</font>";
     $content .= "\n\t\t\t<table cellpadding='1' cellspacing='2' border='0'>\n\t\t\t<tr><td>" . _('Receiver number') . "</td><td>:</td><td>" . $in_receiver . "</td></tr>\n\t\t\t<tr><td>" . _('Keywords') . "</td><td>:</td><td>" . $keywords . "</td></tr>\n\t\t\t<tr><td>" . _('Description') . "</td><td>:</td><td>" . $description . "</td></tr>\n\t\t\t<tr><td>" . _('Members') . "</td><td>:</td><td>" . $c_members . "</td></tr>\n\t\t\t<tr><td>" . _('Catch-all') . "</td><td>:</td><td>" . $c_catchall . "</td></tr>\n\t\t\t<tr><td>" . _('Status') . "</td><td>:</td><td>" . $c_status . "</td></tr>\n\t\t\t</table>\n\t\t";
     $list_of_users = '';
     // get admins
     $users = user_getallwithstatus(2);
     for ($i = 0; $i < count($users); $i++) {
         $list_of_users .= "<option value='" . $users[$i]['uid'] . "'>" . $users[$i]['name'] . " " . $users[$i]['mobile'] . "</option>";
     }
     // get normal users
     $users = user_getallwithstatus(3);
     for ($i = 0; $i < count($users); $i++) {
         $list_of_users .= "<option value='" . $users[$i]['uid'] . "'>" . $users[$i]['name'] . " " . $users[$i]['mobile'] . "</option>";
     }
     $content .= "\n\t\t\t<form action=\"index.php?app=menu&inc=feature_inboxgroup&route=members&op=members_add_submit\" method=\"post\">\n\t\t\t<input type=hidden name='rid' value='" . $rid . "'>\n\t\t\t<table cellpadding=1 cellspacing=2 border=0>\n\t\t\t<tr>\n\t\t\t\t<td nowrap>\n\t\t\t\t\t" . _('All users') . ":<br />\n\t\t    \t\t\t<select name=\"uids_dump[]\" size=\"10\" multiple=\"multiple\" onDblClick=\"moveSelectedOptions(this.form['uids_dump[]'],this.form['uids[]'])\">{$list_of_users}</select>\n\t\t\t\t</td>\n\t\t\t\t<td width=10>&nbsp;</td>\n\t\t\t\t<td align=center valign=middle>\n\t\t\t\t\t<input type=\"button\" class=\"button\" value=\"&gt;&gt;\" onclick=\"moveSelectedOptions(this.form['uids_dump[]'],this.form['uids[]'])\"><br><br>\n\t\t\t\t\t<input type=\"button\" class=\"button\" value=\"" . _('All') . " &gt;&gt;\" onclick=\"moveAllOptions(this.form['uids_dump[]'],this.form['uids[]'])\"><br><br>\n\t\t\t\t\t<input type=\"button\" class=\"button\" value=\"&lt;&lt;\" onclick=\"moveSelectedOptions(this.form['uids[]'],this.form['uids_dump[]'])\"><br><br>\n\t\t\t\t\t<input type=\"button\" class=\"button\" value=\"" . _('All') . " &lt;&lt;\" onclick=\"moveAllOptions(this.form['uids[]'],this.form['uids_dump[]'])\">\n\t\t\t\t</td>\t\t\n\t\t\t\t<td width=10>&nbsp;</td>\n\t\t\t\t<td nowrap>\n\t\t\t\t    " . _('Selected users') . ":<br>\n\t\t\t\t    <select name=\"uids[]\" size=\"10\" multiple=\"multiple\" onDblClick=\"moveSelectedOptions(this.form['uids[]'],this.form['uids_dump[]'])\"></select>\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t<p>" . _('Press submit button to add selected users to member list') . "</p>\n\t\t\t<p><input class='button' type='submit' value='Submit' onClick=\"selectAllOptions(this.form['uids[]'])\"></p>\n\t\t\t</form>\n\t\t";
     echo $content;
     break;
 case 'members_add_submit':
     $rid = $_REQUEST['rid'];
     $rid = $_REQUEST['rid'];
     $data = inboxgroup_getdatabyid($rid);
     $in_receiver = $data['in_receiver'];
     if ($rid && $in_receiver) {
         $uids = $_REQUEST['uids'];
         for ($i = 0; $i < count($uids); $i++) {
             $c_uid = $uids[$i];
Beispiel #3
0
function themes_select_users_single($select_field_name, $selected_value = '', $tag_params = array(), $css_id = '', $css_class = '')
{
    global $user_config;
    $ret = '';
    if (core_themes_get()) {
        $ret = core_hook(core_themes_get(), 'themes_select_users_single', array($select_field_name, $selected_value, $tag_params, $css_id, $css_class));
    }
    if (!$ret) {
        if (!is_array($selected_value)) {
            $selected_value = array($selected_value);
        }
        if (auth_isadmin()) {
            $admins = user_getallwithstatus(2);
            $users = user_getallwithstatus(3);
        }
        $subusers = user_getsubuserbyuid($user_config['uid']);
        $option_user .= '<option value="0">' . _('Select users') . '</option>';
        if (count($admins) > 0) {
            $option_user .= '<optgroup label="' . _('Administrators') . '">';
            foreach ($admins as $admin) {
                $selected = '';
                foreach ($selected_value as $sv) {
                    if ($admin['uid'] == $sv) {
                        $selected = 'selected';
                        break;
                    }
                }
                $option_user .= '<option value="' . $admin['uid'] . '" ' . $selected . '>' . $admin['name'] . ' (' . $admin['username'] . ') - ' . _('Administrator') . '</option>';
            }
            $option_user .= '</optgroup>';
        }
        if (count($users) > 0) {
            $option_user .= '<optgroup label="' . _('Users') . '">';
            foreach ($users as $user) {
                $selected = '';
                foreach ($selected_value as $sv) {
                    if ($user['uid'] == $sv) {
                        $selected = 'selected';
                        break;
                    }
                }
                $option_user .= '<option value="' . $user['uid'] . '" ' . $selected . '>' . $user['name'] . ' (' . $user['username'] . ') - ' . _('User') . '</option>';
            }
            $option_user .= '</optgroup>';
        }
        if (count($subusers) > 0) {
            $option_user .= '<optgroup label="' . _('Subusers') . '">';
            foreach ($subusers as $subuser) {
                $selected = '';
                foreach ($selected_value as $sv) {
                    if ($subuser['uid'] == $sv) {
                        $selected = 'selected';
                        break;
                    }
                }
                $option_user .= '<option value="' . $subuser['uid'] . '"' . $selected . '>' . $subuser['name'] . ' (' . $subuser['username'] . ') - ' . _('Subuser') . '</option>';
            }
            $option_user .= '</optgroup>';
        }
        $css_id = trim($css_id) ? trim($css_id) : 'playsms-select-users-single-' . core_sanitize_alphanumeric($select_field_name);
        if (is_array($tag_params)) {
            foreach ($tag_params as $key => $val) {
                $params .= ' ' . $key . '="' . $val . '"';
            }
        }
        $placeholder = $tag_params['placeholder'] ? $tag_params['placeholder'] : _('Select users');
        $width = $tag_params['width'] ? $tag_params['width'] : 'resolve';
        $js = '
			<script language="javascript" type="text/javascript">
				$(document).ready(function() {
					$("#' . $css_id . '").select2({
						placeholder: "' . $placeholder . '",
						width: "' . $width . '",
						separator: [\',\'],
						tokenSeparators: [\',\'],
					});
				});
			</script>
		';
        $ret = $js . PHP_EOL . '<select name="' . $select_field_name . '" id="' . $css_id . '" class="playsms-select ' . $css_class . '" ' . $params . '>' . $option_user . '</select>';
        return $ret;
    }
}
Beispiel #4
0
         $selected = "";
     }
 }
 // get list of users as parents
 $option_parents = '<option value="0">--' . _('Select parent account for subuser') . '--</option>';
 // get admins
 $list = user_getallwithstatus(2);
 foreach ($list as $parent) {
     if ($parent['uid'] == $user_edited['parent_uid']) {
         $selected = 'selected';
     }
     $option_parents .= '<option value="' . $parent['uid'] . '" ' . $selected . '>' . $parent['username'] . ' - ' . _('Administrator') . '</option>';
     $selected = '';
 }
 // get users
 $list = user_getallwithstatus(3);
 foreach ($list as $parent) {
     if ($parent['uid'] == $user_edited['parent_uid']) {
         $selected = 'selected';
     }
     $option_parents .= '<option value="' . $parent['uid'] . '" ' . $selected . '>' . $parent['username'] . '</option>';
     $selected = '';
 }
 $select_parents = '<select name="add_parent_uid">' . $option_parents . '</select>';
 if ($view == 'admin') {
     $selected_admin = 'selected';
 } else {
     if ($view == 'users') {
         $selected_users = 'selected';
     } else {
         if ($view == 'subusers') {
Beispiel #5
0
/**
 * Add sender ID
 *
 * @param integer $uid
 *        User ID
 * @param string $sender_id
 *        Sender ID
 * @param string $sender_id_description
 *        Sender ID description
 * @param integer $isdefault
 *        Flag 1 for default sender ID
 * @param integer $isapproved
 *        Flag 1 for approved sender ID
 * @return boolean TRUE when new sender ID has been added
 */
function sender_id_add($uid, $sender_id, $sender_id_description = '', $isdefault = 1, $isapproved = 1)
{
    global $user_config;
    if (sender_id_check($uid, $sender_id)) {
        // not available
        return FALSE;
    } else {
        $default = auth_isadmin() ? (int) $isdefault : 0;
        $approved = auth_isadmin() ? (int) $isapproved : 0;
        $data_sender_id = array($sender_id => $approved);
        $sender_id_description = trim($sender_id_description) ? trim($sender_id_description) : $sender_id;
        $data_description = array($sender_id => $sender_id_description);
        $uid = auth_isadmin() && $uid ? $uid : $user_config['uid'];
        if ($uid) {
            registry_update($uid, 'features', 'sender_id', $data_sender_id);
            $ret = registry_update($uid, 'features', 'sender_id_desc', $data_description);
        } else {
            // unknown error
            return FALSE;
        }
        if ($ret[$sender_id]) {
            _log('sender ID has been added id:' . $sender_id . ' uid:' . $uid, 2, 'sender_id_add');
        } else {
            _log('fail to add sender ID id:' . $sender_id . ' uid:' . $uid, 2, 'sender_id_add');
            return FALSE;
        }
        // if default and approved
        if (auth_isadmin() && $default && $approved) {
            sender_id_default_set($uid, $sender_id);
        }
        // notify admins if user or subuser
        if ($user_config['status'] == 3 || $user_config['status'] == 4) {
            $admins = user_getallwithstatus(2);
            foreach ($admins as $admin) {
                $message_to_admins = sprintf(_('Username %s with account ID %d has requested approval for sender ID %s'), user_uid2username($uid), $uid, $sender_id);
                recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $admin['username'], $message_to_admins);
            }
        }
        // added
        return TRUE;
    }
}
Beispiel #6
0
function simplerate_hook_rate_deduct($smslog_id)
{
    global $core_config;
    logger_print("enter smslog_id:" . $smslog_id, 2, "simplerate deduct");
    $db_query = "SELECT p_dst,p_footer,p_msg,uid,unicode FROM " . _DB_PREF_ . "_tblSMSOutgoing WHERE smslog_id='{$smslog_id}'";
    $db_result = dba_query($db_query);
    if ($db_row = dba_fetch_array($db_result)) {
        $p_dst = $db_row['p_dst'];
        $p_msg = $db_row['p_msg'];
        $p_footer = $db_row['p_footer'];
        $uid = $db_row['uid'];
        $unicode = $db_row['unicode'];
        if ($p_dst && $p_msg && $uid) {
            // get charge
            $p_msg_len = strlen($p_msg) + strlen($p_footer);
            list($count, $rate, $charge) = rate_getcharges($uid, $p_msg_len, $unicode, $p_dst);
            // sender's
            $username = user_uid2username($uid);
            $credit = rate_getusercredit($username);
            $balance = $credit - $charge;
            // parent's when sender is a subuser
            $parent_uid = user_getparentbyuid($uid);
            if ($parent_uid) {
                $username_parent = user_uid2username($parent_uid);
                $credit_parent = rate_getusercredit($username_parent);
                $balance_parent = $credit_parent - $charge;
            }
            // if sender have parent then deduct parent first
            if ($parent_uid) {
                if (!rate_setusercredit($parent_uid, $balance_parent)) {
                    return FALSE;
                }
                logger_print("parent uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " msglen:" . $p_msg_len . " count:" . $count . " rate:" . $rate . " charge:" . $charge . " credit_parent:" . $credit_parent . " balance_parent:" . $balance_parent, 2, "simplerate deduct");
            }
            if (rate_setusercredit($uid, $balance)) {
                logger_print("user uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id . " msglen:" . $p_msg_len . " count:" . $count . " rate:" . $rate . " charge:" . $charge . " credit:" . $credit . " balance:" . $balance, 2, "simplerate deduct");
                if (billing_post($smslog_id, $rate, $credit, $count, $charge)) {
                    logger_print("deduct successful uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
                    // if balance under credit lowest limit and never been notified then notify admins, parent_uid and uid
                    $credit_lowest_limit = (double) $core_config['main']['credit_lowest_limit'];
                    _log('credit_lowest_limit:' . $credit_lowest_limit . ' balance:' . $balance . ' charge:' . $charge, 3, 'simplerate deduct');
                    $reg = registry_search($uid, 'feature', 'credit', 'lowest_limit_notif');
                    $notified = $reg['feature']['credit']['lowest_limit_notif'] ? TRUE : FALSE;
                    if ($charge && $balance && $credit_lowest_limit && $balance <= $credit_lowest_limit && !$notified) {
                        // set notified
                        registry_update($uid, 'feature', 'credit', array('lowest_limit_notif' => TRUE));
                        // notif admins
                        $admins = user_getallwithstatus(2);
                        foreach ($admins as $admin) {
                            $credit_message_to_admins = sprintf(_('Username %s with account ID %d has reached lowest credit limit of %s'), $username, $uid, $credit_lowest_limit);
                            recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $admin['username'], $credit_message_to_admins);
                        }
                        // notif parent_uid if exists
                        if ($parent_uid && $username_parent) {
                            $credit_message_to_parent = sprintf(_('Your subuser with username %s and account ID %d has reached lowest credit limit of %s'), $username, $uid, $credit_lowest_limit);
                            recvsms_inbox_add(core_get_datetime(), _SYSTEM_SENDER_ID_, $username_parent, $credit_message_to_parent);
                        }
                        // notif uid
                        $sender_username = $username_parent ? $username_parent : _SYSTEM_SENDER_ID_;
                        $credit_message_to_self = sprintf(_('You have reached lowest credit limit of %s'), $credit_lowest_limit);
                        recvsms_inbox_add(core_get_datetime(), $sender_username, $username, $credit_message_to_self);
                        _log('sent notification credit_lowest_limit:' . $credit_lowest_limit, 3, 'simplerate deduct');
                    }
                    return TRUE;
                } else {
                    logger_print("deduct failed uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
                    return FALSE;
                }
            } else {
                logger_print("rate deduct failed due to unable to save to db uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
            }
        } else {
            logger_print("rate deduct failed due to empty data uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
        }
    } else {
        logger_print("rate deduct failed due to missing data uid:" . $uid . " parent_uid:" . $parent_uid . " smslog_id:" . $smslog_id, 3, "simplerate deduct");
    }
    return FALSE;
}