Exemple #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;
    }
}
Exemple #2
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;
}
Exemple #3
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;
}
Exemple #4
0
 public function __construct($load_policy = null)
 {
     $this->DB = LMSDB::getInstance();
     if ($load_policy !== null) {
         $this->setLoadPolicy($load_policy);
     }
 }
Exemple #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;
}
Exemple #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;
}
Exemple #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);
     }
 }
 /**
  * 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)));
 }
Exemple #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;
}
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;
}
Exemple #11
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;
}
Exemple #12
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;
}
Exemple #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;
}
Exemple #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;
}
Exemple #15
0
 public function __construct()
 {
     $this->DB = LMSDB::getInstance();
 }
Exemple #16
0
 /**
  * Returns user rights configuration
  * 
  * Avaliable options are:
  * force - forces to reload whole ini config
  * user_id - user id
  * 
  * @param array $options Associative array of options
  * @return ConfigContainer User rights configuration
  * @throws Exception Throws exception when required parameters are not set
  */
 public static function getUserRightsConfig(array $options = array())
 {
     if (!LMSDB::checkIfInstanceExists()) {
         throw new Exception('Cannot load uiconfig while database connection does not exist!');
     }
     if (!isset($options['user_id'])) {
         throw new Exception('Cannot load user rights config without user id!');
     }
     $force = isset($options['force']) ? $options['force'] : false;
     if ($force || self::$user_rights_config === null) {
         $options['provider'] = UserRightsConfigProvider::NAME;
         $options['parser'] = UserRightsConfigParser::NAME;
         $config_loader = new ConfigLoader();
         self::$user_rights_config = $config_loader->loadConfig($options);
     }
     return self::$user_rights_config;
 }
Exemple #17
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;
}
Exemple #18
0
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 *  USA.
 *
 *  $Id$
 */
// Load autloader
require_once LIB_DIR . '/autoloader.php';
$_MAILDBTYPE = ConfigHelper::getConfig('database.mail_db_type');
$_MAILDBHOST = ConfigHelper::getConfig('database.mail_db_host');
$_MAILDBUSER = ConfigHelper::getConfig('database.mail_db_user');
$_MAILDBPASS = ConfigHelper::getConfig('database.mail_db_password');
$_MAILDBNAME = ConfigHelper::getConfig('database.mail_db_database');
// Initialize mail database
$DB_MAIL = null;
try {
    $DB_MAIL = LMSDB::getDB($_MAILDBTYPE, $_MAILDBHOST, $_MAILDBUSER, $_MAILDBPASS, $_MAILDBNAME);
} catch (Exception $ex) {
    trigger_error($ex->getMessage(), E_USER_WARNING);
    // can't working without database
    die("Fatal error: cannot connect to database!\n");
}
if (defined('USERPANEL_SETUPMODE')) {
    function module_setup()
    {
        global $SMARTY, $LMS;
        $SMARTY->assign('mail_limit', ConfigHelper::getConfig('userpanel.mail_limit'));
        $SMARTY->assign('mail_allowed_domains', ConfigHelper::getConfig('userpanel.mail_allowed_domains'));
        $SMARTY->display('module:accounts:setup.html');
    }
    function module_submit_setup()
    {
Exemple #19
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');
 }
Exemple #20
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;
}
Exemple #21
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;
}
Exemple #22
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');
 }
Exemple #23
0
 /**
  * @covers LMSDB::destroyInstance
  */
 public function testDestroyInstance()
 {
     \LMSDB::getInstance();
     $db = \LMSDB::destroyInstance();
     $this->assertEquals($db, null);
 }
Exemple #24
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'));
 }
Exemple #25
0
 /**
  * Destroys database handler and singleton instance.
  * 
  * Useful for unit tests.
  * @return null Null database handler
  */
 public static function destroyInstance()
 {
     if (self::$db !== null) {
         self::$db->Destroy();
         self::$db = null;
     }
     return self::$db;
 }
Exemple #26
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;
}
Exemple #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();
        }
    }
}
Exemple #28
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;
}
Exemple #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', '');
Exemple #30
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;
}