Esempio n. 1
0
function GetReceipt($id)
{
    $db = LMSDB::getInstance();
    if ($receipt = $db->GetRow('SELECT d.*, u.name AS user, n.template,
					ds.name AS d_name, ds.address AS d_address,
					ds.zip AS d_zip, ds.city AS d_city
				FROM documents d
				LEFT JOIN vusers u ON (d.userid = u.id)
				LEFT JOIN numberplans n ON (d.numberplanid = n.id)
				LEFT JOIN customers c ON (d.customerid = c.id)
				LEFT JOIN divisions ds ON (ds.id = c.divisionid)
				WHERE d.type = 2 AND d.id = ?', array($id))) {
        $receipt['contents'] = $db->GetAll('SELECT * FROM receiptcontents WHERE docid = ? ORDER BY itemid', array($id));
        $receipt['total'] = 0;
        foreach ($receipt['contents'] as $row) {
            $receipt['total'] += $row['value'];
        }
        $receipt['number'] = docnumber(array('number' => $receipt['number'], 'template' => $receipt['template'], 'cdate' => $receipt['cdate'], 'ext_num' => $receipt['extnumber'], 'customerid' => $receipt['customerid']));
        if ($receipt['total'] < 0) {
            $receipt['type'] = 'out';
            // change values sign
            foreach ($receipt['contents'] as $idx => $row) {
                $receipt['contents'][$idx]['value'] *= -1;
            }
            $receipt['total'] *= -1;
        } else {
            $receipt['type'] = 'in';
        }
        $receipt['totalg'] = round($receipt['total'] * 100 - (int) $receipt['total'] * 100);
        return $receipt;
    }
}
Esempio n. 2
0
function select_customer($id)
{
    $JSResponse = new xajaxResponse();
    $nodes_location = LMSDB::getInstance()->GetAll('SELECT n.id, n.name, location FROM vnodes n WHERE ownerid = ? ORDER BY n.name ASC', array($id));
    $JSResponse->call('update_nodes_location', (array) $nodes_location);
    return $JSResponse;
}
Esempio n. 3
0
function IncomePerMonth($only_year)
{
    global $LMS, $SMARTY, $SESSION;
    $db = LMSDB::getInstance();
    $income = $db->GetAll('SELECT MONTH(FROM_UNIXTIME(time)) as month, SUM(value) AS suma FROM cash WHERE value>0 AND YEAR(FROM_UNIXTIME(time))=' . $only_year . ' GROUP BY month(FROM_UNIXTIME(time))');
    return $income;
}
Esempio n. 4
0
 public function __construct($load_policy = null)
 {
     $this->DB = LMSDB::getInstance();
     if ($load_policy !== null) {
         $this->setLoadPolicy($load_policy);
     }
 }
Esempio n. 5
0
function getEventsToClose($userid)
{
    global $LMS, $SMARTY, $SESSION;
    $db = LMSDB::getInstance();
    $events = $db->GetAll('SELECT from_unixtime(e.date, \'%Y-%m-%d\') AS startdate, e.title, e.id
			FROM events e, eventassignments ea WHERE e.closed=0 AND ea.userid=' . $userid . ' AND e.id=ea.eventid');
    return $events;
}
Esempio n. 6
0
function GetEventList($year = NULL, $month = NULL, $day = NULL, $forward = 0, $customerid = 0, $userid = 0, $type = 0, $privacy = 0, $closed = '')
{
    global $AUTH;
    $DB = LMSDB::getInstance();
    if (!$year) {
        $year = date('Y', time());
    }
    if (!$month) {
        $month = date('n', time());
    }
    if (!$day) {
        $day = date('j', time());
    }
    $startdate = mktime(0, 0, 0, $month, $day, $year);
    $enddate = mktime(0, 0, 0, $month, $day + $forward, $year);
    $list = $DB->GetAll('SELECT events.id AS id, title, note, description, date, begintime, enddate, endtime, customerid, closed, events.type, ' . $DB->Concat('UPPER(c.lastname)', "' '", 'c.name') . ' AS customername,
		userid, users.name AS username, ' . $DB->Concat('c.city', "', '", 'c.address') . ' AS customerlocation, nodeid, nodes.location AS location 
		FROM events 
		LEFT JOIN nodes ON (nodeid = nodes.id)
		LEFT JOIN customerview c ON (customerid = c.id)
		LEFT JOIN users ON (userid = users.id)
		WHERE ((date >= ? AND date < ?) OR (enddate <> 0 AND date < ? AND enddate >= ?))
			AND (private = 0 OR (private = 1 AND userid = ?)) ' . ($customerid ? ' AND customerid = ' . intval($customerid) : '') . ($userid ? ' AND EXISTS (
			SELECT 1 FROM eventassignments 
			WHERE eventid = events.id AND userid = ' . intval($userid) . '
			)' : '') . ($type ? ' AND events.type = ' . intval($type) : '') . ($privacy == 1 ? ' AND private = 0' : ($privacy == 2 ? ' AND private = 1' : '')) . ($closed != '' ? ' AND closed = ' . intval($closed) : '') . ' ORDER BY date, begintime', array($startdate, $enddate, $enddate, $startdate, $AUTH->id));
    $list2 = array();
    if ($list) {
        foreach ($list as $idx => $row) {
            $row['userlist'] = $DB->GetAll('SELECT userid AS id, users.name
					FROM eventassignments, users
					WHERE userid = users.id AND eventid = ? ', array($row['id']));
            $endtime = $row['endtime'];
            if ($row['enddate'] && $row['enddate'] - $row['date']) {
                $days = round(($row['enddate'] - $row['date']) / 86400);
                $row['enddate'] = $row['date'] + 86400;
                $row['endtime'] = 0;
                $list2[] = $row;
                while ($days) {
                    if ($days == 1) {
                        $row['endtime'] = $endtime;
                    }
                    $row['date'] += 86400;
                    list($year, $month, $day) = explode('/', date('Y/n/j', $row['date']));
                    $row['date'] = mktime(0, 0, 0, $month, $day, $year);
                    $row['enddate'] = $row['date'] + 86400;
                    if ($days > 1 || $endtime) {
                        $list2[] = $row;
                    }
                    $days--;
                }
            } else {
                $list2[] = $row;
            }
        }
    }
    return $list2;
}
Esempio n. 7
0
 /**
  * Loads plugin database schema updates
  */
 protected function upgradeDb()
 {
     $constant = get_class($this) . '::PLUGIN_DBVERSION';
     if (defined($constant)) {
         $libdir = $this->dirname . DIRECTORY_SEPARATOR . 'lib';
         $docdir = $this->dirname . DIRECTORY_SEPARATOR . 'doc';
         $this->dbschversion = LMSDB::getInstance()->UpgradeDb(constant($constant), get_class($this), $libdir, $docdir);
     }
 }
Esempio n. 8
0
 /**
  * Return user rights mask
  * 
  * @param array $options Associative array of options
  * @return array
  */
 public function load(array $options = array())
 {
     if (!isset($options['user_id'])) {
         throw new Exception('User id not set. Cannot find user rights config!');
     }
     $id = $options['user_id'];
     $db = LMSDB::getInstance();
     return array($db->GetOne('SELECT rights FROM users WHERE id = ?', array($id)));
 }
Esempio n. 9
0
function select_producer($id)
{
    $JSResponse = new xajaxResponse();
    $models = LMSDB::getInstance()->GetAll('
        SELECT id, name
        FROM netdevicemodels 
        WHERE netdeviceproducerid = ?
        ORDER BY name', array($id));
    $JSResponse->call('update_models', (array) $models);
    return $JSResponse;
}
Esempio n. 10
0
function deletedCustomers($year)
{
    global $LMS, $SMARTY, $SESSION;
    $db = LMSDB::getInstance();
    $deletedcustomers = $db->GetAll('
    SELECT COUNT(id) AS customers, MONTH(FROM_UNIXTIME(moddate)) as month
    FROM customers
    WHERE deleted=1 AND YEAR(FROM_UNIXTIME(moddate))=' . $year . ' 
    GROUP BY MONTH(FROM_UNIXTIME(moddate))
    ');
    return $deletedcustomers;
}
Esempio n. 11
0
function findAlreadyExists(&$prefixList)
{
    $DB = LMSDB::getInstance();
    $prefixHelperArray = $DB->GetAllByKey("SELECT id, prefix FROM voip_prefixes", "prefix");
    $exists = array();
    foreach ($prefixList as $v => $k) {
        if (isset($prefixHelperArray[$v])) {
            $exists[] = $v;
        }
    }
    return $exists ? $exists : NULL;
}
Esempio n. 12
0
function getSummary()
{
    global $LMS, $SMARTY, $SESSION;
    $db = LMSDB::getInstance();
    $summary = $db->GetAll('SELECT u.id, u.name, COUNT(e.closed) AS wszystkie, SUM(IF(e.closed, 1, 0)) AS zamkniete, SUM(IF(e.closed, 0, 1)) AS otwarte
			    FROM eventassignments ea
			    LEFT JOIN users u ON (u.id = ea.userid)
			    LEFT JOIN events e ON (e.id = ea.eventid)
			    WHERE u.deleted=0
			    GROUP BY ea.userid');
    return $summary;
}
Esempio n. 13
0
function getUsersForGroup($groupid)
{
    $JSResponse = new xajaxResponse();
    if (empty($groupid)) {
        $users = null;
    } else {
        $users = LMSDB::getInstance()->GetCol('SELECT u.id FROM users u
			JOIN userassignments ua ON ua.userid = u.id
			WHERE u.deleted = 0 AND u.access = 1 AND ua.usergroupid = ?', array($groupid));
    }
    $JSResponse->call('update_user_selection', $users);
    return $JSResponse;
}
Esempio n. 14
0
function GetEvents($date = NULL, $userid = 0, $customerid = 0, $privacy = 0, $closed = '')
{
    global $AUTH;
    $DB = LMSDB::getInstance();
    switch ($privacy) {
        case 0:
            $privacy_condition = '(private = 0 OR (private = 1 AND userid = ' . intval($AUTH->id) . '))';
            break;
        case 1:
            $privacy_condition = 'private = 0';
            break;
        case 2:
            $privacy_condition = 'private = 1 AND userid = ' . intval($AUTH->id);
            break;
    }
    $enddate = $date + 86400;
    $list = $DB->GetAll('SELECT events.id AS id, title, note, description, date, begintime, enddate, endtime, closed, events.type,' . $DB->Concat('UPPER(c.lastname)', "' '", 'c.name') . ' AS customername, ' . $DB->Concat('c.city', "', '", 'c.address') . ' AS customerlocation,
		 nodes.location AS nodelocation,
		 (SELECT contact FROM customercontacts WHERE customerid = c.id
			AND (customercontacts.type & ?) > 0 AND (customercontacts.type & ?) <> ?  ORDER BY id LIMIT 1) AS customerphone
		 FROM events LEFT JOIN customerview c ON (customerid = c.id) LEFT JOIN nodes ON (nodeid = nodes.id)
		 WHERE ((date >= ? AND date < ?) OR (enddate <> 0 AND date < ? AND enddate >= ?)) AND ' . $privacy_condition . ($customerid ? 'AND customerid = ' . intval($customerid) : '') . ($closed != '' ? ' AND closed = ' . intval($closed) : '') . ' ORDER BY date, begintime', array(CONTACT_MOBILE | CONTACT_FAX | CONTACT_LANDLINE, CONTACT_DISABLED, CONTACT_DISABLED, $date, $enddate, $enddate, $date));
    $list2 = array();
    if ($list) {
        foreach ($list as $idx => $row) {
            $row['userlist'] = $DB->GetAll('SELECT userid AS id, vusers.name
				FROM eventassignments, vusers
				WHERE userid = vusers.id AND eventid = ? ', array($row['id']));
            $endtime = $row['endtime'];
            if ($row['enddate'] && $row['enddate'] - $row['date']) {
                $days = round(($row['enddate'] - $row['date']) / 86400);
                $row['enddate'] = $row['date'] + 86400;
                $row['endtime'] = 0;
                $list2[] = $row;
            } else {
                $list2[] = $row;
            }
        }
    }
    return $list2;
}
Esempio n. 15
0
 public function __construct()
 {
     $this->DB = LMSDB::getInstance();
 }
Esempio n. 16
0
function GetConfigList()
{
    $DB = LMSDB::getInstance();
    $config = $DB->GetAll('SELECT id, section, var, value, description as usercomment, disabled 
			FROM uiconfig WHERE section != \'userpanel\'');
    if ($config) {
        foreach ($config as $idx => $item) {
            switch ($item['section']) {
                case 'phpui':
                    switch ($item['var']) {
                        case 'autosuggest_max_length':
                            $config[$idx]['description'] = trans('Max length of auto suggest proposal, further characters will be dotted.');
                            break;
                        case 'default_autosuggest_placement':
                            $config[$idx]['description'] = trans('Default placement of suggestion window (left/right/top/bottom)');
                            break;
                        case 'allow_from2':
                            $config[$idx]['description'] = trans('List of networks and IP addresses, with access to LMS. If empty, every IP address has access to LMS. When you write list of addresses or address pools here, LMS will dismiss every unwanted user with HTTP 403 error.');
                            break;
                        case 'allow_from':
                            $config[$idx]['description'] = trans('List of networks and IP addresses, with access to LMS. If empty, every IP address has access to LMS. When you write list of addresses or address pools here, LMS will dismiss every unwanted user with HTTP 403 error.');
                            break;
                        case 'lang':
                            $config[$idx]['description'] = trans('System language code. If not set, language will be determined on browser settings. Default: en.');
                            break;
                        case 'timeout':
                            $config[$idx]['description'] = trans('WWW session timeout. After that time (in seconds) user will be logged out if action has been made. Default: 600.');
                            break;
                        case 'customerlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in customers list. Default: 100.');
                            break;
                        case 'nodelist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in nodes list. Default: 100.');
                            break;
                        case 'balancelist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in customer\'s balance. Default: 100.');
                            break;
                        case 'configlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in UI config options list. Default: 100.');
                            break;
                        case 'invoicelist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in invoices list. Default: 100.');
                            break;
                        case 'ticketlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in tickets (requests) list. Default: 100.');
                            break;
                        case 'accountlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in accounts list. Default: 100.');
                            break;
                        case 'domainlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in domains list. Default: 100.');
                            break;
                        case 'aliaslist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in aliases list. Default: 100.');
                            break;
                        case 'receiptlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in cash receipts list. Default: 100.');
                            break;
                        case 'taxratelist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in tax rates list. Default: 100.');
                            break;
                        case 'numberplanlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in numbering plans list. Default: 100.');
                            break;
                        case 'billinglist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of billings displayed on one page. Default: 100.');
                            break;
                        case 'divisionlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in divisions list. Default: 100.');
                            break;
                        case 'documentlist_pagelimit':
                            $config[$idx]['description'] = trans('Limit of records displayed on one page in documents list. Default: 100.');
                            break;
                        case 'networkhosts_pagelimit':
                            $config[$idx]['description'] = trans('Limit of nodes displayed on one page in Network Information. Default: 256. With 0, this information is omitted (page is displaying faster).');
                            break;
                        case 'force_ssl':
                            $config[$idx]['description'] = trans('SSL Enforcing. Setting this option to 1 will effect with that LMS will enforce SSL connection with redirect to \'https://\'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI] at every request without SSL. Default: 0 (off).');
                            break;
                        case 'reload_timer':
                            $config[$idx]['description'] = trans('Reload timer. If set to true it will display remaining time to configuration reload. If using more than one host, remember to sync time between them.');
                            break;
                        case 'reload_type':
                            $config[$idx]['description'] = trans('Reload type. Allowed values: exec - call some command (most often with sudo, some script or something else, configurable below); sql - writes down to SQL (multiple queries separated with semicolon may be setup).');
                            break;
                        case 'reload_execcmd':
                            $config[$idx]['description'] = trans('Command to run during reload, if reload_type is set to \'exec\'. By default /bin/true. That string is sent to command system(), so I propose you to think what you do and how :) Altogether, semicolons should be parsed by bash, but LMS splits that string and execute commands separately.');
                            break;
                        case 'reload_sqlquery':
                            $config[$idx]['description'] = trans('SQL query executed while reload, if reload_type = sql. Default: empty. You can use \'%TIME%\' as replacement to current unix timestamp. WARNING! Semicolon is handled as query separator, which means that you can enter couple of SQL queries separated by semicolon sign.');
                            break;
                        case 'allow_mac_sharing':
                            $config[$idx]['description'] = trans('Allow nodes addition with duplicated MAC address (not checking that some computer have that MAC yet). Default: 0 (off).');
                            break;
                        case 'default_zip':
                        case 'default_city':
                        case 'default_address':
                            $config[$idx]['description'] = trans('Default zip code, city, street, used while inserting new customer. Useful if you add majority of customers with the same street.');
                            break;
                        case 'lastonline_limit':
                            $config[$idx]['description'] = trans('Specify time (in seconds), after which node will be marked offline. It should match with frequency of running nodes activity script (i.e. lms-fping). Default: 600.');
                            break;
                        case 'use_current_payday':
                            $config[$idx]['description'] = trans('Qualify to use current day of month for payment day. Default: 0 (off).');
                            break;
                        case 'default_monthly_payday':
                            $config[$idx]['description'] = trans('Qualify the day of month for payment day. Default: 0 (undefined).');
                            break;
                        case 'smarty_debug':
                            $config[$idx]['description'] = trans('Enable Smarty\'s debug console. Useful for tracking values passed from PHP to Smarty. Default: 0 (off).');
                            break;
                        case 'arpd_servers':
                            $config[$idx]['description'] = trans('List of arpd servers for MAC addresses retrieval from remote networks. That list should include IP[:port] items separated with spaces. Default: empty.');
                            break;
                        case 'helpdesk_backend_mode':
                            $config[$idx]['description'] = trans('When enabled, all messages in helpdesk system (except those sent to requester) will be sent to mail server corresponding queue address. lms-rtparser script should be running on server. Messages won\'t be written directly to database, but on solely responsibility of rtparser script. Default: disabled.');
                            break;
                        case 'helpdesk_sender_name':
                            $config[$idx]['description'] = trans('Name of messages sender or predefined variables: "queue" - queue name, "user" - logged user name. Default: none.');
                            break;
                        case 'newticket_notify':
                            $config[$idx]['description'] = trans('When enabled, system will sent notification to all users with rights for current queue after new ticket creation. Default: disabled.');
                            break;
                        case 'to_words_short_version':
                            $config[$idx]['description'] = trans('Specify format of verbal amounts representation (on invoices). e.g. for value "1" verbal expand of 123,15 will be "one two thr 15/100". Default: 0.');
                            break;
                        case 'timetable_days_forward':
                            $config[$idx]['description'] = trans('Number of days (including current day) on timetable. Default: 7.');
                            break;
                        case 'gd_translate_to':
                            $config[$idx]['description'] = trans('Charset of data gd library expects (useful if gd library needs ISO-8859-2 instead of UTF-8 to feed imagetext() function).');
                            break;
                        case 'nodepassword_length':
                            $config[$idx]['description'] = trans('Length of (auto-generated) node password. Max.32. Default: 16.');
                            break;
                        case 'custom_accesstable':
                            $config[$idx]['description'] = trans('PHP file with user-defined access rules in "lib" directory. Default: empty.');
                            break;
                        case 'check_for_updates_period':
                            $config[$idx]['description'] = trans('How often to check for LMS updates (in seconds). Default: 86400.');
                            break;
                        case 'map_type':
                            $config[$idx]['description'] = trans('Network map type. Use "flash" if you have Ming library or "gd" if your PHP supports gdlib. By default LMS will try to generate flash map, with fallback to GD if it fails.');
                            break;
                        case 'homedir_prefix':
                            $config[$idx]['description'] = trans('Prefix for account home directory. Default: /home/');
                            break;
                        case 'default_taxrate':
                            $config[$idx]['description'] = trans('Value of tax rate which will be selected by default on tax rates lists. Default: 22.0');
                            break;
                        case 'default_prodid':
                            $config[$idx]['description'] = trans('Value of product ID. Default: empty');
                            break;
                        case 'helpdesk_reply_body':
                            $config[$idx]['description'] = trans('Adds body of message in ticket reply. Default: false');
                            break;
                        case 'big_networks':
                            $config[$idx]['description'] = trans('Support for big ISPs e.g. hidding long customers selection dropdowns. Default: false');
                            break;
                        case 'short_pagescroller':
                            $config[$idx]['description'] = trans('Enables page scroller designed for lists with very big number of pages. Default: false');
                            break;
                        case 'ewx_support':
                            $config[$idx]['description'] = trans('Support for EtherWerX devices. Default: false');
                            break;
                        case 'helpdesk_stats':
                            $config[$idx]['description'] = trans('Adds helpdesk requests causes stats on ticket view and print pages. Default: true');
                            break;
                        case 'helpdesk_customerinfo':
                            $config[$idx]['description'] = trans('Adds customer basic information on ticket view and in notifications. Default: true');
                            break;
                        case 'ticket_template_file':
                            $config[$idx]['description'] = trans('Helpdesk ticket printout template file. Default: rtticketprint.html');
                            break;
                        case 'ticketlist_status':
                            $config[$idx]['description'] = trans('Default status filter setting on tickets list. For allowed values see html source code. Default: not set');
                            break;
                        case 'use_invoices':
                            $config[$idx]['description'] = trans('Makes option "with invoice" checked by default. Default: false');
                            break;
                        case 'default_module':
                            $config[$idx]['description'] = trans('Start-up module (filename from /modules without .php). Default: welcome');
                            break;
                        case 'default_assignment_period':
                            $config[$idx]['description'] = trans('Default period value for assignment. Default: 0');
                            break;
                        case 'arp_table_backend':
                            $config[$idx]['description'] = trans('Command which returns IP-MAC bindings. Default: internal backend');
                            break;
                        case 'report_type':
                            $config[$idx]['description'] = trans('Documents type. You can use "html" or "pdf". Default: html.');
                            break;
                        case 'hide_toolbar':
                            $config[$idx]['description'] = trans('Hide toolbar from user interface. Default: false.');
                            break;
                        case 'logging':
                            $config[$idx]['description'] = trans('Does this LMS have transaction log support (not opensource). Default: false.');
                            break;
                        case 'add_customer_group_required':
                            $config[$idx]['description'] = trans('If isset "true" when adding new customer select group is required. Default "false"');
                            break;
                        case 'event_max_userlist_size':
                            $config[$idx]['description'] = trans('Automatically adjusts the size of the selection list to the number of users when set to 0.');
                            break;
                        case 'ping_type':
                            $config[$idx]['description'] = trans('Default ping type. You can use "1" for ping or "2" for arping. Default: 1.');
                            break;
                        case 'default_teryt_city':
                            $config[$idx]['description'] = trans('Default City in TERYT. Set city id in TERYT.');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'payments':
                    switch ($item['var']) {
                        case 'date_format':
                            $config[$idx]['description'] = trans('Define date format for variable: %period, %aligned_period, %current_month used in payments.comment and payments.settlement_comment');
                            break;
                        case 'default_unit_name':
                            $config[$idx]['description'] = trans('Unit name on invoice, default: "pcs."');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'finances':
                    switch ($item['var']) {
                        case 'suspension_percentage':
                            $config[$idx]['description'] = trans('Percentage of suspended liabilities. Default: 0');
                            break;
                        case 'cashimport_checkinvoices':
                            $config[$idx]['description'] = trans('Check invoices as accounted when importing cash operations. Default: false');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'invoices':
                    switch ($item['var']) {
                        case 'header':
                            $config[$idx]['description'] = trans('This is a seller data. A new line replacement is "\\n" sign, e.g. SuperNet ISP\\n00-950 Warsaw\\nWiosenna 52\\n0 49 3883838\\n\\naccounting@supernet.pl\\n\\nNIP: 123-123-12-23');
                            break;
                        case 'footer':
                            $config[$idx]['description'] = trans('Small font text appearing in selected (in template) place of the invoice, e.g. Our Bank: SNETISP, 828823917293871928371\\nPhone number 555 123 123');
                            break;
                        case 'default_author':
                            $config[$idx]['description'] = trans('Default invoice issuer');
                            break;
                        case 'cplace':
                            $config[$idx]['description'] = trans('Invoice draw-up place.');
                            break;
                        case 'template_file':
                            $config[$idx]['description'] = trans('Invoice template file. Default: "invoice.html". Should be placed in templates directory.');
                            break;
                        case 'cnote_template_file':
                            $config[$idx]['description'] = trans('Credit note template file. Default: "invoice.html". Should be placed in templates directory.');
                            break;
                        case 'content_type':
                            $config[$idx]['description'] = trans('Content-type for document. If you enter "application/octet-stream", browser will send file to save on disk, instead of displaying it. It\'s useful if you use your own template which generate e.g. rtf or xls file. Default: "text/html".');
                            break;
                        case 'attachment_name':
                            $config[$idx]['description'] = trans('File name for saving document printout. WARNING: Setting attachment_name with default content_type will (in case of MSIE) print document, and prompt for save on disk. Default: empty.');
                            break;
                        case 'type':
                            $config[$idx]['description'] = trans('Documents type. You can use "html" or "pdf". Default: html.');
                            break;
                        case 'print_balance_history':
                            $config[$idx]['description'] = trans('If true on invoice (html) will be printed history of financial operations on customer account. Default: not set.');
                            break;
                        case 'print_balance_history_limit':
                            $config[$idx]['description'] = trans('Number of Records on customer balance list on invoice. Specify last x records. Default: 10.');
                            break;
                        case 'default_printpage':
                            $config[$idx]['description'] = trans('Coma-separated list of default invoice printout pages. You can use "original", "copy", "duplicate". Default: "original,copy".');
                            break;
                        case 'radius':
                            $config[$idx]['description'] = trans('Enable RADIUS support. Default: 1');
                            break;
                        case 'public_ip':
                            $config[$idx]['description'] = trans('Enable public IP address fields. Default: 1');
                            break;
                        case 'paytime':
                            $config[$idx]['description'] = trans('Default documents paytime in days. Default: 14');
                            break;
                        case 'paytype':
                            $config[$idx]['description'] = trans('Default invoices paytype. Default: "1" (cash)');
                            break;
                        case 'customer_bankaccount':
                            $config[$idx]['description'] = trans('Show bankaccount on invoice. Default: 0');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'notes':
                    switch ($item['var']) {
                        case 'template_file':
                            $config[$idx]['description'] = trans('Debit note template file. Default: "note.html". Should be placed in templates directory.');
                            break;
                        case 'content_type':
                            $config[$idx]['description'] = trans('Content-type for document. If you enter "application/octet-stream", browser will send file to save on disk, instead of displaying it. It\'s useful if you use your own template which generate e.g. rtf or xls file. Default: "text/html".');
                            break;
                        case 'attachment_name':
                            $config[$idx]['description'] = trans('File name for saving document printout. WARNING: Setting attachment_name with default content_type will (in case of MSIE) print document, and prompt for save on disk. Default: empty.');
                            break;
                        case 'type':
                            $config[$idx]['description'] = trans('Documents type. You can use "html" or "pdf". Default: html.');
                            break;
                        case 'paytime':
                            $config[$idx]['description'] = trans('Default documents paytime in days. Default: 14');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'receipts':
                    switch ($item['var']) {
                        case 'template_file':
                            $config[$idx]['description'] = trans('Cash receipt template file. Default: "receipt.html". Should be placed in templates directory.');
                            break;
                        case 'content_type':
                            $config[$idx]['description'] = trans('Content-type for document. If you enter "application/octet-stream", browser will send file to save on disk, instead of displaying it. It\'s useful if you use your own template which generate e.g. rtf or xls file. Default: "text/html".');
                            break;
                        case 'attachment_name':
                            $config[$idx]['description'] = trans('File name for saving document printout. WARNING: Setting attachment_name with default content_type will (in case of MSIE) print document, and prompt for save on disk. Default: empty.');
                            break;
                        case 'type':
                            $config[$idx]['description'] = trans('Documents type. You can use "html" or "pdf". Default: html.');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'mail':
                    switch ($item['var']) {
                        case 'debug_email':
                            $config[$idx]['description'] = trans('E-mail address for debugging - messages from \'Mailing\' module will be sent at this address, instead to real users.');
                            break;
                        case 'smtp_port':
                        case 'smtp_host':
                        case 'smtp_username':
                        case 'smtp_password':
                        case 'smtp_auth_type':
                            $config[$idx]['description'] = trans('SMTP settings.');
                            break;
                        case 'backend':
                            $config[$idx]['description'] = trans('Mail backend settings. Available options: pear or phpmailer.');
                            break;
                        case 'phpmailer_from':
                            $config[$idx]['description'] = trans('E-mail address from which we send mail.');
                            break;
                        case 'phpmailer_from_name':
                            $config[$idx]['description'] = trans('E-mail address name from which we send mail.');
                            break;
                        case 'phpmailer_is_html':
                            $config[$idx]['description'] = trans('Email message in html format.');
                            break;
                        case 'smtp_secure':
                            $config[$idx]['description'] = trans('Security protocol. Available options: ssl or tls.');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'sms':
                    switch ($item['var']) {
                        case 'service':
                            $config[$idx]['description'] = trans('Default service type for sending text messages.');
                            break;
                        case 'prefix':
                            $config[$idx]['description'] = trans('Country prefix code, needed for number validation. Default: 48');
                            break;
                        case 'from':
                            $config[$idx]['description'] = trans('Default sender of a text message.');
                            break;
                        case 'username':
                            $config[$idx]['description'] = trans('Username for smscenter service');
                            break;
                        case 'password':
                            $config[$idx]['description'] = trans('Password for smscenter service');
                            break;
                        case 'smscenter_type':
                            $config[$idx]['description'] = trans('Type of account you have at smscenter service. LMS will add sender at the end of message, when static type has been set. Correct values are: static and dynamic');
                            break;
                        default:
                            $config[$idx]['description'] = trans('Unknown option. No description.');
                            break;
                    }
                    //end: var
                    break;
                case 'zones':
                    switch ($item['var']) {
                        case 'hostmaster_mail':
                            $config[$idx]['description'] = trans('Domain admin e-mail address.');
                            break;
                        case 'master_dns':
                            $config[$idx]['description'] = trans('Primary Name Server name (should be a FQDN).');
                            break;
                        case 'slave_dns':
                            $config[$idx]['description'] = trans('Secondary Name Server name (should be a FQDN).');
                            break;
                        case 'default_mx':
                            $config[$idx]['description'] = trans('Mail Exchange (MX) name record which identifies the name of the server that handles mail for domain (should be a FQDN).');
                            break;
                        case 'default_ttl':
                            $config[$idx]['description'] = trans('The default expiration time of a resource record. Default 86400.');
                            break;
                        case 'ttl_refresh':
                            $config[$idx]['description'] = trans('Time after slave server refreshes records. Default 28800.');
                            break;
                        case 'ttl_retry':
                            $config[$idx]['description'] = trans('Slave server retry time in case of a problem. Default 7200.');
                            break;
                        case 'ttl_expire':
                            $config[$idx]['description'] = trans('Records expiration time. Default 604800.');
                            break;
                        case 'ttl_minimum':
                            $config[$idx]['description'] = trans('Minimum caching time in case of failed lookups. Default 86400.');
                            break;
                        case 'default_webserver_ip':
                            $config[$idx]['description'] = trans('IP address of webserver');
                            break;
                        case 'default_mailserver_ip':
                            $config[$idx]['description'] = trans('IP address of mailserver');
                            break;
                        case 'default_spf':
                            $config[$idx]['description'] = trans('Default SPF record. If you leave the field blank, record will not add. Example: "v=spf1 a mx ip4:ADDRESS_MAILSERVER ~all" (Put in quotes).');
                            break;
                    }
                    //end: var
                    break;
                default:
                    $config[$idx]['description'] = trans('Unknown option. No description.');
                    break;
            }
            //end: section
            if (!empty($config[$idx]['usercomment'])) {
                $config[$idx]['usercomment'] = str_replace("\n", '<br>', $config[$idx]['usercomment']);
            }
        }
    }
    //end: foreach
    return $config;
}
Esempio n. 17
0
 public function getPrefixGroupName($number, $t_id)
 {
     if (isset($this->number_groupname[$number . '|' . $t_id])) {
         return $this->number_groupname[$number . '|' . $t_id];
     }
     $DB = LMSDB::getInstance();
     $pref = $this->getLongestPrefix($number, $t_id);
     $i = $DB->GetOne('SELECT
                          vpg.name
                       FROM
                          voip_prefixes vp 
                          LEFT JOIN voip_prefix_groups vpg ON vp.groupid = vpg.id
                       WHERE
                           prefix ?LIKE? ?', array($pref));
     $this->number_groupname[$number . '|' . $t_id] = $i;
     return $i;
 }
Esempio n. 18
0
 /**
  * Enables/Disables plugin
  *
  * @param string $name plugin name
  * @param bool $enable enable plugin flag
  */
 public function enablePlugin($name, $enable)
 {
     if (in_array($name, $this->new_style_plugins)) {
         $this->new_style_plugins[$name]['enabled'] = $enable;
     } else {
         $this->old_style_plugins[$name]['enabled'] = $enable;
     }
     $plugins_config = array();
     foreach (array_merge($this->new_style_plugins, $this->old_style_plugins) as $plugin_name => $plugin) {
         if ($plugin['enabled']) {
             $plugins_config[] = $plugin_name . (isset($plugin['priority']) && $plugin['priority'] != SubjectInterface::LAST_PRIORITY ? ':' . $plugin['priority'] : '');
         }
     }
     LMSDB::getInstance()->Execute("UPDATE uiconfig SET value = ? WHERE section = ? AND var = ?", array(implode(' ', $plugins_config), 'phpui', 'plugins'));
 }
Esempio n. 19
0
 /**
  * @covers LMSDB::destroyInstance
  */
 public function testDestroyInstance()
 {
     \LMSDB::getInstance();
     $db = \LMSDB::destroyInstance();
     $this->assertEquals($db, null);
 }
Esempio n. 20
0
function module_save_module_order()
{
    $DB = LMSDB::getInstance();
    $DB->Execute('UPDATE uiconfig SET value = ? WHERE section = ? AND var = ?', array(implode(',', $_POST['modules']), 'userpanel', 'module_order'));
    header('Content-Type: application/json');
    echo json_encode(array('result' => 'OK'));
    die;
}
Esempio n. 21
0
function getCustomerByPhone($phone_number)
{
    $DB = LMSDB::getInstance();
    $customer = $DB->GetRow('SELECT
												va.id as voipaccountid, va.phone, va.balance, t.id as tariffid
											 FROM
												voipaccounts va left join assignments a on va.ownerid = a.customerid left join tariffs t on t.id = a.tariffid
											 WHERE
												va.phone ?LIKE? ? and
												t.type = ?', array($phone_number, TARIFF_PHONE));
    if (!$customer) {
        die('Caller number phone "' . $phone_number . '" not found.' . PHP_EOL);
    }
    return $customer;
}
Esempio n. 22
0
    function module_submit_changes_save()
    {
        global $LMS, $SYSLOG_RESOURCE_KEYS;
        $DB = LMSDB::getInstance();
        if (isset($_POST['userchanges'])) {
            $args = array();
            foreach ($_POST['userchanges'] as $changeid) {
                $changes = $DB->GetRow('SELECT customerid, fieldname, fieldvalue FROM up_info_changes
					WHERE id = ?', array($changeid));
                if (!isset($args[$changes['customerid']])) {
                    $args[$changes['customerid']] = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST] => $changes['customerid'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER] => $LMS->AUTH->id);
                }
                if (preg_match('/(phone|email)([0-9]+)/', $changes['fieldname'], $matches)) {
                    if ($matches[2]) {
                        $fields = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST] => $changes['customerid'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUSTCONTACT] => $matches[2]);
                        if ($changes['fieldvalue']) {
                            $DB->Execute('UPDATE customercontacts SET contact = ? WHERE id = ?', array($changes['fieldvalue'], $matches[2]));
                            if ($LMS->SYSLOG) {
                                $fields['contact'] = $changes['fieldvalue'];
                                $LMS->SYSLOG->AddMessage(SYSLOG_RES_CUSTCONTACT, SYSLOG_OPER_UPDATE, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUSTCONTACT]));
                            }
                        } else {
                            $DB->Execute('DELETE FROM customercontacts WHERE id = ?', array($matches[2]));
                            if ($LMS->SYSLOG) {
                                $LMS->SYSLOG->AddMessage(SYSLOG_RES_CUSTCONTACT, SYSLOG_OPER_DELETE, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUSTCONTACT]));
                            }
                        }
                    } else {
                        // new phone or email
                        $DB->Execute('INSERT INTO customercontacts (contact, customerid, type) VALUES(?, ?, ?)', array($changes['fieldvalue'], $changes['customerid'], $matches[1] == 'phone' ? CONTACT_LANDLINE : CONTACT_EMAIL));
                        if ($LMS->SYSLOG) {
                            $fields = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST] => $changes['customerid'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUSTCONTACT] => $DB->GetLastInsertID('customercontacts'), 'contact' => $changes['fieldvalue'], 'type' => $matches[1] == 'phone' ? CONTACT_LANDLINE : CONTACT_EMAIL);
                            $LMS->SYSLOG->AddMessage(SYSLOG_RES_CUSTCONTACT, SYSLOG_OPER_ADD, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUSTCONTACT]));
                        }
                    }
                } else {
                    switch ($changes['fieldname']) {
                        case 'im':
                        case 'yahoo':
                        case 'skype':
                            $contact_types = array('im' => IM_GG, 'yahoo' => IM_YAHOO, 'skype' => IM_SKYPE);
                            $contact_type = $contact_types[$changes['fieldname']];
                            $fields = array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST] => $changes['customerid'], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER] => $LMS->AUTH->id, 'type' => $contact_type);
                            $DB->Execute('DELETE FROM imessengers WHERE customerid = ? AND type = ?', array($changes['customerid'], $contact_type));
                            if ($LMS->SYSLOG) {
                                $LMS->SYSLOG->AddMessage(SYSLOG_RES_IMCONTACT, SYSLOG_OPER_DELETE, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]));
                            }
                            if ($changes['fieldvalue']) {
                                $DB->Execute('INSERT INTO imessengers (customerid, uid, type) VALUES (?, ?, ?)', array($changes['customerid'], $changes['fieldvalue'], $contact_type));
                                if ($LMS->SYSLOG) {
                                    $fields['uid'] = $changes['fieldvalue'];
                                    $LMS->SYSLOG->AddMessage(SYSLOG_RES_IMCONTACT, SYSLOG_OPER_ADD, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]));
                                }
                            }
                            break;
                        case 'name':
                        case 'lastname':
                        case 'street':
                        case 'building':
                        case 'apartment':
                        case 'zip':
                        case 'city':
                        case 'ssn':
                        case 'ten':
                            $DB->Execute('UPDATE customers SET ' . $changes['fieldname'] . ' = ? WHERE id = ?', array($changes['fieldvalue'], $changes['customerid']));
                            $args[$changes['customerid']][$changes['fieldname']] = $changes['fieldvalue'];
                            break;
                    }
                }
                if ($LMS->SYSLOG && !empty($args)) {
                    foreach ($args as $customerid => $fields) {
                        if (count($fields) > 2) {
                            $LMS->SYSLOG->AddMessage(SYSLOG_RES_CUST, SYSLOG_OPER_UPDATE, $fields, array($SYSLOG_RESOURCE_KEYS[SYSLOG_RES_CUST], $SYSLOG_RESOURCE_KEYS[SYSLOG_RES_USER]));
                        }
                    }
                }
                $DB->Execute('DELETE FROM up_info_changes WHERE id = ?', array($changeid));
            }
        }
        module_changes();
    }
Esempio n. 23
0
 /**
  * Return uiconfig database table
  * 
  * @param array $options Associative array of options
  * @return array
  */
 public function load(array $options = array())
 {
     $db = LMSDB::getInstance();
     return $db->GetAll('SELECT section, var, value, description FROM uiconfig WHERE disabled = 0');
 }
Esempio n. 24
0
function valid_pool($p, $id = 0)
{
    $error = array();
    $DB = LMSDB::getInstance();
    $id = (int) $id;
    $pool_list = $DB->GetAllByKey("SELECT id, name, poolstart, poolend FROM voip_pool_numbers;", 'name');
    $name = !empty($p['name']) ? trim($p['name']) : null;
    $pstart = !empty($p['poolstart']) ? trim($p['poolstart']) : null;
    $pend = !empty($p['poolend']) ? trim($p['poolend']) : null;
    $type = !empty($p['pooltype']) ? trim($p['pooltype']) : null;
    if (empty($name)) {
        $error['name'] = trans('Name is required!');
    } else {
        if (preg_match('/[^a-zA-Z0-9\\s]+/', $name)) {
            $error['name'] = trans('Name contains forbidden characters!');
        } else {
            if (isset($pool_list[$name]) && $pool_list[$name]['id'] != $id) {
                $error['name'] = trans('Name is already in use!');
            }
        }
    }
    if (empty($pstart)) {
        $error['poolstart'] = trans('Pool start is required!');
    } else {
        if (strlen($pstart) > 20) {
            $error['poolstart'] = trans('Value is too long (max. $a characters)!', 20);
        } else {
            if (preg_match('/[^0-9]/i', $pstart)) {
                $error['poolstart'] = trans('Incorrect format! Only values 0 to 9.');
            }
        }
    }
    if (empty($pend)) {
        $error['poolend'] = trans('Pool end is required!');
    } else {
        if (strlen($pend) > 20) {
            $error['poolend'] = trans('Value is too long (max. $a characters)!', 20);
        } else {
            if (preg_match('/[^0-9]/i', $pend)) {
                $error['poolend'] = trans('Incorrect format! Only values 0 to 9.');
            }
        }
    }
    if (gmp_cmp($pstart, $pend) == 0 || gmp_cmp($pstart, $pend) == 1) {
        $error['poolstart'] = trans('Pool start must be lower that end!');
    }
    if (!getPoolTypeNameByNumber($type)) {
        $error['pooltype'] = trans("Incorrect pool type!");
    }
    foreach ($pool_list as $v) {
        if ($id == $v['id'] || !$id) {
            continue;
        }
        $check1 = gmp_cmp($pstart, $v['poolstart']);
        $check2 = gmp_cmp($pstart, $v['poolend']);
        if (($check1 == 1 || $check1 == 0) && ($check2 == -1 || $check2 == 0)) {
            $error['poolstart'] = trans('Number coincides with pool `$a` !', $v['name']);
        }
        $check1 = gmp_cmp($pend, $v['poolstart']);
        $check2 = gmp_cmp($pend, $v['poolend']);
        if (($check1 == 1 || $check1 == 0) && ($check2 == -1 || $check2 == 0)) {
            $error['poolend'] = trans('Number coincides with pool `$a` !', $v['name']);
        }
        if ($check1 == -1 && $check2 == 1) {
            $error['poolstart'] = trans('Number range coincides with pool `$a` !', $v['name']);
        }
    }
    return $error ? $error : 0;
}
Esempio n. 25
0
 function module_submit_setup()
 {
     $DB = LMSDB::getInstance();
     $DB->Execute('UPDATE uiconfig SET value = ? WHERE section = ? AND var = ?', array(isset($_POST['hide_nodesbox']) ? 1 : 0, 'userpanel', 'hide_nodesbox'));
     $DB->Execute('UPDATE uiconfig SET value = ? WHERE section = ? AND var = ?', array($_POST['consent_text'], 'userpanel', 'data_consent_text'));
     $DB->Execute('UPDATE uiconfig SET value = ? WHERE section = ? AND var = ?', array(isset($_POST['show_confirmed_documents_only']) ? 'true' : 'false', 'userpanel', 'show_confirmed_documents_only'));
     header('Location: ?m=userpanel&module=info');
 }
Esempio n. 26
0
function getFirstFreeAddress($netid, $elemid)
{
    global $LMS;
    $DB = LMSDB::getInstance();
    $result = new xajaxResponse();
    $reservedaddresses = intval(ConfigHelper::getConfig('phpui.first_reserved_addresses', 0, true));
    $net = $LMS->GetNetworkRecord($netid);
    $ip = '';
    foreach ($net['nodes']['id'] as $idx => $nodeid) {
        if ($idx < $reservedaddresses) {
            continue;
        }
        if ($nodeid) {
            $firstnodeid = $idx;
            $ip = '';
        }
        if (!$nodeid && !isset($net['nodes']['name'][$idx]) && empty($ip)) {
            $ip = $net['nodes']['address'][$idx];
            if (isset($firstnodeid)) {
                break;
            }
        }
    }
    if (!empty($ip)) {
        $result->assign($elemid, 'value', $ip);
    }
    return $result;
}
Esempio n. 27
0
function commit_cashimport()
{
    global $LMS;
    $DB = LMSDB::getInstance();
    $imports = $DB->GetAll('SELECT i.*, f.idate
		FROM cashimport i
		LEFT JOIN sourcefiles f ON (f.id = i.sourcefileid)
		WHERE i.closed = 0 AND i.customerid <> 0');
    if (!empty($imports)) {
        $idate = ConfigHelper::checkValue(ConfigHelper::getConfig('finances.cashimport_use_idate', false));
        $icheck = ConfigHelper::checkValue(ConfigHelper::getConfig('finances.cashimport_checkinvoices', false));
        foreach ($imports as $import) {
            $DB->BeginTrans();
            $balance['time'] = $idate ? $import['idate'] : $import['date'];
            $balance['type'] = 1;
            $balance['value'] = $import['value'];
            $balance['customerid'] = $import['customerid'];
            $balance['comment'] = $import['description'];
            $balance['importid'] = $import['id'];
            $balance['sourceid'] = $import['sourceid'];
            $balance['userid'] = 0;
            if ($import['value'] > 0 && $icheck) {
                if ($invoices = $DB->GetAll('SELECT x.id, x.value FROM (
                                        SELECT d.id,
                                            (SELECT SUM(value*count) FROM invoicecontents WHERE docid = d.id) +
                                            COALESCE((
                                                SELECT SUM((a.value+b.value)*(a.count+b.count)) - SUM(b.value*b.count) 
                                                FROM documents dd
                                                JOIN invoicecontents a ON (a.docid = dd.id)
                                                JOIN invoicecontents b ON (dd.reference = b.docid AND a.itemid = b.itemid)
                                                WHERE dd.reference = d.id
                                                GROUP BY dd.reference), 0) AS value,
                                            d.cdate
                                        FROM documents d
                                        WHERE d.customerid = ? AND d.type = ? AND d.closed = 0
                                        GROUP BY d.id, d.cdate
                                        UNION
                                        SELECT d.id, dn.value, d.cdate
                                        FROM documents d 
                                        JOIN debitnotecontents dn ON dn.docid = d.id 
                                        WHERE d.customerid = ?
                                    ) x ORDER BY x.cdate', array($balance['customerid'], DOC_INVOICE, $balance['customerid']))) {
                    foreach ($invoices as $inv) {
                        $sum += $inv['value'];
                    }
                    $bval = $LMS->GetCustomerBalance($balance['customerid']);
                    $value = f_round($bval + $import['value'] + $sum);
                    foreach ($invoices as $inv) {
                        $inv['value'] = f_round($inv['value']);
                        if ($inv['value'] > $value) {
                            break;
                        } else {
                            // close invoice and assigned credit notes
                            $DB->Execute('UPDATE documents SET closed = 1
								WHERE id = ? OR reference = ?', array($inv['id'], $inv['id']));
                            $value -= $inv['value'];
                        }
                    }
                }
            }
            $DB->Execute('UPDATE cashimport SET closed = 1 WHERE id = ?', array($import['id']));
            $LMS->AddBalance($balance);
            $DB->CommitTrans();
        }
    }
}
Esempio n. 28
0
function iban_account($country, $length, $id, $account = NULL)
{
    if ($account === NULL) {
        $DB = LMSDB::getInstance();
        $account = $DB->GetOne('SELECT account FROM divisions WHERE id IN (SELECT divisionid
			FROM customers WHERE id = ?)', array($id));
    }
    if (!empty($account)) {
        $acclen = strlen($account);
        if ($acclen <= $length - 6) {
            $format = '%0' . ($length - 2 - $acclen) . 'd';
            $account .= sprintf($format, $id);
            $checkaccount = $account . $country . '00';
            $numericaccount = '';
            for ($i = 0; $i < strlen($checkaccount); $i++) {
                $ch = strtoupper($checkaccount[$i]);
                $numericaccount .= ctype_alpha($ch) ? ord($ch) - 55 : $ch;
            }
            $account = sprintf('%02d', 98 - bcmod($numericaccount, 97)) . $account;
        }
    }
    return $account;
}
Esempio n. 29
0
}
define('CONFIG_FILE', $CONFIG_FILE);
$CONFIG = (array) parse_ini_file($CONFIG_FILE, true);
// Check for configuration vars and set default values
$CONFIG['directories']['sys_dir'] = !isset($CONFIG['directories']['sys_dir']) ? getcwd() : $CONFIG['directories']['sys_dir'];
$CONFIG['directories']['lib_dir'] = !isset($CONFIG['directories']['lib_dir']) ? $CONFIG['directories']['sys_dir'] . DIRECTORY_SEPARATOR . 'lib' : $CONFIG['directories']['lib_dir'];
define('SYS_DIR', $CONFIG['directories']['sys_dir']);
define('LIB_DIR', $CONFIG['directories']['lib_dir']);
// Load autoloader
require_once LIB_DIR . DIRECTORY_SEPARATOR . 'autoloader.php';
// Do some checks and load config defaults
require_once LIB_DIR . DIRECTORY_SEPARATOR . 'config.php';
// Init database
$DB = null;
try {
    $DB = LMSDB::getInstance();
} catch (Exception $ex) {
    trigger_error($ex->getMessage(), E_USER_WARNING);
    // can't working without database
    die("Fatal error: cannot connect to database!" . PHP_EOL);
}
$host = ConfigHelper::getConfig($config_section . '.smtp_host');
$port = ConfigHelper::getConfig($config_section . '.smtp_port');
$user = ConfigHelper::getConfig($config_section . '.smtp_user');
$pass = ConfigHelper::getConfig($config_section . '.smtp_pass');
$auth = ConfigHelper::getConfig($config_section . '.smtp_auth');
$debug_email = ConfigHelper::getConfig($config_section . '.debug_email', '');
$mail_from = ConfigHelper::getConfig($config_section . '.mailfrom', '');
$mail_fname = ConfigHelper::getConfig($config_section . '.mailfname', '');
$notify_email = ConfigHelper::getConfig($config_section . '.notify_email', '');
$debug_phone = ConfigHelper::getConfig($config_section . '.debug_phone', '');
Esempio n. 30
0
function getGroupTableRow($name, $def_price = '', $def_units = '', $def_unit_size = '')
{
    $JSResponse = new xajaxResponse();
    if (empty($name)) {
        $group = null;
        $JSResponse->call('addGroup', '');
    } else {
        $group = LMSDB::getInstance()->GetRow('SELECT id as groupid, name
                                               FROM voip_prefix_groups
                                               WHERE name = ?', array($name));
        $id = time();
        $default = array('price' => $def_price, 'units' => $def_units, 'unit_size' => $def_unit_size);
        global $SMARTY;
        $SMARTY->assign('default', $default);
        $SMARTY->assign('row_id', $id);
        $SMARTY->assign('group', $group);
        $row = $SMARTY->fetch('voipaccount/voiptarifftablerow.html');
        $JSResponse->call('addGroup', array($id, $row));
    }
    return $JSResponse;
}