diff --git a/CHANGLOG.md b/CHANGLOG.md old mode 100644 new mode 100755 diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/TODO.md b/TODO.md old mode 100644 new mode 100755 index ca3be4b..2139fd4 --- a/TODO.md +++ b/TODO.md @@ -16,7 +16,7 @@ ICTCore TODOs * mysql_fetch_object * mysql_fetch_row * mysql_insert_id - * mysql_num_rows + * count * mysql_query * mysql_real_escape_string * mysql_result diff --git a/bin/freeswitch/application.lua b/bin/freeswitch/application.lua old mode 100644 new mode 100755 diff --git a/bin/freeswitch/lib/LIP.lua b/bin/freeswitch/lib/LIP.lua old mode 100644 new mode 100755 diff --git a/bin/freeswitch/spool_failed.lua b/bin/freeswitch/spool_failed.lua old mode 100644 new mode 100755 diff --git a/bin/sendmail/email_to_fax b/bin/sendmail/email_to_fax old mode 100644 new mode 100755 diff --git a/bin/sendmail/gateway.php b/bin/sendmail/gateway.php old mode 100644 new mode 100755 diff --git a/cache/.gitignore b/cache/.gitignore old mode 100644 new mode 100755 diff --git a/cache/placeholder b/cache/placeholder old mode 100644 new mode 100755 diff --git a/composer.json b/composer.json old mode 100644 new mode 100755 diff --git a/composer.lock b/composer.lock old mode 100644 new mode 100755 index e201206..e9d5c40 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "95e563eecf9988201704aa120c545ece", + "content-hash": "d11e2d0314cddbadc66fe78448c8df08", "packages": [ { "name": "aza/clibase", @@ -258,25 +258,93 @@ ], "time": "2013-05-28T13:05:37+00:00" }, + { + "name": "dompdf/dompdf", + "version": "v0.8.6", + "source": { + "type": "git", + "url": "https://github.com/dompdf/dompdf.git", + "reference": "db91d81866c69a42dad1d2926f61515a1e3f42c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/db91d81866c69a42dad1d2926f61515a1e3f42c5", + "reference": "db91d81866c69a42dad1d2926f61515a1e3f42c5", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "phenx/php-font-lib": "^0.5.2", + "phenx/php-svg-lib": "^0.3.3", + "php": "^7.1" + }, + "require-dev": { + "mockery/mockery": "^1.3", + "phpunit/phpunit": "^7.5", + "squizlabs/php_codesniffer": "^3.5" + }, + "suggest": { + "ext-gd": "Needed to process images", + "ext-gmagick": "Improves image processing performance", + "ext-imagick": "Improves image processing performance", + "ext-zlib": "Needed for pdf stream compression" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-develop": "0.7-dev" + } + }, + "autoload": { + "psr-4": { + "Dompdf\\": "src/" + }, + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + }, + { + "name": "Brian Sweeney", + "email": "eclecticgeek@gmail.com" + }, + { + "name": "Gabriel Bull", + "email": "me@gabrielbull.com" + } + ], + "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", + "homepage": "https://github.com/dompdf/dompdf", + "time": "2020-08-30T22:54:22+00:00" + }, { "name": "firebase/php-jwt", - "version": "v5.0.0", + "version": "v5.2.0", "source": { "type": "git", "url": "https://github.com/firebase/php-jwt.git", - "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e" + "reference": "feb0e820b8436873675fd3aca04f3728eb2185cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", - "reference": "9984a4d3a32ae7673d6971ea00bae9d0a1abba0e", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/feb0e820b8436873675fd3aca04f3728eb2185cb", + "reference": "feb0e820b8436873675fd3aca04f3728eb2185cb", "shasum": "" }, "require": { "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": " 4.8.35" + "phpunit/phpunit": ">=4.8 <=9" }, "type": "library", "autoload": { @@ -302,7 +370,11 @@ ], "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", "homepage": "https://github.com/firebase/php-jwt", - "time": "2017-06-27T22:17:23+00:00" + "keywords": [ + "jwt", + "php" + ], + "time": "2020-03-25T18:49:23+00:00" }, { "name": "firehed/processmanager", @@ -345,12 +417,12 @@ "source": { "type": "git", "url": "https://github.com/ictinnovations/RestServer.git", - "reference": "2b99afbd9702795fea78eeb0ce7797df6bd8b8bf" + "reference": "0a09d5b1537b205d40a42312561367889eb761a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ictinnovations/RestServer/zipball/2b99afbd9702795fea78eeb0ce7797df6bd8b8bf", - "reference": "2b99afbd9702795fea78eeb0ce7797df6bd8b8bf", + "url": "https://api.github.com/repos/ictinnovations/RestServer/zipball/0a09d5b1537b205d40a42312561367889eb761a4", + "reference": "0a09d5b1537b205d40a42312561367889eb761a4", "shasum": "" }, "require": { @@ -387,7 +459,7 @@ "support": { "source": "https://github.com/ictinnovations/RestServer/tree/master" }, - "time": "2017-12-23T13:24:13+00:00" + "time": "2020-05-18T12:02:54+00:00" }, { "name": "nategood/httpful", @@ -484,18 +556,95 @@ }, "time": "2018-08-31T10:55:57+00:00" }, + { + "name": "phenx/php-font-lib", + "version": "0.5.2", + "source": { + "type": "git", + "url": "https://github.com/PhenX/php-font-lib.git", + "reference": "ca6ad461f032145fff5971b5985e5af9e7fa88d8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhenX/php-font-lib/zipball/ca6ad461f032145fff5971b5985e5af9e7fa88d8", + "reference": "ca6ad461f032145fff5971b5985e5af9e7fa88d8", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5 || ^6 || ^7" + }, + "type": "library", + "autoload": { + "psr-4": { + "FontLib\\": "src/FontLib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse, export and make subsets of different types of font files.", + "homepage": "https://github.com/PhenX/php-font-lib", + "time": "2020-03-08T15:31:32+00:00" + }, + { + "name": "phenx/php-svg-lib", + "version": "v0.3.3", + "source": { + "type": "git", + "url": "https://github.com/PhenX/php-svg-lib.git", + "reference": "5fa61b65e612ce1ae15f69b3d223cb14ecc60e32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PhenX/php-svg-lib/zipball/5fa61b65e612ce1ae15f69b3d223cb14ecc60e32", + "reference": "5fa61b65e612ce1ae15f69b3d223cb14ecc60e32", + "shasum": "" + }, + "require": { + "sabberworm/php-css-parser": "^8.3" + }, + "require-dev": { + "phpunit/phpunit": "^5.5|^6.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Svg\\": "src/Svg" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse and export to PDF SVG files.", + "homepage": "https://github.com/PhenX/php-svg-lib", + "time": "2019-09-11T20:02:13+00:00" + }, { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc", + "reference": "0f73288fd15629204f9d42b7055f72dacbe811fc", "shasum": "" }, "require": { @@ -504,7 +653,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -529,20 +678,65 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2020-03-23T09:12:05+00:00" + }, + { + "name": "sabberworm/php-css-parser", + "version": "8.3.1", + "source": { + "type": "git", + "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", + "reference": "d217848e1396ef962fb1997cf3e2421acba7f796" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/d217848e1396ef962fb1997cf3e2421acba7f796", + "reference": "d217848e1396ef962fb1997cf3e2421acba7f796", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "codacy/coverage": "^1.4", + "phpunit/phpunit": "~4.8" + }, + "type": "library", + "autoload": { + "psr-0": { + "Sabberworm\\CSS": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Raphael Schweikert" + } + ], + "description": "Parser for CSS Files written in PHP", + "homepage": "http://www.sabberworm.com/blog/2010/6/10/php-css-parser", + "keywords": [ + "css", + "parser", + "stylesheet" + ], + "time": "2020-06-01T09:10:00+00:00" }, { "name": "swiftmailer/swiftmailer", - "version": "v5.4.8", + "version": "v5.4.12", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "9a06dc570a0367850280eefd3f1dc2da45aef517" + "reference": "181b89f18a90f8925ef805f950d47a7190e9b950" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/9a06dc570a0367850280eefd3f1dc2da45aef517", - "reference": "9a06dc570a0367850280eefd3f1dc2da45aef517", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/181b89f18a90f8925ef805f950d47a7190e9b950", + "reference": "181b89f18a90f8925ef805f950d47a7190e9b950", "shasum": "" }, "require": { @@ -577,40 +771,102 @@ } ], "description": "Swiftmailer, free feature-rich PHP mailer", - "homepage": "http://swiftmailer.org", + "homepage": "https://swiftmailer.symfony.com", "keywords": [ "email", "mail", "mailer" ], - "time": "2017-05-01T15:54:03+00:00" + "time": "2018-07-31T09:26:32+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.22.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/c6c942b1ac76c82448322025e084cadc56048b4e", + "reference": "c6c942b1ac76c82448322025e084cadc56048b4e", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.22-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2021-01-07T16:49:33+00:00" }, { "name": "twig/twig", - "version": "v1.35.0", + "version": "v1.44.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "daa657073e55b0a78cce8fdd22682fddecc6385f" + "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/daa657073e55b0a78cce8fdd22682fddecc6385f", - "reference": "daa657073e55b0a78cce8fdd22682fddecc6385f", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/138c493c5b8ee7cff3821f80b8896d371366b5fe", + "reference": "138c493c5b8ee7cff3821f80b8896d371366b5fe", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=7.2.5", + "symfony/polyfill-ctype": "^1.8" }, "require-dev": { "psr/container": "^1.0", - "symfony/debug": "~2.7", - "symfony/phpunit-bridge": "~3.3@dev" + "symfony/phpunit-bridge": "^4.4.9|^5.0.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.35-dev" + "dev-master": "1.44-dev" } }, "autoload": { @@ -632,23 +888,22 @@ "homepage": "http://fabien.potencier.org", "role": "Lead Developer" }, + { + "name": "Twig Team", + "role": "Contributors" + }, { "name": "Armin Ronacher", "email": "armin.ronacher@active-4.com", "role": "Project Founder" - }, - { - "name": "Twig Team", - "homepage": "http://twig.sensiolabs.org/contributors", - "role": "Contributors" } ], "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", + "homepage": "https://twig.symfony.com", "keywords": [ "templating" ], - "time": "2017-09-27T18:06:46+00:00" + "time": "2021-01-05T10:10:05+00:00" } ], "packages-dev": [], diff --git a/core.zip b/core.zip new file mode 100644 index 0000000..d5bfb8c Binary files /dev/null and b/core.zip differ diff --git a/core/Account.php b/core/Account.php old mode 100644 new mode 100755 index 0de6178..bc41fb3 --- a/core/Account.php +++ b/core/Account.php @@ -128,7 +128,7 @@ public function __construct($account_id = NULL) $query = "SELECT account_id FROM " . self::$table . " WHERE active=1 AND created_by=%user_id% ORDER BY account_id DESC LIMIT 1"; $result = DB::query(self::$table, $query, array('user_id' => $oSession->user->user_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; $this->account_id = $data['account_id']; } $this->_load(); @@ -184,7 +184,7 @@ public static function search($aFilter = array()) $query = "SELECT account_id, type, username, first_name, last_name, phone, email, created_by FROM " . $from_str; Corelog::log("account search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('account', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aAccount[] = $data; } @@ -211,8 +211,8 @@ public static function getClass(&$account_id, $namespace = 'ICT\\Core\\Account') if (ctype_digit(trim($account_id))) { $query = "SELECT type FROM " . self::$table . " WHERE account_id='%account_id%' "; $result = DB::query(self::$table, $query, array('account_id' => $account_id)); - if (is_resource($result)) { - $account_type = mysql_result($result, 0); + if ($result) { + $account_type = $result[0]; } } else { $account_type = $account_id; @@ -249,7 +249,7 @@ protected function _load() Corelog::log("Loading account: $this->account_id", Corelog::CRUD); $query = "SELECT * FROM " . self::$table . " WHERE account_id='%account_id%' "; $result = DB::query(self::$table, $query, array('account_id' => $this->account_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->account_id = $data['account_id']; $this->type = $data['type']; diff --git a/core/Account/Did.php b/core/Account/Did.php old mode 100644 new mode 100755 diff --git a/core/Account/Extension.php b/core/Account/Extension.php old mode 100644 new mode 100755 diff --git a/core/Account/eaddress.php b/core/Account/eaddress.php old mode 100644 new mode 100755 diff --git a/core/Action.php b/core/Action.php old mode 100644 new mode 100755 index 969cca8..c1674c7 --- a/core/Action.php +++ b/core/Action.php @@ -83,7 +83,7 @@ public static function search($application_id) $aAction = array(); $query = "SELECT action_id FROM " . self::$table . " WHERE application_id='%application_id%' "; $result = DB::query(self::$table, $query, array('application_id' => $application_id)); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aAction[] = $data; } Corelog::log("Search actions for application: $application_id", Corelog::DEBUG, $aAction); @@ -95,7 +95,7 @@ protected function _load() Corelog::log("Loading action: $this->action_id", Corelog::DEBUG); $query = "SELECT * FROM " . self::$table . " WHERE action_id='%action_id%' "; $result = DB::query(self::$table, $query, array('action_id' => $this->action_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; $this->action_id = $data['action_id']; $this->type = $data['type']; $this->action = $data['action']; diff --git a/core/Api.php b/core/Api.php index 99e1951..44fffe4 100755 --- a/core/Api.php +++ b/core/Api.php @@ -59,6 +59,7 @@ protected function set($oEntity, $data) public function create_interface($interface_type = null, $root_path = null) { + global $path_cache; if (!empty($interface_type) && $interface_type = 'rest') { // Initialize the server diff --git a/core/Api/Authenticate.php b/core/Api/Authenticate.php old mode 100644 new mode 100755 index 2702679..7a20241 --- a/core/Api/Authenticate.php +++ b/core/Api/Authenticate.php @@ -24,6 +24,7 @@ class AuthenticateApi extends Api */ public function create($data = array()) { + $key_type = null; $credentials = null; diff --git a/core/Api/CampaignApi.php b/core/Api/CampaignApi.php old mode 100644 new mode 100755 diff --git a/core/Api/CoreApi.php b/core/Api/CoreApi.php old mode 100644 new mode 100755 diff --git a/core/Api/GroupApi.php b/core/Api/GroupApi.php old mode 100644 new mode 100755 diff --git a/core/Application.php b/core/Application.php old mode 100644 new mode 100755 index 9d8d660..e030569 --- a/core/Application.php +++ b/core/Application.php @@ -168,7 +168,7 @@ public static function search($program_id, $weight = NULL) } $query = "SELECT application_id FROM " . self::$table . " WHERE $where"; $result = DB::query(self::$table, $query, array('program_id' => $program_id, 'weight' => $weight)); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aApplication[] = $data; } Corelog::log("Application search for program: $program_id", Corelog::CRUD, $aApplication); @@ -191,8 +191,8 @@ public static function getClass(&$application_id, $namespace = 'ICT\\Core\\Appli if (ctype_digit(trim($application_id))) { $query = "SELECT type FROM " . self::$table . " WHERE application_id='%application_id%' "; $result = DB::query(self::$table, $query, array('application_id' => $application_id)); - if (is_resource($result)) { - $application_type = mysql_result($result, 0); + if ($result) { + $application_type = $result[0]; } } else { $application_type = $application_id; @@ -225,7 +225,7 @@ protected function _load() { $query = "SELECT * FROM " . self::$table . " WHERE application_id='%application_id%' "; $result = DB::query(self::$table, $query, array('application_id' => $this->application_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->application_id = $data['application_id']; $this->name = $data['name']; diff --git a/core/Application/Amd.php b/core/Application/Amd.php old mode 100644 new mode 100755 diff --git a/core/Application/Callerid_set.php b/core/Application/Callerid_set.php old mode 100644 new mode 100755 diff --git a/core/Application/Connect.php b/core/Application/Connect.php old mode 100644 new mode 100755 diff --git a/core/Application/Disconnect.php b/core/Application/Disconnect.php old mode 100644 new mode 100755 diff --git a/core/Application/Dnc.php b/core/Application/Dnc.php old mode 100644 new mode 100755 diff --git a/core/Application/Email_receive.php b/core/Application/Email_receive.php old mode 100644 new mode 100755 diff --git a/core/Application/Email_send.php b/core/Application/Email_send.php old mode 100644 new mode 100755 diff --git a/core/Application/Fax_receive.php b/core/Application/Fax_receive.php old mode 100644 new mode 100755 diff --git a/core/Application/Fax_send.php b/core/Application/Fax_send.php old mode 100644 new mode 100755 diff --git a/core/Application/Inbound.php b/core/Application/Inbound.php old mode 100644 new mode 100755 diff --git a/core/Application/Input.php b/core/Application/Input.php old mode 100644 new mode 100755 diff --git a/core/Application/Log.php b/core/Application/Log.php old mode 100644 new mode 100755 diff --git a/core/Application/Originate.php b/core/Application/Originate.php old mode 100644 new mode 100755 diff --git a/core/Application/Play_menu.php b/core/Application/Play_menu.php old mode 100644 new mode 100755 diff --git a/core/Application/Record.php b/core/Application/Record.php old mode 100644 new mode 100755 diff --git a/core/Application/Say_alpha.php b/core/Application/Say_alpha.php old mode 100644 new mode 100755 diff --git a/core/Application/Say_digit.php b/core/Application/Say_digit.php old mode 100644 new mode 100755 diff --git a/core/Application/Say_number.php b/core/Application/Say_number.php old mode 100644 new mode 100755 diff --git a/core/Application/Say_time.php b/core/Application/Say_time.php old mode 100644 new mode 100755 diff --git a/core/Application/Sms_receive.php b/core/Application/Sms_receive.php old mode 100644 new mode 100755 diff --git a/core/Application/Sms_send.php b/core/Application/Sms_send.php old mode 100644 new mode 100755 diff --git a/core/Application/Transfer.php b/core/Application/Transfer.php old mode 100644 new mode 100755 diff --git a/core/Application/Voice_play.php b/core/Application/Voice_play.php old mode 100644 new mode 100755 diff --git a/core/Application/Wait.php b/core/Application/Wait.php old mode 100644 new mode 100755 diff --git a/core/Campaign.php b/core/Campaign.php old mode 100644 new mode 100755 index da3beeb..0bfd36c --- a/core/Campaign.php +++ b/core/Campaign.php @@ -116,7 +116,7 @@ public static function search($aFilter = array()) $query = "SELECT c.*, p.type AS program_type FROM " . $from_str; Corelog::log("Campaign search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('Campaign', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aCampaign[] = $data; } @@ -127,7 +127,7 @@ private function load() { $query = "SELECT * FROM " . self::$table . " WHERE campaign_id='%campaign_id%' "; $result = DB::query(self::$table, $query, array('campaign_id' => $this->campaign_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->campaign_id = $data['campaign_id']; $this->program_id = $data['program_id']; diff --git a/core/Contact.php b/core/Contact.php old mode 100644 new mode 100755 index 9e2e1a3..13b3277 --- a/core/Contact.php +++ b/core/Contact.php @@ -148,7 +148,7 @@ public static function search($aFilter = array(), $full = false) } Corelog::log("contact search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('contact', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aContact[] = $data; } @@ -177,7 +177,7 @@ private function load() { $query = "SELECT * FROM " . self::$table . " WHERE contact_id='%contact_id%' "; $result = DB::query(self::$table, $query, array('contact_id' => $this->contact_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->contact_id = $data['contact_id']; $this->first_name = $data['first_name']; @@ -199,7 +199,7 @@ private function load() public function delete() { Corelog::log("Contact delete", Corelog::CRUD); - mysql_query("DELETE from contact_link where contact_id=".$this->contact_id); + DB::raw_insert_delete_update("DELETE from contact_link where contact_id=".$this->contact_id); DB::delete(self::$table_link, 'contact_id', $this->contact_id); return DB::delete(self::$table, 'contact_id', $this->contact_id); } @@ -303,12 +303,12 @@ public function link_delete($group_id = null) } else { $link_delete_query = "DELETE FROM ".self::$table_link." WHERE contact_id=%contact_id% AND group_id=%group_id%"; } - DB::query(self::$table, $req_query, array('contact_id' => $this->contact_id, 'group_id' => $group_id)); - $get_link_count = mysql_query("SELECT * from contact_link"); - $result_add = mysql_query("DELETE from contact_link where contact_id=".$this->contact_id." AND group_id=".$group_id); - $result = mysql_num_rows($get_link_count)-1; + DB::insert_delete_update(self::$table, $link_delete_query, array('contact_id' => $this->contact_id, 'group_id' => $group_id)); + $get_link_count = DB::rawSelect("SELECT * from contact_link"); + $result_add = DB::raw_insert_delete_update("DELETE from contact_link where contact_id=".$this->contact_id." AND group_id=".$group_id); + $result = count($get_link_count)-1; //$count_contact = mysql_query("SELECT * from contact_link where group_id=".$group_id." GROUP BY contact_id"); - //$cont_result = mysql_num_rows($count_contact); + //$cont_result = count($count_contact); //$udate_group = mysql_query("UPDATE contact_group set contact_count=".$cont_result." where group_id=".$group_id); Corelog::log("group contacts Deleted: ", Corelog::CRUD); return $result ; diff --git a/core/Core.php b/core/Core.php old mode 100644 new mode 100755 index 6d6f969..c99dc78 --- a/core/Core.php +++ b/core/Core.php @@ -18,6 +18,7 @@ class Core { + public static function statistic($aFilter = array()) { $aWhere = array(); diff --git a/core/Exchange/Dialplan.php b/core/Exchange/Dialplan.php old mode 100644 new mode 100755 index 15a0cb2..2f8555f --- a/core/Exchange/Dialplan.php +++ b/core/Exchange/Dialplan.php @@ -156,7 +156,7 @@ public static function search($aFilter = array()) weight ASC, gateway_flag ASC"; Corelog::log("dialplan search with $query", Corelog::DEBUG); $result = DB::query(self::$table, $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $listDialplan[] = $data; } @@ -168,7 +168,7 @@ private function load() { $query = "SELECT * FROM " . self::$table . " WHERE dialplan_id='%dialplan_id%' "; $result = DB::query(self::$table, $query, array('dialplan_id' => $this->dialplan_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->dialplan_id = $data['dialplan_id']; $this->gateway_flag = $data['gateway_flag']; diff --git a/core/Gateway.php b/core/Gateway.php old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/account/extension.twig b/core/Gateway/Freeswitch/templates/account/extension.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/amd.json b/core/Gateway/Freeswitch/templates/application/amd.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/callerid_set.json b/core/Gateway/Freeswitch/templates/application/callerid_set.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/connect.json b/core/Gateway/Freeswitch/templates/application/connect.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/disconnect.json b/core/Gateway/Freeswitch/templates/application/disconnect.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/dnc.json b/core/Gateway/Freeswitch/templates/application/dnc.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/fax_receive.json b/core/Gateway/Freeswitch/templates/application/fax_receive.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/fax_send.json b/core/Gateway/Freeswitch/templates/application/fax_send.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/input.json b/core/Gateway/Freeswitch/templates/application/input.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/log.json b/core/Gateway/Freeswitch/templates/application/log.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/originate/fax.json b/core/Gateway/Freeswitch/templates/application/originate/fax.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/originate/voice.json b/core/Gateway/Freeswitch/templates/application/originate/voice.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/play_menu.json b/core/Gateway/Freeswitch/templates/application/play_menu.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/record.json b/core/Gateway/Freeswitch/templates/application/record.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/say_alpha.json b/core/Gateway/Freeswitch/templates/application/say_alpha.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/say_date.json b/core/Gateway/Freeswitch/templates/application/say_date.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/say_digit.json b/core/Gateway/Freeswitch/templates/application/say_digit.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/say_number.json b/core/Gateway/Freeswitch/templates/application/say_number.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/say_time.json b/core/Gateway/Freeswitch/templates/application/say_time.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/transfer.json b/core/Gateway/Freeswitch/templates/application/transfer.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/tts.json b/core/Gateway/Freeswitch/templates/application/tts.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/voice_play.json b/core/Gateway/Freeswitch/templates/application/voice_play.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/application/wait.json b/core/Gateway/Freeswitch/templates/application/wait.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/provider.twig b/core/Gateway/Freeswitch/templates/provider.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/provider/sip.twig b/core/Gateway/Freeswitch/templates/provider/sip.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Freeswitch/templates/user.twig b/core/Gateway/Freeswitch/templates/user.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel.php b/core/Gateway/Kannel.php old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/application/log.json b/core/Gateway/Kannel/templates/application/log.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/application/sms_receive.json b/core/Gateway/Kannel/templates/application/sms_receive.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/application/sms_send.json b/core/Gateway/Kannel/templates/application/sms_send.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/provider/http.twig b/core/Gateway/Kannel/templates/provider/http.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/provider/http/default.twig b/core/Gateway/Kannel/templates/provider/http/default.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/provider/http/ufone.twig b/core/Gateway/Kannel/templates/provider/http/ufone.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Kannel/templates/provider/smpp.twig b/core/Gateway/Kannel/templates/provider/smpp.twig old mode 100644 new mode 100755 diff --git a/core/Gateway/Sendmail.php b/core/Gateway/Sendmail.php old mode 100644 new mode 100755 diff --git a/core/Gateway/Sendmail/templates/application/email_receive.json b/core/Gateway/Sendmail/templates/application/email_receive.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Sendmail/templates/application/email_send.json b/core/Gateway/Sendmail/templates/application/email_send.json old mode 100644 new mode 100755 diff --git a/core/Gateway/Sendmail/templates/application/log.json b/core/Gateway/Sendmail/templates/application/log.json old mode 100644 new mode 100755 diff --git a/core/Group.php b/core/Group.php old mode 100644 new mode 100755 index 10300df..1f48234 --- a/core/Group.php +++ b/core/Group.php @@ -86,7 +86,7 @@ public static function search($aFilter = array()) $query = "SELECT group_id, name, contact_total FROM " . $from_str; Corelog::log("group search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('group', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aGroup[] = $data; } @@ -104,7 +104,7 @@ private function load() { $query = "SELECT * FROM " . self::$table . " WHERE group_id='%group_id%' "; $result = DB::query(self::$table, $query, array('group_id' => $this->group_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->group_id = $data['group_id']; $this->name = $data['name']; diff --git a/core/Message.php b/core/Message.php old mode 100644 new mode 100755 diff --git a/core/Message/Document.php b/core/Message/Document.php old mode 100644 new mode 100755 index 1c4b11c..8fa82bf --- a/core/Message/Document.php +++ b/core/Message/Document.php @@ -199,7 +199,7 @@ public static function search($aFilter = array()) $query = "SELECT document_id, name, file_name, type, pages, description FROM " . $from_str; Corelog::log("document search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('document', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aDocument[] = $data; } @@ -210,7 +210,7 @@ protected function load() { $query = "SELECT * FROM " . self::$table . " WHERE document_id='%document_id%' "; $result = DB::query(self::$table, $query, array('document_id' => $this->document_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->document_id = $data['document_id']; $this->name = $data['name']; diff --git a/core/Message/Recording.php b/core/Message/Recording.php old mode 100644 new mode 100755 index b6cb0bb..0d21c69 --- a/core/Message/Recording.php +++ b/core/Message/Recording.php @@ -161,7 +161,7 @@ public static function search($aFilter = array()) $query = "SELECT recording_id, name, file_name, type, length, description FROM " . $from_str; Corelog::log("recording search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('recording', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aRecording[] = $data; } @@ -172,7 +172,7 @@ protected function load() { $query = "SELECT * FROM " . self::$table . " WHERE recording_id='%recording_id%' "; $result = DB::query(self::$table, $query, array('recording_id' => $this->recording_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->recording_id = $data['recording_id']; $this->name = $data['name']; @@ -318,9 +318,9 @@ private function create_wav($sourceFile, $type, $targetFile) private function recording_type_allowed() { $type = array(); - $query = DB::query('codec', 'SELECT * FROM codec WHERE active=1'); - while ($codec = mysql_fetch_object($query)) { - $type[$codec->codec_value] = $codec->codec_value; + $result = DB::query('codec', 'SELECT * FROM codec WHERE active=1'); + forEach ($result as $data) { + $type[$data->codec_value] = $data->codec_value; } return $type; } diff --git a/core/Message/Template.php b/core/Message/Template.php old mode 100644 new mode 100755 index adb9dae..0ac148b --- a/core/Message/Template.php +++ b/core/Message/Template.php @@ -145,7 +145,7 @@ public static function search($aFilter = array()) $query = "SELECT template_id, name, subject, type, length, description FROM " . $from_str; Corelog::log("template search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('template', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aTemplate[] = $data; } @@ -156,7 +156,7 @@ protected function load() { $query = "SELECT * FROM " . self::$table . " WHERE template_id='%template_id%' "; $result = DB::query(self::$table, $query, array('template_id' => $this->template_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->template_id = $data['template_id']; $this->name = $data['name']; diff --git a/core/Message/Text.php b/core/Message/Text.php old mode 100644 new mode 100755 index a772d80..bdca63e --- a/core/Message/Text.php +++ b/core/Message/Text.php @@ -136,7 +136,7 @@ public static function search($aFilter = array()) $query = "SELECT text_id, name, type, length, description FROM " . $from_str; Corelog::log("text search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('text', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aText[] = $data; } @@ -147,7 +147,7 @@ protected function load() { $query = "SELECT * FROM " . self::$table . " WHERE text_id='%text_id%' "; $result = DB::query(self::$table, $query, array('text_id' => $this->text_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->text_id = $data['text_id']; $this->name = $data['name']; diff --git a/core/Program.php b/core/Program.php index 395d586..a58f477 100755 --- a/core/Program.php +++ b/core/Program.php @@ -197,7 +197,7 @@ public static function search($aFilter = array()) $query = "SELECT program_id, name, type, parent_id FROM " . $from_str; Corelog::log("program search with $query", Corelog::DEBUG, array('aFilter' => $aFilter)); $result = DB::query('program', $query); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aProgram[] = $data; } @@ -210,7 +210,7 @@ public static function search_child($program_id) $where = "parent_id='%program_id%'"; $query = "SELECT program_id FROM " . self::$table . " WHERE $where"; $result = DB::query(self::$table, $query, array('program_id' => $program_id)); - while ($data = mysql_fetch_assoc($result)) { + forEach ($result as $data ) { $aProgram[] = $data; } Corelog::log("Child program search for program: $program_id", Corelog::CRUD, $aProgram); @@ -292,8 +292,8 @@ public static function getClass(&$program_id, $namespace = 'ICT\\Core\\Program') if (ctype_digit(trim($program_id))) { $query = "SELECT type FROM " . self::$table . " WHERE program_id='%program_id%' "; $result = DB::query(self::$table, $query, array('program_id' => $program_id)); - if (is_resource($result)) { - $program_type = mysql_result($result, 0); + if ($result) { + $program_type = $result[0]; } } else { $program_type = $program_id; @@ -326,7 +326,7 @@ protected function _load() { $query = "SELECT * FROM " . self::$table . " WHERE program_id='%program_id%' "; $result = DB::query(self::$table, $query, array('program_id' => $this->program_id)); - $data = mysql_fetch_assoc($result); + $data = $result[0]; if ($data) { $this->program_id = $data['program_id']; $this->name = $data['name']; @@ -414,7 +414,7 @@ public static function resource_search($resource_type, $resource_id) } $query = "SELECT program_id FROM " . self::$table . "_resource WHERE resource_type IN ('$resource_type') AND resource_id=%resource_id%"; $result = DB::query(self::$table . "_resource", $query, array('resource_id' => $resource_id)); - while ($resource = mysql_fetch_assoc($result)) { + forEach ($result as $resource ) { $aProgram[] = $resource; } diff --git a/core/Program/Agent.php b/core/Program/Agent.php old mode 100644 new mode 100755 diff --git a/core/Program/Emailtofax.php b/core/Program/Emailtofax.php old mode 100644 new mode 100755 diff --git a/core/Program/Emailtofax/data/email_accepted.tpl.php b/core/Program/Emailtofax/data/email_accepted.tpl.php old mode 100644 new mode 100755 diff --git a/core/Program/Emailtofax/data/email_error.tpl.php b/core/Program/Emailtofax/data/email_error.tpl.php old mode 100644 new mode 100755 diff --git a/core/Program/Emailtofax/data/fax_error.tpl.php b/core/Program/Emailtofax/data/fax_error.tpl.php old mode 100644 new mode 100755 diff --git a/core/Program/Emailtofax/data/fax_success.tpl.php b/core/Program/Emailtofax/data/fax_success.tpl.php old mode 100644 new mode 100755 diff --git a/core/Program/Faxtoemail.php b/core/Program/Faxtoemail.php old mode 100644 new mode 100755 diff --git a/core/Program/Faxtoemail/data/fax_received.tpl.php b/core/Program/Faxtoemail/data/fax_received.tpl.php old mode 100644 new mode 100755 diff --git a/core/Program/Forward.php b/core/Program/Forward.php old mode 100644 new mode 100755 diff --git a/core/Program/Ivr.php b/core/Program/Ivr.php old mode 100644 new mode 100755 index 925a613..f31fc66 --- a/core/Program/Ivr.php +++ b/core/Program/Ivr.php @@ -221,7 +221,6 @@ private function _scheme_find_action($aActions, $app_index) private function _scheme_add_action($oScheme, $app_index, $aApps, $aActions) { $app_actions = $this->_scheme_find_action($aActions, $app_index); - //echo "
";print_r($app_actions);
foreach($app_actions as $key => $action) {
if ($action->pointer->linked_app_index) {
$aApps[$app_index]->processed = true;
diff --git a/core/Program/Receiveemail.php b/core/Program/Receiveemail.php
old mode 100644
new mode 100755
diff --git a/core/Program/Receivefax.php b/core/Program/Receivefax.php
old mode 100644
new mode 100755
diff --git a/core/Program/Receivesms.php b/core/Program/Receivesms.php
old mode 100644
new mode 100755
diff --git a/core/Program/Sendemail.php b/core/Program/Sendemail.php
old mode 100644
new mode 100755
diff --git a/core/Program/Sendfax.php b/core/Program/Sendfax.php
old mode 100644
new mode 100755
diff --git a/core/Program/Sendsms.php b/core/Program/Sendsms.php
old mode 100644
new mode 100755
diff --git a/core/Program/Voicemessage.php b/core/Program/Voicemessage.php
old mode 100644
new mode 100755
diff --git a/core/Program/Voicetts.php b/core/Program/Voicetts.php
old mode 100644
new mode 100755
diff --git a/core/Provider.php b/core/Provider.php
old mode 100644
new mode 100755
index 28d1a00..fbcbb5e
--- a/core/Provider.php
+++ b/core/Provider.php
@@ -125,7 +125,7 @@ public static function search($aFilter = array())
$query = "SELECT provider_id, name, host, service_flag, node_id, type FROM " . $from_str;
Corelog::log("provider search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query(self::$table, $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data ) {
$aProvider[] = $data;
}
@@ -137,8 +137,8 @@ public static function getClass(&$provider_id, $namespace = 'ICT\\Core\\Provider
if (ctype_digit(trim($provider_id))) {
$query = "SELECT type FROM " . self::$table . " WHERE provider_id='%provider_id%' ";
$result = DB::query(self::$table, $query, array('provider_id' => $provider_id));
- if (is_resource($result)) {
- $provider_type = mysql_result($result, 0);
+ if ($result) {
+ $provider_type = $result[0];
}
} else {
$provider_type = $provider_id;
@@ -172,7 +172,7 @@ private function _load()
Corelog::log("Loading provider: $this->provider_id", Corelog::CRUD);
$query = "SELECT * FROM " . self::$table . " WHERE provider_id='%provider_id%' ";
$result = DB::query(self::$table, $query, array('provider_id' => $this->provider_id));
- $data = mysql_fetch_assoc($result);
+ $data = $result[0];
if ($data) {
$this->provider_id = $data['provider_id'];
$this->name = $data['name'];
diff --git a/core/Provider/Emailcmd.php b/core/Provider/Emailcmd.php
old mode 100644
new mode 100755
diff --git a/core/Provider/Http.php b/core/Provider/Http.php
old mode 100644
new mode 100755
diff --git a/core/Provider/Sip.php b/core/Provider/Sip.php
old mode 100644
new mode 100755
diff --git a/core/Provider/Smpp.php b/core/Provider/Smpp.php
old mode 100644
new mode 100755
diff --git a/core/Provider/Smtp.php b/core/Provider/Smtp.php
old mode 100644
new mode 100755
diff --git a/core/Request.php b/core/Request.php
old mode 100644
new mode 100755
diff --git a/core/Response.php b/core/Response.php
old mode 100644
new mode 100755
diff --git a/core/Result.php b/core/Result.php
old mode 100644
new mode 100755
index 3bd7341..6c6f988
--- a/core/Result.php
+++ b/core/Result.php
@@ -93,7 +93,7 @@ public static function search($aFilter = array())
$query = "SELECT * FROM " . $from_str;
$result = DB::query(self::$table, $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data ) {
$aResult[] = $data;
}
Corelog::log("Result search for spool", Corelog::CRUD, $aResult);
@@ -104,7 +104,7 @@ private function load()
{
$query = "SELECT * FROM " . self::$table . " WHERE spool_result_id='%spool_result_id%'";
$result = DB::query(self::$table, $query, array('spool_result_id' => $this->spool_result_id));
- $data = mysql_fetch_assoc($result);
+ $data = $result[0];
if ($data) {
$this->spool_result_id = $data['spool_result_id'];
$this->application_id = $data['application_id'];
diff --git a/core/Schedule.php b/core/Schedule.php
old mode 100644
new mode 100755
index a28f0fd..64f71a5
--- a/core/Schedule.php
+++ b/core/Schedule.php
@@ -78,7 +78,7 @@ public function load()
$query = "SELECT * FROM " . self::$sub_table . " WHERE task_id='%task_id%'";
$schedule = DB::query(self::$sub_table, $query, array('task_id' => $this->task_id));
- while ($data = mysql_fetch_assoc($schedule)) {
+ foreach ($schedule as $data) {
$year[] = $data['year'];
$month[] = $data['month'];
$day[] = $data['day'];
diff --git a/core/Service.php b/core/Service.php
old mode 100644
new mode 100755
diff --git a/core/Service/Email.php b/core/Service/Email.php
old mode 100644
new mode 100755
diff --git a/core/Service/Fax.php b/core/Service/Fax.php
old mode 100644
new mode 100755
diff --git a/core/Service/Sms.php b/core/Service/Sms.php
old mode 100644
new mode 100755
diff --git a/core/Service/Voice.php b/core/Service/Voice.php
old mode 100644
new mode 100755
diff --git a/core/Spool.php b/core/Spool.php
old mode 100644
new mode 100755
index 5e69c44..7412319
--- a/core/Spool.php
+++ b/core/Spool.php
@@ -154,7 +154,7 @@ public static function search($aFilter = array())
$query = "SELECT spool_id, account_id, transmission_id, status, response FROM " . $from_str;
Corelog::log("spool search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query('spool', $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data ) {
$aSpool[] = $data;
}
@@ -165,7 +165,7 @@ private function load()
{
$query = "SELECT * FROM " . self::$table . " WHERE spool_id='%spool_id%' ";
$result = DB::query(self::$table, $query, array('spool_id' => $this->spool_id));
- $data = mysql_fetch_assoc($result);
+ $data = $result[0];
if ($data) {
$this->spool_id = $data['spool_id'];
$this->time_spool = $data['time_spool'];
diff --git a/core/Task.php b/core/Task.php
old mode 100644
new mode 100755
index 87f82be..a197f49
--- a/core/Task.php
+++ b/core/Task.php
@@ -125,7 +125,7 @@ public static function search($aFilter = array())
$query = "SELECT task_id, account_id, type, action, data FROM " . $from_str;
Corelog::log("task search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query('task', $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data ) {
$aTask[] = $data;
}
@@ -141,7 +141,7 @@ public static function search_pending()
WHERE status = " . Task::PENDING . "
AND (t.last_run IS NULL OR (t.last_run + 59) < UNIX_TIMESTAMP())"; // don't run a task twice
$rsTask = DB::query(self::$table, $query, array());
- while ($data = mysql_fetch_assoc($rsTask)) {
+ forEach ($rsTask as $data) {
$aTask[] = $data;
}
Corelog::log("Task search", Corelog::CRUD, $aTask);
@@ -152,7 +152,7 @@ protected function load()
{
$query = "SELECT * FROM " . self::$table . " WHERE task_id='%task_id%'";
$task = DB::query(self::$table, $query, array('task_id' => $this->task_id));
- $data = mysql_fetch_assoc($task);
+ $data = $task;
if ($data) {
$this->task_id = $data['task_id'];
$this->type = $data['type'];
diff --git a/core/Test.php b/core/Test.php
new file mode 100644
index 0000000..ac55d0e
--- /dev/null
+++ b/core/Test.php
@@ -0,0 +1,55 @@
+";
+print_r( \ICT\Core\DB::column_list('configuration'));
+echo "";*/
+
+/*echo "statistics:".PHP_EOL;
+$aStatic = \ICT\Core\Core::statistic();
+print_r($aStatic);*/
+
+/*
+echo "user:".PHP_EOL;
+$user = \ICT\Core\User::search(array('user_id'=>1));
+print_r($user);*/
+
+class Test
+{
+ public function __construct()
+ {
+ echo "const";
+ }
+
+ public static function login()
+ {
+ \ICT\Core\do_login(1);
+ }
+
+ // \ICT\Core\Test::user(); from cli
+ public static function user()
+ {
+ echo "user:" . PHP_EOL;
+ $user = \ICT\Core\User::search(array('user_id' => 1));
+ print_r($user);
+ }
+
+ public static function statistics()
+ {
+ echo "statistics:" . PHP_EOL;
+ $aStatic = \ICT\Core\Core::statistic();
+ print_r($aStatic);
+ }
+
+ public static function auth()
+ {
+ //$aStatic = \ICT\Core\Api\AuthenticateApi::create(['username'=>'sxkjk','password'=>'sxkdskk']);
+ echo \ICT\Core\Api::authenticate(['username'=>'banna','password'=>'alio1610'],User::AUTH_TYPE_DIGEST);
+ // print_r($aStatic);
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/core/Transmission.php b/core/Transmission.php
old mode 100644
new mode 100755
index 16f144f..991aacb
--- a/core/Transmission.php
+++ b/core/Transmission.php
@@ -260,7 +260,7 @@ public static function search($aFilter = array())
$query = "SELECT t.transmission_id, $owner_fields, $contact_fields, t.status, t.response, t.direction, t.last_run FROM " . $from_str . " LIMIT 5000";
Corelog::log("transmission search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query('transmission', $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data ) {
$aTransmission[] = $data;
}
@@ -271,7 +271,7 @@ private function load()
{
$query = "SELECT * FROM " . self::$table . " WHERE transmission_id='%transmission_id%' ";
$result = DB::query(self::$table, $query, array('transmission_id' => $this->transmission_id));
- $data = mysql_fetch_assoc($result);
+ $data = $result[0];
if ($data) {
$this->transmission_id = $data['transmission_id'];
$this->title = $data['title'];
diff --git a/core/User.php b/core/User.php
old mode 100644
new mode 100755
index ed54b68..17ad460
--- a/core/User.php
+++ b/core/User.php
@@ -17,515 +17,521 @@
class User
{
- const GUEST = -1;
-
- const AUTH_TYPE_BASIC = 'basic';
- const AUTH_TYPE_DIGEST = 'digest';
- const AUTH_TYPE_BEARER = 'bearer';
- const AUTH_TYPE_NETWORK = 'network';
-
- private static $table = 'usr';
- private static $link_role = 'user_role';
- private static $link_permission = 'user_permission';
- private static $primary_key = 'usr_id';
- private static $fields = array(
- 'user_id', // will be mapped to usr_id in database table
- 'role_id',
- 'username',
- 'passwd',
- 'password_hash', // will be mapped to passwd in database table
- 'password', // dummy field to hold plain password, will not be saved in database
- 'first_name',
- 'last_name',
- 'phone',
- 'email',
- 'address',
- 'company',
- 'country_id',
- 'timezone_id',
- 'active'
- );
- private static $read_only = array(
- 'user_id',
- 'role_id',
- 'password_hash'
- );
-
- /**
- * @property-read integer $user_id
- * @var integer
- */
- public $user_id = NULL;
-
- /**
- * @property-read integer $role_id
- * not in use
- * @var integer
- */
- private $role_id = NULL;
-
- /**
- * @property-read string $username
- * @see User::set_username
- * @var string
- */
- private $username = NULL;
-
- /** @var string */
- private $passwd = NULL;
-
- /**
- * @property-write string $password
- * Accept plain password, which will be imediately converted into md5 hash
- * @see User::set_password
- */
- /**
- * @property-read string $password_hash
- * represent password hash value from database
- * @see User::get_password_hash
- */
-
- /** @var string */
- public $first_name = NULL;
-
- /** @var string */
- public $last_name = NULL;
-
- /** @var string */
- public $phone = NULL;
-
- /** @var string */
- public $email = NULL;
-
- /** @var string */
- public $address = NULL;
-
- /** @var string */
- public $company = NULL;
-
- /** @var integer */
- public $country_id = NULL;
-
- /** @var string */
- public $language_id = NULL;
-
- /** @var integer */
- public $timezone_id = NULL;
-
- /** @var integer */
- public $active = 0;
-
- /** @var integer */
- public $owner_id = null;
-
- /**
- * ***************************************************** Runtime Variables **
- */
-
- /**
- * @property-read string $aRole
- * list of Roles, to set role call role_assign
- * @see User::role_assign() and User::role_unassign()
- * @var Role[] $aRole
- */
- private $aRole = array();
-
- /** @var array $aPermission */
- private $aPermission = array();
-
- public function __construct($user_id = NULL)
- {
- if (!empty($user_id)) {
- if (!is_numeric($user_id)) {
- if (filter_var($user_id, FILTER_VALIDATE_EMAIL)) {
- $this->email = $user_id;
- } else {
- $this->username = $user_id;
- }
- } else {
- $this->user_id = $user_id;
- if (User::GUEST == $user_id) {
- Corelog::log("Guest user: creating instance", Corelog::CRUD);
- $this->user_id = User::GUEST;
- $this->username = 'guest';
- $this->first_name = 'Anonymous';
- $this->last_name = 'Guest';
- $this->email = 'no-reply@example.com';
- $this->phone = '1111111111';
- $this->address = Conf::get('company:address', 'PK');
- return $this->user_id; // don't proceed further
+ const GUEST = -1;
+
+ const AUTH_TYPE_BASIC = 'basic';
+ const AUTH_TYPE_DIGEST = 'digest';
+ const AUTH_TYPE_BEARER = 'bearer';
+ const AUTH_TYPE_NETWORK = 'network';
+
+ private static $table = 'usr';
+ private static $link_role = 'user_role';
+ private static $link_permission = 'user_permission';
+ private static $primary_key = 'usr_id';
+ private static $fields = array(
+ 'user_id', // will be mapped to usr_id in database table
+ 'role_id',
+ 'username',
+ 'passwd',
+ 'password_hash', // will be mapped to passwd in database table
+ 'password', // dummy field to hold plain password, will not be saved in database
+ 'first_name',
+ 'last_name',
+ 'phone',
+ 'email',
+ 'address',
+ 'company',
+ 'country_id',
+ 'timezone_id',
+ 'active'
+ );
+ private static $read_only = array(
+ 'user_id',
+ 'role_id',
+ 'password_hash'
+ );
+
+ /**
+ * @property-read integer $user_id
+ * @var integer
+ */
+ public $user_id = NULL;
+
+ /**
+ * @property-read integer $role_id
+ * not in use
+ * @var integer
+ */
+ private $role_id = NULL;
+
+ /**
+ * @property-read string $username
+ * @see User::set_username
+ * @var string
+ */
+ private $username = NULL;
+
+ /** @var string */
+ private $passwd = NULL;
+
+ /**
+ * @property-write string $password
+ * Accept plain password, which will be imediately converted into md5 hash
+ * @see User::set_password
+ */
+ /**
+ * @property-read string $password_hash
+ * represent password hash value from database
+ * @see User::get_password_hash
+ */
+
+ /** @var string */
+ public $first_name = NULL;
+
+ /** @var string */
+ public $last_name = NULL;
+
+ /** @var string */
+ public $phone = NULL;
+
+ /** @var string */
+ public $email = NULL;
+
+ /** @var string */
+ public $address = NULL;
+
+ /** @var string */
+ public $company = NULL;
+
+ /** @var integer */
+ public $country_id = NULL;
+
+ /** @var string */
+ public $language_id = NULL;
+
+ /** @var integer */
+ public $timezone_id = NULL;
+
+ /** @var integer */
+ public $active = 0;
+
+ /** @var integer */
+ public $owner_id = null;
+
+ /**
+ * ***************************************************** Runtime Variables **
+ */
+
+ /**
+ * @property-read string $aRole
+ * list of Roles, to set role call role_assign
+ * @see User::role_assign() and User::role_unassign()
+ * @var Role[] $aRole
+ */
+ private $aRole = array();
+
+ /** @var array $aPermission */
+ private $aPermission = array();
+
+ public function __construct($user_id = NULL)
+ {
+ if (!empty($user_id)) {
+ if (!is_numeric($user_id)) {
+ if (filter_var($user_id, FILTER_VALIDATE_EMAIL)) {
+ $this->email = $user_id;
+ } else {
+ $this->username = $user_id;
+ }
+ } else {
+ $this->user_id = $user_id;
+ if (User::GUEST == $user_id) {
+ Corelog::log("Guest user: creating instance", Corelog::CRUD);
+ $this->user_id = User::GUEST;
+ $this->username = 'guest';
+ $this->first_name = 'Anonymous';
+ $this->last_name = 'Guest';
+ $this->email = 'no-reply@example.com';
+ $this->phone = '1111111111';
+ $this->address = Conf::get('company:address', 'PK');
+ return $this->user_id; // don't proceed further
+ }
+ }
+ $this->load();
}
- }
- $this->load();
}
- }
-
- public static function search($aFilter = array())
- {
- $aUser = array();
- $from_str = self::$table;
- $aWhere = array();
- foreach ($aFilter as $search_field => $search_value) {
- switch ($search_field) {
- case 'user_id':
- $aWhere[] = "usr_id = $search_value";
- break;
- case 'created_by':
- $aWhere[] = "created_by = $search_value";
- break;
- case 'username':
- case 'phone':
- case 'email':
- case 'first_name':
- case 'last_name':
- $aWhere[] = "$search_field = '$search_value'";
- break;
-
- case 'created_by':
- $aWhere[] = "created_by = '$search_value'";
- break;
- case 'before':
- $aWhere[] = "date_created <= $search_value";
- break;
- case 'after':
- $aWhere[] = "date_created >= $search_value";
- break;
- }
+
+ public static function search($aFilter = array())
+ {
+ $aUser = array();
+ $from_str = self::$table;
+ $aWhere = array();
+ foreach ($aFilter as $search_field => $search_value) {
+ switch ($search_field) {
+ case 'user_id':
+ $aWhere[] = "usr_id = $search_value";
+ break;
+ case 'created_by':
+ $aWhere[] = "created_by = $search_value";
+ break;
+ case 'username':
+ case 'phone':
+ case 'email':
+ case 'first_name':
+ case 'last_name':
+ $aWhere[] = "$search_field = '$search_value'";
+ break;
+
+ case 'created_by':
+ $aWhere[] = "created_by = '$search_value'";
+ break;
+ case 'before':
+ $aWhere[] = "date_created <= $search_value";
+ break;
+ case 'after':
+ $aWhere[] = "date_created >= $search_value";
+ break;
+ }
+ }
+ if (!empty($aWhere)) {
+ $from_str .= ' WHERE ' . implode(' AND ', $aWhere);
+ }
+
+ $query = "SELECT usr_id AS user_id, username, first_name, last_name, phone, email FROM " . $from_str;
+
+ Corelog::log("user search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
+ $result = DB::query('user', $query);
+ foreach ($result as $data) {
+ $aUser[] = $data;
+ }
+
+ // if no user found, check for guest user
+ if (empty($aUser) && isset($aFilter['user_id']) && $aFilter['user_id'] == User::GUEST) {
+ $oUser = new User($aFilter['user_id']);
+ $aUser[$oUser->user_id] = array(
+ 'user_id' => $oUser->user_id,
+ 'username' => $oUser->username,
+ 'first_name' => $oUser->first_name,
+ 'last_name' => $oUser->last_name,
+ 'phone' => $oUser->phone,
+ 'email' => $oUser->email
+ );
+ }
+
+ return $aUser;
}
- if (!empty($aWhere)) {
- $from_str .= ' WHERE ' . implode(' AND ', $aWhere);
+
+ public function search_role($aFilter = array())
+ {
+ $aFilter['query'] = "SELECT ur.role_id FROM " . self::$link_role . " ur WHERE ur.usr_id=" . $this->user_id;
+ return Role::search($aFilter);
}
- $query = "SELECT usr_id AS user_id, username, first_name, last_name, phone, email FROM " . $from_str;
- Corelog::log("user search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
- $result = DB::query('user', $query);
- while ($data = mysql_fetch_assoc($result)) {
- $aUser[] = $data;
+ public function search_permission($aFilter = array())
+ {
+ $aFilter['query'] = "SELECT up.permission_id FROM " . self::$link_permission . " up WHERE up.usr_id=" . $this->user_id;
+ return Permission::search($aFilter);
}
- // if no user found, check for guest user
- if (empty($aUser) && isset($aFilter['user_id']) && $aFilter['user_id'] == User::GUEST) {
- $oUser = new User($aFilter['user_id']);
- $aUser[$oUser->user_id] = array(
- 'user_id' => $oUser->user_id,
- 'username' => $oUser->username,
- 'first_name' => $oUser->first_name,
- 'last_name' => $oUser->last_name,
- 'phone' => $oUser->phone,
- 'email' => $oUser->email
- );
+ private function load()
+ {
+
+ Corelog::log("Loading user with id:" . $this->user_id . ' name:' . $this->username, Corelog::CRUD);
+ if (!empty($this->email)) {
+ $search_field = 'u.email';
+ $search_value = $this->email;
+ } else if (!empty($this->username)) {
+ $search_field = 'u.username';
+ $search_value = $this->username;
+ } else {
+ $search_field = 'u.usr_id';
+ $search_value = $this->user_id;
+ }
+ $query = "SELECT u.* FROM " . self::$table . " u WHERE %search_field%='%search_value%'";
+ $result = DB::query(self::$table, $query, array('search_field' => $search_field, 'search_value' => $search_value));
+
+ $data = $result[0];
+ if ($data) {
+ $this->user_id = $data['usr_id'];
+ $this->role_id = $data['role_id'];
+ $this->username = $data['username'];
+ $this->passwd = $data['passwd'];
+ $this->first_name = $data['first_name'];
+ $this->last_name = $data['last_name'];
+ $this->phone = $data['phone'];
+ $this->email = $data['email'];
+ $this->address = $data['address'];
+ $this->company = $data['company'];
+ $this->country_id = $data['country_id'];
+ $this->language_id = $data['language_id'];
+ $this->timezone_id = $data['timezone_id'];
+ $this->active = $data['active'];
+
+ $this->load_role();
+ $this->load_permission();
+ } else {
+ throw new CoreException('404', 'User not found');
+ }
}
- return $aUser;
- }
-
- public function search_role($aFilter = array()) {
- $aFilter['query'] = "SELECT ur.role_id FROM " . self::$link_role . " ur WHERE ur.usr_id=" . $this->user_id;
- return Role::search($aFilter);
- }
-
- public function search_permission($aFilter = array()) {
- $aFilter['query'] = "SELECT up.permission_id FROM " . self::$link_permission . " up WHERE up.usr_id=" . $this->user_id;
- return Permission::search($aFilter);
- }
-
- private function load()
- {
- Corelog::log("Loading user with id:" . $this->user_id . ' name:' . $this->username, Corelog::CRUD);
- if (!empty($this->email)) {
- $search_field = 'u.email';
- $search_value = $this->email;
- } else if (!empty($this->username)) {
- $search_field = 'u.username';
- $search_value = $this->username;
- } else {
- $search_field = 'u.usr_id';
- $search_value = $this->user_id;
+ private function load_role()
+ {
+ $this->aRole = array();
+ $listRole = $this->search_role();
+ foreach ($listRole as $aRole) {
+ $role_id = $aRole['role_id'];
+ $this->aRole[$role_id] = new Role($role_id);
+ }
}
- $query = "SELECT u.* FROM " . self::$table . " u WHERE %search_field%='%search_value%'";
- $result = DB::query(self::$table, $query, array('search_field' => $search_field, 'search_value' => $search_value));
- $data = mysql_fetch_assoc($result);
- if ($data) {
- $this->user_id = $data['usr_id'];
- $this->role_id = $data['role_id'];
- $this->username = $data['username'];
- $this->passwd = $data['passwd'];
- $this->first_name = $data['first_name'];
- $this->last_name = $data['last_name'];
- $this->phone = $data['phone'];
- $this->email = $data['email'];
- $this->address = $data['address'];
- $this->company = $data['company'];
- $this->country_id = $data['country_id'];
- $this->language_id = $data['language_id'];
- $this->timezone_id = $data['timezone_id'];
- $this->active = $data['active'];
-
- $this->load_role();
- $this->load_permission();
- } else {
- throw new CoreException('404', 'User not found');
+
+ private function load_permission()
+ {
+ $this->aPermission = array();
+ $listPermission = $this->search_permission();
+ foreach ($listPermission as $aPermission) {
+ $permission_id = $aPermission['permission_id'];
+ $this->aPermission[$permission_id] = $aPermission['name'];
+ }
}
- }
-
- private function load_role()
- {
- $this->aRole = array();
- $listRole = $this->search_role();
- foreach ($listRole as $aRole) {
- $role_id = $aRole['role_id'];
- $this->aRole[$role_id] = new Role($role_id);
+
+ public function delete()
+ {
+ Corelog::log("Deleting user: $this->user_id", Corelog::CRUD);
+ // first remove roles assignements for current user
+ $query = 'DELETE FROM ' . self::$link_role . ' WHERE usr_id=%user_id%';
+ DB::query(self::$link_role, $query, array('user_id' => $this->user_id));
+ // then remove permissions for current user
+ $query = 'DELETE FROM ' . self::$link_permission . ' WHERE usr_id=%user_id%';
+ DB::query(self::$link_permission, $query, array('user_id' => $this->user_id));
+ // now delete user
+ return DB::delete(self::$table, 'usr_id', $this->user_id);
}
- }
-
- private function load_permission()
- {
- $this->aPermission = array();
- $listPermission = $this->search_permission();
- foreach($listPermission as $aPermission) {
- $permission_id = $aPermission['permission_id'];
- $this->aPermission[$permission_id] = $aPermission['name'];
+
+ public function __isset($field)
+ {
+ $method_name = 'isset_' . $field;
+ if (method_exists($this, $method_name)) {
+ return $this->$method_name();
+ } else {
+ return isset($this->$field);
+ }
}
- }
-
- public function delete()
- {
- Corelog::log("Deleting user: $this->user_id", Corelog::CRUD);
- // first remove roles assignements for current user
- $query = 'DELETE FROM ' . self::$link_role . ' WHERE usr_id=%user_id%';
- DB::query(self::$link_role, $query, array('user_id' => $this->user_id));
- // then remove permissions for current user
- $query = 'DELETE FROM ' . self::$link_permission . ' WHERE usr_id=%user_id%';
- DB::query(self::$link_permission, $query, array('user_id' => $this->user_id));
- // now delete user
- return DB::delete(self::$table, 'usr_id', $this->user_id);
- }
-
- public function __isset($field)
- {
- $method_name = 'isset_' . $field;
- if (method_exists($this, $method_name)) {
- return $this->$method_name();
- } else {
- return isset($this->$field);
+
+ public function __get($field)
+ {
+ $method_name = 'get_' . $field;
+ if (method_exists($this, $method_name)) {
+ return $this->$method_name();
+ } else if (!empty($field) && isset($this->$field)) {
+ return $this->$field;
+ }
+ return NULL;
}
- }
-
- public function __get($field)
- {
- $method_name = 'get_' . $field;
- if (method_exists($this, $method_name)) {
- return $this->$method_name();
- } else if (!empty($field) && isset($this->$field)) {
- return $this->$field;
+
+ public function __set($field, $value)
+ {
+ $method_name = 'set_' . $field;
+ if (method_exists($this, $method_name)) {
+ $this->$method_name($value);
+ } else if (empty($field) || in_array($field, self::$read_only)) {
+ return;
+ } else {
+ $this->$field = $value;
+ }
}
- return NULL;
- }
-
- public function __set($field, $value)
- {
- $method_name = 'set_' . $field;
- if (method_exists($this, $method_name)) {
- $this->$method_name($value);
- } else if (empty($field) || in_array($field, self::$read_only)) {
- return;
- } else {
- $this->$field = $value;
+
+ public function get_id()
+ {
+ return $this->user_id;
}
- }
- public function get_id()
- {
- return $this->user_id;
- }
+ private function set_username($username)
+ {
+ if (empty($this->username)) {
+ $this->username = $username;
+ }
+ }
- private function set_username($username)
- {
- if (empty($this->username)) {
- $this->username = $username;
+ private function set_password($password)
+ {
+ $this->passwd = md5($password);
}
- }
-
- private function set_password($password)
- {
- $this->passwd = md5($password);
- }
-
- private function get_password_hash()
- {
- return $this->passwd;
- }
-
- public function role_assign($role_id)
- {
- $oRole = new Role($role_id);
- $this->aRole[$oRole->role_id] = $oRole;
- }
-
- public function role_unassign($role_id)
- {
- unset($this->aRole[$role_id]);
- }
-
- public function permission_assign($permission_id)
- {
- $oPermission = new Permission($permission_id);
- $this->aPermission[$oPermission->permission_id] = $oPermission->name;
- }
-
- public function permission_unassign($permission_id)
- {
- unset($this->aPermission[$permission_id]);
- }
-
- public function save()
- {
- $data = array(
- 'usr_id' => $this->user_id,
- 'user_id' => $this->user_id,
- 'role_id' => $this->role_id,
- 'username' => $this->username,
- 'passwd' => $this->password_hash,
- 'first_name' => $this->first_name,
- 'last_name' => $this->last_name,
- 'phone' => $this->phone,
- 'email' => $this->email,
- 'address' => $this->address,
- 'company' => $this->company,
- 'country_id' => $this->country_id,
- 'language_id' => $this->language_id,
- 'timezone_id' => $this->timezone_id,
- 'active' => $this->active
- // Note: user_id or created_by field can't be updated here, instead use associate method
- );
- if (!empty($this->password)) {
- $data['passwd'] = md5($this->password);
+
+ private function get_password_hash()
+ {
+ return $this->passwd;
}
- if (isset($data['user_id']) && !empty($data['user_id'])) {
- // first remove existing roles assignements
- $query = 'DELETE FROM ' . self::$link_role . ' WHERE usr_id=%user_id%';
- DB::query(self::$link_role, $query, array('user_id' => $this->user_id));
- // then remove permissions for current user
- $query = 'DELETE FROM ' . self::$link_permission . ' WHERE usr_id=%user_id%';
- DB::query(self::$link_permission, $query, array('user_id' => $this->user_id));
- // update existing record
- $result = DB::update(self::$table, $data, 'usr_id');
- Corelog::log("User updated: $this->user_id", Corelog::CRUD);
- } else {
- // add new
- $result = DB::update(self::$table, $data, false);
- $data['user_id'] = $data['usr_id']; // mapping
- $this->user_id = $data['user_id'];
- Corelog::log("New user created: $this->user_id", Corelog::CRUD);
+
+ public function role_assign($role_id)
+ {
+
+ $oRole = new Role($role_id);
+ $this->aRole[$oRole->role_id] = $oRole;
}
- // save roles for current user
- foreach ($this->aRole as $oRole) {
- $query = "INSERT INTO " . self::$link_role . " (usr_id, role_id) VALUES (%user_id%, %role_id%)";
- $result = DB::query(self::$link_role, $query, array('user_id' => $this->user_id, 'role_id' => $oRole->role_id));
+ public function role_unassign($role_id)
+ {
+ unset($this->aRole[$role_id]);
}
- // save permissions for current user
- foreach ($this->aPermission as $permission_id) {
- $query = "INSERT INTO " . self::$link_permission . " (usr_id, permission_id) VALUES (%user_id%, %permission_id%)";
- $result = DB::query(self::$link_permission, $query, array('user_id' => $this->user_id, 'permission_id' => $permission_id));
+ public function permission_assign($permission_id)
+ {
+ $oPermission = new Permission($permission_id);
+ $this->aPermission[$oPermission->permission_id] = $oPermission->name;
}
- return $result;
- }
-
- public function generate_token()
- {
- $key_file = Conf::get('security:private_key', '/usr/ictcore/etc/ssh/ib_node');
- $private_key = file_get_contents($key_file);
-
- $token = array(
- "iss" => Conf::get('website:url'),
- "iat" => time(),
- "nbf" => time(),
- "exp" => time() + Conf::get('security:token_expiry', (60 * 60 * 24 * 30 * 12 * 1)), // valid for one year
- "user_id" => $this->user_id,
- "username" => $this->username,
- "is_admin" => can_access('user_create', $this->user_id) ? "1" : "0",
- "api-version" => "1.0"
- );
+ public function permission_unassign($permission_id)
+ {
+ unset($this->aPermission[$permission_id]);
+ }
- return JWT::encode($token, $private_key, Conf::get('security:hash_type', 'RS256'));
- }
-
- public static function authenticate($access_key, $key_type = User::AUTH_TYPE_BASIC)
- {
- $oUser = null;
- switch ($key_type) {
- case User::AUTH_TYPE_BEARER:
- try {
- $key_file = Conf::get('security:public_key', '/usr/ictcore/etc/ssh/ib_node.pub');
- $hash_type = Conf::get('security:hash_type', 'RS256');
- $public_key = file_get_contents($key_file);
- $token = JWT::decode($access_key, $public_key, array($hash_type));
- if ($token) {
- // TODO check api-version
- if (!empty($token->user_id)) {
- $oUser = new self($token->user_id);
- return $oUser;
- }
- }
- } catch (Exception $e) {
- Corelog::log('Unable to parse bearer token. error: ' . $e->getMessage(), Corelog::ERROR);
+ public function save()
+ {
+ $data = array(
+ 'usr_id' => $this->user_id,
+ 'user_id' => $this->user_id,
+ 'role_id' => $this->role_id,
+ 'username' => $this->username,
+ 'passwd' => $this->password_hash,
+ 'first_name' => $this->first_name,
+ 'last_name' => $this->last_name,
+ 'phone' => $this->phone,
+ 'email' => $this->email,
+ 'address' => $this->address,
+ 'company' => $this->company,
+ 'country_id' => $this->country_id,
+ 'language_id' => $this->language_id,
+ 'timezone_id' => $this->timezone_id,
+ 'active' => $this->active
+ // Note: user_id or created_by field can't be updated here, instead use associate method
+ );
+ if (!empty($this->password)) {
+ $data['passwd'] = md5($this->password);
+ }
+ if (isset($data['user_id']) && !empty($data['user_id'])) {
+ // first remove existing roles assignements
+ $query = 'DELETE FROM ' . self::$link_role . ' WHERE usr_id=%user_id%';
+ DB::query(self::$link_role, $query, array('user_id' => $this->user_id));
+ // then remove permissions for current user
+ $query = 'DELETE FROM ' . self::$link_permission . ' WHERE usr_id=%user_id%';
+ DB::query(self::$link_permission, $query, array('user_id' => $this->user_id));
+ // update existing record
+ $result = DB::update(self::$table, $data, 'usr_id');
+ Corelog::log("User updated: $this->user_id", Corelog::CRUD);
+ } else {
+ // add new
+ $result = DB::update(self::$table, $data, false);
+ $data['user_id'] = $data['usr_id']; // mapping
+ $this->user_id = $data['user_id'];
+ Corelog::log("New user created: $this->user_id", Corelog::CRUD);
}
- Corelog::log('Bearer authentication failed', Corelog::ERROR);
- return false;
- case User::AUTH_TYPE_NETWORK:
- return false; // TODO
- case User::AUTH_TYPE_DIGEST:
- if (!empty($access_key['username'])) {
- $oUser = new self($access_key['username']);
- if ($oUser->get_password_hash() == $access_key['password']) {
- return $oUser;
- }
+ // save roles for current user
+ foreach ($this->aRole as $oRole) {
+ $query = "INSERT INTO " . self::$link_role . " (usr_id, role_id) VALUES (%user_id%, %role_id%)";
+ $result = DB::query(self::$link_role, $query, array('user_id' => $this->user_id, 'role_id' => $oRole->role_id));
}
- Corelog::log('Basic authentication failed', Corelog::ERROR);
- return false;
- case User::AUTH_TYPE_BASIC:
- default:
- if (!empty($access_key['username'])) {
- $oUser = new self($access_key['username']);
- if ($oUser->get_password_hash() == md5($access_key['password'])) {
- return $oUser;
- }
+ // save permissions for current user
+ foreach ($this->aPermission as $permission_id) {
+ $query = "INSERT INTO " . self::$link_permission . " (usr_id, permission_id) VALUES (%user_id%, %permission_id%)";
+ $result = DB::query(self::$link_permission, $query, array('user_id' => $this->user_id, 'permission_id' => $permission_id));
}
- Corelog::log('Network authentication has been failed', Corelog::ERROR);
- return false;
+
+ return $result;
}
- }
-
- public function authorize($permission)
- {
- $aPart = explode('_', $permission);
- $level = count($aPart);
- $perm = '';
-
- // first check if parent permission exist and then try for sub permissions
- for ($i = 0; $i < $level; $i++) {
- $perm .= $aPart[$i];
- if (in_array($perm, $this->aPermission)) {
- return true;
- } else {
- $perm .= '_';
- }
+
+ public function generate_token()
+ {
+ $key_file = Conf::get('security:private_key', '/usr/ictcore/etc/ssh/ib_node');
+ $private_key = file_get_contents($key_file);
+
+ $token = array(
+ "iss" => Conf::get('website:url'),
+ "iat" => time(),
+ "nbf" => time(),
+ "exp" => time() + Conf::get('security:token_expiry', (60 * 60 * 24 * 30 * 12 * 1)), // valid for one year
+ "user_id" => $this->user_id,
+ "username" => $this->username,
+ "is_admin" => can_access('user_create', $this->user_id) ? "1" : "0",
+ "api-version" => "1.0"
+ );
+
+ return JWT::encode($token, $private_key, Conf::get('security:hash_type', 'RS256'));
}
- // now try with role permissions
- foreach ($this->aRole as $oRole) {
- if ($oRole->authorize($permission)) {
- return true;
- }
+ public static function authenticate($access_key, $key_type = User::AUTH_TYPE_BASIC)
+ {
+ $oUser = null;
+ switch ($key_type) {
+ case User::AUTH_TYPE_BEARER:
+ try {
+ $key_file = Conf::get('security:public_key', '/usr/ictcore/etc/ssh/ib_node.pub');
+ $hash_type = Conf::get('security:hash_type', 'RS256');
+ $public_key = file_get_contents($key_file);
+ $token = JWT::decode($access_key, $public_key, array($hash_type));
+ if ($token) {
+ // TODO check api-version
+ if (!empty($token->user_id)) {
+ $oUser = new self($token->user_id);
+ return $oUser;
+ }
+ }
+ } catch (Exception $e) {
+ Corelog::log('Unable to parse bearer token. error: ' . $e->getMessage(), Corelog::ERROR);
+ }
+ Corelog::log('Bearer authentication failed', Corelog::ERROR);
+ return false;
+
+ case User::AUTH_TYPE_NETWORK:
+ return false; // TODO
+ case User::AUTH_TYPE_DIGEST:
+ if (!empty($access_key['username'])) {
+ $oUser = new self($access_key['username']);
+ if ($oUser->get_password_hash() == $access_key['password']) {
+ return $oUser;
+ }
+ }
+ Corelog::log('Basic authentication failed', Corelog::ERROR);
+ return false;
+
+ case User::AUTH_TYPE_BASIC:
+ default:
+ if (!empty($access_key['username'])) {
+ $oUser = new self($access_key['username']);
+ if ($oUser->get_password_hash() == md5($access_key['password'])) {
+ return $oUser;
+ }
+ }
+ Corelog::log('Network authentication has been failed', Corelog::ERROR);
+ return false;
+ }
}
- // authorization fialed
- return false;
- }
+ public function authorize($permission)
+ {
+ $aPart = explode('_', $permission);
+ $level = count($aPart);
+ $perm = '';
+
+ // first check if parent permission exist and then try for sub permissions
+ for ($i = 0; $i < $level; $i++) {
+ $perm .= $aPart[$i];
+ if (in_array($perm, $this->aPermission)) {
+ return true;
+ } else {
+ $perm .= '_';
+ }
+ }
+
+ // now try with role permissions
+ foreach ($this->aRole as $oRole) {
+ if ($oRole->authorize($permission)) {
+ return true;
+ }
+ }
+
+ // authorization fialed
+ return false;
+ }
}
diff --git a/core/User/Permission.php b/core/User/Permission.php
old mode 100644
new mode 100755
index 86e8e6c..515cf4e
--- a/core/User/Permission.php
+++ b/core/User/Permission.php
@@ -67,7 +67,7 @@ public static function search($aFilter = array())
$query = "SELECT permission_id, name FROM " . $from_str;
Corelog::log("permission search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query('permission', $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data) {
$aPermission[] = $data;
}
@@ -78,8 +78,7 @@ private function load()
{
Corelog::log("Loading permission: $this->permission_id", Corelog::CRUD);
$query = "SELECT * FROM " . self::$table . " WHERE permission_id='%permission_id%'";
- $result = DB::query(self::$table, $query, array('permission_id' => $this->permission_id));
- $data = mysql_fetch_assoc($result);
+ $data = DB::query(self::$table, $query, array('permission_id' => $this->permission_id));
if ($data) {
$this->permission_id = $data['permission_id'];
$this->name = $data['name'];
diff --git a/core/User/Role.php b/core/User/Role.php
old mode 100644
new mode 100755
index bc5d470..0860f1b
--- a/core/User/Role.php
+++ b/core/User/Role.php
@@ -49,6 +49,8 @@ public function __construct($role_id = NULL)
if (!empty($role_id)) {
$this->role_id = $role_id;
$this->load();
+ }else {
+
}
}
@@ -76,7 +78,7 @@ public static function search($aFilter = array())
$query = "SELECT role_id, name FROM " . $from_str;
Corelog::log("role search with $query", Corelog::DEBUG, array('aFilter' => $aFilter));
$result = DB::query('role', $query);
- while ($data = mysql_fetch_assoc($result)) {
+ forEach ($result as $data) {
$aRole[] = $data;
}
@@ -88,7 +90,7 @@ private function load()
Corelog::log("Loading role: $this->role_id", Corelog::CRUD);
$query = "SELECT * FROM " . self::$table . " WHERE role_id='%role_id%'";
$result = DB::query(self::$table, $query, array('role_id' => $this->role_id));
- $data = mysql_fetch_assoc($result);
+ $data = $result[0];
if ($data) {
$this->role_id = $data['role_id'];
$this->name = $data['name'];
@@ -102,6 +104,7 @@ private function load()
private function load_permission()
{
+
$this->aPermission = array();
$query = "SELECT rp.permission_id FROM " . self::$link_permission . " rp WHERE rp.role_id=" . $this->role_id;
diff --git a/core/lib/Conf.php b/core/lib/Conf.php
old mode 100644
new mode 100755
index fc34fe9..af10424
--- a/core/lib/Conf.php
+++ b/core/lib/Conf.php
@@ -96,16 +96,21 @@ protected static function database_conf_load($filter = array(), $type = null)
$filter_string = implode(' AND ', $filter);
// in following query ORDER BY class make sure that top level values should be overwritten specific configuration
- $query = "SELECT c.type, c.name, cd.data FROM configuration c LEFT JOIN configuration_data cd
+
+ $query = "SELECT c.type, c.name, cd.data FROM configuration c
+ LEFT JOIN configuration_data cd
ON c.configuration_id = cd.configuration_id
- WHERE $filter_string
+ WHERE $filter_string
ORDER BY cd.class ASC, cd.node_id ASC, cd.created_by ASC";
- $result = DB::query('configuration', $query);
- if (!$result) {
+
+ //$query = "SELECT type, name, data FROM configuration c";
+ $result = DB::query("configuration",$query);
+
+ /* if (!$result) {
throw new CoreException('500', 'Unable to get configuration, query failed');
- }
+ }*/
- while ($config = mysql_fetch_assoc($result)) {
+ foreach($result as $config) {
$type = $config['type'];
$name = $config['name'];
$data = $config['data'];
@@ -131,8 +136,8 @@ public static function database_conf_set($type, $name, $data, $reference = array
$query = "SELECT configuration_id FROM configuration
WHERE (permission_flag & $permission)=$permission AND type='$type' AND name='$name'";
$result = DB::query('configuration', $query);
- if (mysql_num_rows($result)) {
- $configuration_id = mysql_result($result, 0, 0);
+ if (count($result)) {
+ $configuration_id = $result[0][0];
} else {
Corelog::log("Unable to save configuration. type:$type, name:$name", Corelog::ERROR);
return;
diff --git a/core/lib/Conf/File.php b/core/lib/Conf/File.php
old mode 100644
new mode 100755
index 6e87eef..a7019dd
--- a/core/lib/Conf/File.php
+++ b/core/lib/Conf/File.php
@@ -23,6 +23,7 @@ class File extends Conf
public static function load($file_path = NULL)
{
+
$configSource = is_file($file_path) ? $file_path : self::$config_file;
//reading configuration file.
diff --git a/core/lib/Conf/System.php b/core/lib/Conf/System.php
old mode 100644
new mode 100755
diff --git a/core/lib/Conf/User.php b/core/lib/Conf/User.php
old mode 100644
new mode 100755
diff --git a/core/lib/Config.php b/core/lib/Config.php
old mode 100644
new mode 100755
index f5e6969..6ff6e1b
--- a/core/lib/Config.php
+++ b/core/lib/Config.php
@@ -91,8 +91,8 @@ public function __construct($file_name = '', $file_path = '', $gateway_flag = 0)
}
$result = DB::query('config', "SELECT config_id FROM config WHERE file_name='$this->file_name' AND file_path='$this->file_path'");
- if (mysql_num_rows($result)) {
- $this->config_id = mysql_result($result, 0, 0);
+ if ($result) {
+ $this->config_id = $result[0][0];
} else {
Corelog::log("Creating new Config $this->file_name", Corelog::COMMON);
}
@@ -112,8 +112,7 @@ public function create($source = '', $is_ini = false)
'version' => 1,
'gateway_flag' => $this->gateway_flag
);
- DB::update('config', $data);
- $this->config_id = mysql_insert_id(DB::$link);
+ $this->config_id = DB::update('config', $data);
}
Corelog::log("Config file created $this->file_name", Corelog::COMMON, $this);
@@ -132,8 +131,8 @@ public function drop()
public function load($group_name = false, $group_child = false, $description = false, $node_id = false)
{
- $rsConfig = DB::query('config', "SELECT * FROM config WHERE config_id=$this->config_id LIMIT 1");
- if ($rsConfig && $config = mysql_fetch_object($rsConfig)) {
+ $config = DB::query('config', "SELECT * FROM config WHERE config_id=$this->config_id LIMIT 1");
+ if ($config) {
$this->config_id = $config->config_id;
$this->source = $config->source;
$this->version = $config->version;
@@ -160,7 +159,7 @@ public function load($group_name = false, $group_child = false, $description = f
WHERE file_name='$this->file_name' $group_filter
ORDER BY group_name, group_child, config_data_id";
$rsData = DB::query('config_data', $query);
- while ($data_row = mysql_fetch_assoc($rsData)) {
+ forEach ($rsData as $data_row) {
$this->data[] = $data_row['data'];
}
}
@@ -193,15 +192,15 @@ public function insert($raw_data, $raw_description = false, $skip_duplicate = fa
$raw_description = $this->description;
}
- $description = mysql_real_escape_string($raw_description, DB::$link);
- $data = mysql_real_escape_string($raw_data, DB::$link);
+ $description = $raw_description;
+ $data = $raw_data;
if ($skip_duplicate) {
$query = "SELECT COUNT(*) FROM config_data
WHERE group_name='$this->group_name' AND group_child='$this->group_child' AND data='$data'
AND description='$description' AND file_name='$this->file_name'";
- $rsQry = mysql_query($query, DB::$link);
- if (mysql_result($rsQry, 0, 0) > 0) {
+ $rsQry = DB::rawSelect($query);
+ if ($rsQry[0][0] > 0) {
return false;
}
}
@@ -238,7 +237,7 @@ public function update()
// currently not fully implemented
DB::query('config', "UPDATE config SET version=version+1 WHERE file_name='$this->file_name' LIMIT 1");
$result = DB::query('config', "SELECT version FROM config WHERE file_name='$this->file_name' LIMIT 1");
- $this->version = mysql_result($result, 0, 0);
+ $this->version = $result[0];
return $this->version;
}
@@ -288,7 +287,7 @@ public function node_update($node_id, $gateway_flag = false)
$query_filter";
$rs1 = DB::query('config', $query);
- while ($config = mysql_fetch_object($rs1)) {
+ forEach ($rs1 as $config) {
$this->config_id = $config->config_id;
$this->load(false, false, false, $node_id);
@@ -313,7 +312,7 @@ public function node_update_ack($node_id)
{
// insert new record in config_node table if there is not already
$result = DB::query('config_node', "SELECT * FROM config_node WHERE config_id=$this->config_id AND node_id=$node_id LIMIT 1");
- if (mysql_num_rows($result) < 1) {
+ if (count($result) < 1) {
DB::query('config_node', "INSERT INTO config_node (config_id, node_id, date_created)
VALUES ($this->config_id, $node_id, UNIX_TIMESTAMP())");
}
@@ -326,13 +325,16 @@ public function clean()
{
Corelog::log("Cleaning absolute Config files", Corelog::COMMON);
$result = DB::query('config', "SELECT config_id FROM config WHERE version < 0");
- while ($result && $config = mysql_fetch_object($result)) {
+ if($result){
+ forEach ($result as $config) {
$rsData = DB::query('config_data', "SELECT * FROM config_node WHERE file_name='$config->file_name' AND version > 0");
- if (!mysql_num_rows($rsData)) {
+ //:confusion
+ if (!count($rsData)) {
DB::query('config_data', "DELETE FROM config_node WHERE file_name='$config->file_name'");
DB::query('config', "DELETE FROM config WHERE config_id=$config->config_id");
}
}
+ }
}
}
\ No newline at end of file
diff --git a/core/lib/CoreException.php b/core/lib/CoreException.php
old mode 100644
new mode 100755
diff --git a/core/lib/CoreThread.php b/core/lib/CoreThread.php
old mode 100644
new mode 100755
diff --git a/core/lib/Corelog.php b/core/lib/Corelog.php
old mode 100644
new mode 100755
diff --git a/core/lib/DB.php b/core/lib/DB.php
index c92884c..1ed2cca 100755
--- a/core/lib/DB.php
+++ b/core/lib/DB.php
@@ -10,379 +10,482 @@
* *************************************************************** */
// DB related functions
+use ICT\Core\CoreException;
+use PDO;
+
class DB
{
+ static $link = NULL;
+ static $pdo = NULL;
+
+ public function __construct()
+ {
+ $db_port = Conf::get('db:port', '3306');
+ $db_host = Conf::get('db:host', 'localhost') . ':' . $db_port;
+ $db_user = Conf::get('db:user', 'myuser');
+ $db_pass = Conf::get('db:pass', '');
+ $db_name = Conf::get('db:name', 'ictcore');
+
+ try {
+ self::$pdo = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
+ self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ } catch (Exception $e) {
+ echo "Connection failed" . $e->getMessage();
+ }
- static $link = NULL;
-
- static function connect($link_new = FALSE)
- {
- $db_port = Conf::get('db:port', '3306');
- $db_host = Conf::get('db:host', 'localhost') . ':' . $db_port;
- $db_user = Conf::get('db:user', 'myuser');
- $db_pass = Conf::get('db:pass', '');
- $db_name = Conf::get('db:name', 'ictcore');
+ //$dsn = $this->_engine.':dbname='.$this->_db.';host='.$this->_server.';charset=utf8';
+ //parent::__construct($dsn, $this->_user, $this->_password);
+ //$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $link = mysql_connect($db_host, $db_user, $db_pass, $link_new);
- if (!$link) {
- throw new CoreException('500', 'Unable to connect database server error:' . mysql_error($link));
- }
- $result = mysql_select_db($db_name, $link);
- if (!$result) {
- throw new CoreException('500', 'Unable to select database');
- }
- mysql_query("SET time_zone = '+00:00'", $link); // required to bypass server timezone settings
-
- return $link;
- }
-
- static function next_record_id($table, $field = '')
- {
- $result = mysql_query("SELECT sequence FROM sequence WHERE table_name='$table'", DB::$link);
- if (mysql_num_rows($result)) {
- $newid = mysql_result($result, 0) + 1;
- mysql_query("UPDATE sequence SET sequence = $newid WHERE table_name = '$table'", DB::$link);
- return $newid;
- } else {
- $field = $field ? $field : $table . '_id';
- $result = mysql_query("SELECT MAX($field) as newid FROM $table", DB::$link);
- if ($result) {
- $col_newid = mysql_result($result, 0);
- $newid = $col_newid ? $col_newid + 1 : 1;
- } else {
- $newid = 0;
- }
- $newid = $newid ? $newid + 1 : 1;
- mysql_query("INSERT INTO sequence (table_name, sequence) VALUES ('$table', $newid)", DB::$link);
- return $newid;
}
- }
-
- static function save_record_id($table, $index)
- {
- $result = mysql_query("SELECT sequence FROM sequence WHERE table_name='$table'", DB::$link);
- if (mysql_num_rows($result)) {
- mysql_query("UPDATE sequence SET sequence=$index WHERE table_name='$table'", DB::$link);
- } else {
- mysql_query("INSERT INTO sequence (table_name, sequence) VALUES ('$table', $index)", DB::$link);
- }
- }
- static function getSelectData($DBName, $DBField, $allData = true, $DBOrderField = '0', $check_auth = FALSE)
- {
- if ($DBOrderField == '0') {
- $DBOrderField = $DBField;
- }
+ static function connect($link_new = FALSE)
+ {
+ $db_port = Conf::get('db:port', '3306');
+ $db_host = Conf::get('db:host', 'localhost') . ':' . $db_port;
+ $db_user = Conf::get('db:user', 'myuser');
+ $db_pass = Conf::get('db:pass', '');
+ $db_name = Conf::get('db:name', 'ictcore');
+
+ try {
+ self::$pdo = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
+ self::$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ } catch (Exception $e) {
+ echo "Connection failed" . $e->getMessage();
+ }
+ //mysqli_query("SET time_zone = '+00:00'", $link); // required to bypass server timezone settings
- if ($allData == true) {
- $whereCondition = " WHERE %auth_filter%";
- } else {
- $whereCondition = " WHERE " . $DBName . "_id <> 0 AND %auth_filter%";
+ return self::$pdo;
}
- $query = "
- SELECT " . $DBName . "_id, " . $DBField . " AS name
- FROM " . $DBName . " " . $whereCondition . "
- ORDER BY $DBName.$DBOrderField";
+ static function next_record_id($table, $field = '')
+ {
+ //replacing: $result = mysql_query("SELECT sequence FROM sequence WHERE table_name='$table'", DB::$link);
+ $stmt = self::$pdo->prepare("SELECT sequence FROM sequence WHERE table_name=:table");
+ $stmt->execute(['table' => $table]);
+ $result = $stmt->fetchAll();
+ if ($result) {
+ $newid = count($result) + 1;
+ //replacing:mysql_query("UPDATE sequence SET sequence = $newid WHERE table_name = '$table'", DB::$link);
+ $stmt = self::$pdo->prepare("UPDATE sequence SET sequence = :newid WHERE table_name = :table");
+ $stmt->execute(['table' => $table, 'newid' => $newid]);
+ return $newid;
+ } else {
+ $field = $field ? $field : $table . '_id';
+ //$result = mysql_query("SELECT MAX($field) as newid FROM $table", DB::$link);
+ //searching maximum value in _id column that is the last id
+ $stmt = self::$pdo->prepare("SELECT MAX($field) as newid FROM $table");
+ $stmt->execute();
+ $result = $stmt->fetch();
+ if ($result) {
+ //Replacing: $col_newid = $result[0];
+ $col_newid = $result[0];
+ $newid = $col_newid ? $col_newid + 1 : 1;
+ } else {
+ $newid = 0;
+ }
+ $newid = $newid ? $newid + 1 : 1;
- return self::getSelectData_custom($DBName, $query, $check_auth);
- }
+ //mysql_query("INSERT INTO sequence (table_name, sequence) VALUES ('$table', $newid)", DB::$link);
- static function getSelectData_custom($DBTable, $query, $check_auth = FALSE)
- {
+ $stmt = self::$pdo->prepare("INSERT INTO sequence (table_name, sequence) VALUES (:table, :newid)");
+ $stmt->execute(['table_name' => $table, 'newid' => $newid]);
- $result = self::query($DBTable, $query, array(), $check_auth);
- $aRecord = array();
- while ($record = mysql_fetch_array($result)) {
- if (!empty($record[1]) && !is_null($record[1])) {
- $id = $record[0];
- $aRecord[$id] = $record[1];
- }
+ return $newid;
+ }
}
- return $aRecord;
- }
+ static function column_list($table)
+ {
+ $aColumn = array();
+ //$result = mysql_query("SHOW COLUMNS FROM $table", DB::$link);
+ try {
+ $stmt = self::$pdo->query("SHOW COLUMNS FROM $table ");
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- static function column_list($table)
- {
- $aColumn = array();
- $result = mysql_query("SHOW COLUMNS FROM $table", DB::$link);
- if ($result === FALSE) {
- Corelog::log("DB:unknown table: $table: " . mysql_error(DB::$link), Corelog::ERROR);
- return FALSE;
- }
- while ($column = mysql_fetch_assoc($result)) {
- $column_name = $column['Field'];
- $aColumn[$column_name] = $column;
+ if (!$result) {
+ return FALSE;
+ }
+ foreach ($result as $column) {
+ $column_name = $column['Field'];
+ $aColumn[$column_name] = $column;
+ }
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
+ Corelog::log("DB:unknown table: $table: " . $exception->getMessage(), Corelog::ERROR);
+ }
+ return $aColumn;
}
- return $aColumn;
- }
-
- static function column_map($aColumn, $aData)
- {
- static $non_text = array('bit', 'bigint', 'bool', 'boolean',
- 'dec', 'decimal', 'double', 'float',
- 'int', 'integer', 'mediumint', 'real',
- 'smallint', 'tinyint', 'function'
- );
- $aMap = array(); // an item will consist array('field' => column_id, 'value' => 'something', is_string = false, 'default' = NULL);
- // Field | Type | Null | Key | Default | Extra ==> Value
- foreach ($aColumn as $column_name => $column) {
- if (array_key_exists($column_name, $aData) && $aData[$column_name] !== NULL) {
- $type = strtolower(substr($column['Type'], 0, strpos($column['Type'], '(')));
- $aMap[$column_name] = array(
- 'name' => $column['Field'],
- 'value' => mysql_real_escape_string($aData[$column_name], DB::$link),
- 'is_string' => !in_array(trim($type), $non_text), // treat as string field not is a number
- 'default' => $column['Default']
+
+ static function column_map($aColumn, $aData)
+ {
+ static $non_text = array('bit', 'bigint', 'bool', 'boolean',
+ 'dec', 'decimal', 'double', 'float',
+ 'int', 'integer', 'mediumint', 'real',
+ 'smallint', 'tinyint', 'function'
);
- }
- }
+ $aMap = array(); // an item will consist array('field' => column_id, 'value' => 'something', is_string = false, 'default' = NULL);
+ // Field | Type | Null | Key | Default | Extra ==> Value
+ foreach ($aColumn as $column_name => $column) {
+ if (array_key_exists($column_name, $aData) && $aData[$column_name] !== NULL) {
+ $type = strtolower(substr($column['Type'], 0, strpos($column['Type'], '(')));
+ $aMap[$column_name] = array(
+ 'name' => $column['Field'],
+ 'value' => $aData[$column_name],
+ 'is_string' => !in_array(trim($type), $non_text), // treat as string field not is a number
+ 'default' => $column['Default']
+ );
+ }
+ }
- return $aMap;
- }
-
- static function where($table, $conditions, $glue = 'AND', $start = 'WHERE')
- {
- $aColumn = self::column_list($table);
- $aFilter = self::column_map($aColumn, $conditions);
-
- $cond = array();
- foreach ($aFilter as $field => $filter) {
- $value = $filter['value'];
- if (is_numeric($value)) {
- $cond[] = "$field = $value";
- } else if (strpos($value, 'auth_filter') !== false) {
- $cond[] = "$value";
- } else if (strpos($value, '%') !== false) {
- $cond[] = "$field LIKE '$value'";
- } else if (strpos($value, '=') !== false || strpos($value, '>') !== false || strpos($value, '<') !== false) {
- $cond[] = "$field $value";
- } else {
- $cond[] = "$field = '$value'";
- }
- }
- $cond_str = implode(" $glue ", $cond);
- if ($cond_str != '') {
- return trim("$start ($cond_str)");
+ return $aMap;
}
- return '';
- }
-
- static function update($table, &$values, $primary_key = FALSE, $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
- {
- static $non_text = array('bit', 'bigint', 'bool', 'boolean',
- 'dec', 'decimal', 'double', 'float',
- 'int', 'integer', 'mediumint', 'real',
- 'smallint', 'tinyint', 'function'
- );
-
- $row_id = FALSE;
- $oSession = Session::get_instance();
- $user_id = $oSession->user->user_id;
- $columns = array();
- $data = array();
- $query_start = '';
- $query_end = '';
- //$query_data = '';
-
- $col_result = mysql_query("SHOW COLUMNS FROM $table", DB::$link);
- if ($col_result === FALSE) {
- Corelog::log("DB:unknown table: $table: " . mysql_error(DB::$link), Corelog::ERROR);
- return FALSE;
+
+ static function where($table, $conditions, $glue = 'AND', $start = 'WHERE')
+ {
+ $aColumn = self::column_list($table);
+ $aFilter = self::column_map($aColumn, $conditions);
+
+ $cond = array();
+ foreach ($aFilter as $field => $filter) {
+ $value = $filter['value'];
+ if (is_numeric($value)) {
+ $cond[] = "$field = $value";
+ } else if (strpos($value, 'auth_filter') !== false) {
+ $cond[] = "$value";
+ } else if (strpos($value, '%') !== false) {
+ $cond[] = "$field LIKE '$value'";
+ } else if (strpos($value, '=') !== false || strpos($value, '>') !== false || strpos($value, '<') !== false) {
+ $cond[] = "$field $value";
+ } else {
+ $cond[] = "$field = '$value'";
+ }
+ }
+ $cond_str = implode(" $glue ", $cond);
+ if ($cond_str != '') {
+ return trim("$start ($cond_str)");
+ }
+ return '';
}
- // Field | Type | Null | Key | Default | Extra ==> Value
- while ($column = mysql_fetch_assoc($col_result)) {
- $column_name = $column['Field'];
-
- switch ($column_name) {
- case 'date_created':
- case 'last_updated':
- $columns[$column_name] = $column;
- $columns[$column_name]['Value'] = time();
- break;
- case 'updated_by':
- $columns[$column_name] = $column;
- $columns[$column_name]['Value'] = $user_id;
- break;
- case 'created_by':
- $columns[$column_name] = $column;
- $columns[$column_name]['Value'] = $user_id;
- if (!can_access($table . '_admin')) {
- // if no admin then prevent this field from being customized
- break;
- }
- default:
- if (array_key_exists($column_name, $values) && $values[$column_name] !== NULL) {
- // update <= or if INSERT then don't include empty values
- if ($primary_key !== FALSE || ($primary_key === FALSE && $values[$column_name] != '')) {
- $columns[$column_name] = $column;
- $columns[$column_name]['Value'] = mysql_real_escape_string($values[$column_name], DB::$link);
+
+ static function update($table, &$values, $primary_key = FALSE, $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
+ {
+ static $non_text = array('bit', 'bigint', 'bool', 'boolean',
+ 'dec', 'decimal', 'double', 'float',
+ 'int', 'integer', 'mediumint', 'real',
+ 'smallint', 'tinyint', 'function'
+ );
+
+ $row_id = FALSE;
+ $oSession = Session::get_instance();
+ $user_id = $oSession->user->user_id;
+ $columns = array();
+ $data = array();
+
+ // $col_result = mysql_query("SHOW COLUMNS FROM $table", DB::$link);
+ try {
+ $stmt = self::$pdo->query("SHOW COLUMNS FROM $table ");
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ if (!$result) {
+ return FALSE;
+ }
+
+
+ // Field | Type | Null | Key | Default | Extra ==> Value
+ foreach ($result as $column) {
+ $column_name = $column['Field'];
+
+ switch ($column_name) {
+ case 'date_created':
+ case 'last_updated':
+ $columns[$column_name] = $column;
+ $columns[$column_name]['Value'] = time();
+ break;
+ case 'updated_by':
+ $columns[$column_name] = $column;
+ $columns[$column_name]['Value'] = $user_id;
+ break;
+ case 'created_by':
+ $columns[$column_name] = $column;
+ $columns[$column_name]['Value'] = $user_id;
+ if (!can_access($table . '_admin')) {
+ // if no admin then prevent this field from being customized
+ break;
+ }
+ default:
+ if (array_key_exists($column_name, $values) && $values[$column_name] !== NULL) {
+ // update <= or if INSERT then don't include empty values
+ if ($primary_key !== FALSE || ($primary_key === FALSE && $values[$column_name] != '')) {
+ $columns[$column_name] = $column;
+ $columns[$column_name]['Value'] = $values[$column_name];
+ }
+ }
+ break;
+ }
+ }
+
+ if ($primary_key === FALSE) { // new record => INSERT
+ // this will fix a bug related to pooerly written loops
+ if (isset($values['primary_key']) && $values['primary_key'] == $values[$table . '_id']) {
+ unset($values['primary_key']);
+ unset($values[$table . '_id']);
+ }
+ unset($columns['updated_by']);
+ unset($columns['last_updated']);
+
+ if ($check_auth && $foreign_table != '') {
+ $foreign_value = $columns[$foreign_key]['Value'];
+ if (!self::auth_filter($foreign_table, $foreign_key, $foreign_value)) {
+ return FALSE;
+ }
+ }
+
+ $query_start = "INSERT INTO $table SET";
+ $query_end = '';
+ } else { // existing record => UPDATE
+ $row_id = $columns[$primary_key]['Value'];
+
+ /* // remove unchanged columns from query
+ $current_rs = mysql_query("SELECT * FROM $table_name WHERE $primary_key = $row_id", DB::$link);
+ $current_data = mysql_fetch_assoc($current_rs);
+ foreach ($columns as $col_name => $col_value) {
+ if ($col_value == $current_data[$col_name]) {
+ unset($columns[$col_name]);
+ }
+ } */
+
+ unset($columns[$primary_key]);
+ unset($columns['created_by']);
+ unset($columns['date_created']);
+
+ $query_start = "UPDATE $table SET";
+
+ if ($check_auth) {
+ if ($foreign_table == '') { // main table
+ $auth_filter = self::auth_filter($table);
+ } else { // sub table
+ $foreign_value = $columns[$foreign_key]['Value'];
+ unset($columns[$foreign_key]);
+ $auth_filter = self::auth_filter($foreign_table, $foreign_key, $foreign_value);
+ }
+ if (is_bool($auth_filter)) {
+ $auth_filter = ($auth_filter) ? 'TRUE' : 'FALSE';
+ }
+ $query_end = "WHERE $primary_key=$row_id AND $auth_filter";
+ } else {
+ $query_end = "WHERE $primary_key=$row_id";
+ }
+ }
+
+ foreach ($columns as $key => $column) {
+ $value = $column['Value'];
+ $type = strtolower(substr($column['Type'], 0, strpos($column['Type'], '(')));
+ if (in_array(trim($type), $non_text)) { // number
+ if ("$value" === '') { // don't allow empty value as number, instead replace it with NULL
+ $data[$key] = "$key=NULL";
+ } else {
+ $data[$key] = "$key=$value";
+ }
+ } else { // string
+ $data[$key] = "$key='$value'";
+ }
+ }
+ $query_data = implode($data, ', ');
+ $query_full = "$query_start $query_data $query_end";
+ try {
+ $qry_result = self::$pdo->query($query_full)->execute();
+ Corelog::log("DB:update query executed on table: $table", Corelog::DEBUG, $query_full);
+ $values['primary_key'] = self::$pdo->lastInsertId();
+ if ($primary_key === FALSE) {
+ $values[$table . '_id'] = $values['primary_key'];
+ }
+ return $qry_result;
+ } catch (\Exception $exception) {
+ Corelog::log("DB:update error table: $table error: " . $exception->getMessage(), Corelog::WARNING);
+ return FALSE;
}
- }
- break;
- }
+
+
+ } catch (\Exception $exception) {
+ Corelog::log("DB:unknown table: $table: " . $exception->getMessage(), Corelog::ERROR);
+ return FALSE;
+ }
+
+
+ }
+
+ public static function query_result($table, $query)
+ {
+ try {
+ $stmt = self::$pdo->query($query);
+ $stmt->execute();
+ $result = $stmt->fetchColumn();
+ return $result;
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
+ }
}
- if ($primary_key === FALSE) { // new record => INSERT
- // this will fix a bug related to pooerly written loops
- if (isset($values['primary_key']) && $values['primary_key'] == $values[$table . '_id']) {
- unset($values['primary_key']);
- unset($values[$table . '_id']);
- }
- unset($columns['updated_by']);
- unset($columns['last_updated']);
-
- if ($check_auth && $foreign_table != '') {
- $foreign_value = $columns[$foreign_key]['Value'];
- if (!self::auth_filter($foreign_table, $foreign_key, $foreign_value)) {
- return FALSE;
+ static function query($table, $req_query, $aValues = array(), $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
+ {
+ // echo PHP_EOL;
+ //echo $req_query." ";
+ //echo PHP_EOL;
+ // print_r($aValues);
+ //echo PHP_EOL;
+
+ $values = array();
+ foreach ($aValues as $key => $value) {
+ $values["%$key%"] = $value;
}
- }
-
- $query_start = "INSERT INTO $table SET";
- $query_end = '';
- } else { // existing record => UPDATE
- $row_id = $columns[$primary_key]['Value'];
-
- /* // remove unchanged columns from query
- $current_rs = mysql_query("SELECT * FROM $table_name WHERE $primary_key = $row_id", DB::$link);
- $current_data = mysql_fetch_assoc($current_rs);
- foreach ($columns as $col_name => $col_value) {
- if ($col_value == $current_data[$col_name]) {
- unset($columns[$col_name]);
+ if ($check_auth) {
+ if ($foreign_table == '') {
+ $values['%auth_filter%'] = self::auth_filter($table);
+ } else {
+ $values['%auth_filter%'] = self::auth_filter($foreign_table, $foreign_key, $values["%$foreign_key%"]);
+ }
+ } else {
+ $values['%auth_filter%'] = TRUE;
}
- } */
- unset($columns[$primary_key]);
- unset($columns['created_by']);
- unset($columns['date_created']);
+ // in case of Boolean following code will remove table prefix if any exist with auth_filter
+ if (is_bool($values['%auth_filter%'])) {
+ $boolStr = ($values['%auth_filter%']) ? 'TRUE' : 'FALSE';
+ $req_query = preg_replace('/(\w*\.)?\%auth_filter\%/', $boolStr, $req_query);
+ }
- $query_start = "UPDATE $table SET";
- if ($check_auth) {
- if ($foreign_table == '') { // main table
- $auth_filter = self::auth_filter($table);
- } else { // sub table
- $foreign_value = $columns[$foreign_key]['Value'];
- unset($columns[$foreign_key]);
- $auth_filter = self::auth_filter($foreign_table, $foreign_key, $foreign_value);
- }
- if (is_bool($auth_filter)) {
- $auth_filter = ($auth_filter) ? 'TRUE' : 'FALSE';
+ $final_query = str_replace(array_keys($values), array_values($values), $req_query);
+ Corelog::log("DB:query executed on table: $table", Corelog::DEBUG, $final_query);
+
+ //echo PHP_EOL.$final_query . PHP_EOL;
+
+ //return mysql_query($final_query, DB::$link);
+ try {
+ $stmt = self::$pdo->query($final_query);
+ $stmt->execute();
+ $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
+ return $result;
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
}
- $query_end = "WHERE $primary_key=$row_id AND $auth_filter";
- } else {
- $query_end = "WHERE $primary_key=$row_id";
- }
+
+
}
- foreach ($columns as $key => $column) {
- $value = $column['Value'];
- $type = strtolower(substr($column['Type'], 0, strpos($column['Type'], '(')));
- if (in_array(trim($type), $non_text)) { // number
- if ("$value" === '') { // don't allow empty value as number, instead replace it with NULL
- $data[$key] = "$key=NULL";
+
+ static function delete($table, $primary_key, $row_id, $check_auth = FALSE, $foreign_table = '', $foreign_key = '', $foreign_value = '')
+ {
+ $values = array($primary_key => $row_id);
+ Corelog::log("DB:delete requested on table: $table", Corelog::DEBUG);
+
+ if ($check_auth) {
+ $query = "DELETE FROM $table WHERE $primary_key=%$primary_key% AND %auth_filter%";
+ $values[$foreign_key] = $foreign_value;
+ return self::raw_insert_delete_update($table, $query, $values, TRUE, $foreign_table, $foreign_key);
} else {
- $data[$key] = "$key=$value";
+ $query = "DELETE FROM $table WHERE $primary_key=%$primary_key%";
+ return self::raw_insert_delete_update($table, $query, $values, FALSE);
}
- } else { // string
- $data[$key] = "$key='$value'";
- }
- }
- $query_data = implode($data, ', ');
- $query_full = "$query_start $query_data $query_end";
- $qry_result = mysql_query($query_full, DB::$link);
- Corelog::log("DB:update query executed on table: $table", Corelog::DEBUG, $query_full);
- if ($qry_result === FALSE) {
- Corelog::log("DB:update error table: $table error: " . mysql_error(DB::$link), Corelog::WARNING);
- return FALSE;
- }
- $values['primary_key'] = mysql_insert_id(DB::$link);
- if ($primary_key === FALSE) {
- $values[$table . '_id'] = $values['primary_key'];
- }
- return $qry_result;
- }
-
- public static function query_result($table, $query, $aValues = array(), $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
- {
- $result = self::query($table, $query, $aValues , $check_auth, $foreign_table, $foreign_key);
- if (is_resource($result)) {
- return mysql_result($result, 0);
- }
- return null;
- }
-
- static function query($table, $req_query, $aValues = array(), $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
- {
- $values = array();
- foreach ($aValues as $key => $value) {
- $values["%$key%"] = mysql_real_escape_string($value, DB::$link);
}
- if ($check_auth) {
- if ($foreign_table == '') {
- $values['%auth_filter%'] = self::auth_filter($table);
- } else {
- $values['%auth_filter%'] = self::auth_filter($foreign_table, $foreign_key, $values["%$foreign_key%"]);
- }
- } else {
- $values['%auth_filter%'] = TRUE;
+ static function auth_filter($table, $auth_key = 'created_by', $auth_value = FALSE)
+ {
+ if (can_access($table . '_admin')) {
+ echo " ADmin access ";
+ return TRUE;
+ } else {
+ $oSession = Session::get_instance();
+ if ($auth_key == 'created_by') { // main table
+ $auth_value = $oSession->user->user_id;
+ if (empty($auth_value)) {
+ return FALSE; // null user id is not allowed
+ }
+ } else { // sub table
+ $user_value = $oSession->user->user_id;
+ if (empty($user_value)) {
+ return FALSE; // null user id is not allowed
+ }
+ $user_key = 'created_by';
+ //Not required in pdo
+ //$auth_value = mysql_real_escape_string($auth_value, DB::$link);
+ $parent_query = "SELECT $auth_key FROM $table WHERE $auth_key=$auth_value AND $user_key=$user_value";
+
+ self::rawSelect($parent_query);
+ }
+
+ echo " Auth key vlaue:";
+ echo "$auth_key=$auth_value ";
+
+ return "$auth_key=$auth_value";
+ }
}
- // in case of Boolean following code will remove table prefix if any exist with auth_filter
- if (is_bool($values['%auth_filter%'])) {
- $boolStr = ($values['%auth_filter%']) ? 'TRUE' : 'FALSE';
- $req_query = preg_replace('/(\w*\.)?\%auth_filter\%/', $boolStr, $req_query);
+ public static function rawSelect($query)
+ {
+ try {
+ $stmt = self::$pdo->query($query);
+ $stmt->execute();
+ $result = $stmt->fetchAll();
+ return $result;
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
+ return FALSE;
+ }
+
}
- $final_query = str_replace(array_keys($values), array_values($values), $req_query);
- Corelog::log("DB:query executed on table: $table", Corelog::DEBUG, $final_query);
- return mysql_query($final_query, DB::$link);
- }
-
- static function delete($table, $primary_key, $row_id, $check_auth = FALSE, $foreign_table = '', $foreign_key = '', $foreign_value = '')
- {
- $values = array($primary_key => $row_id);
- Corelog::log("DB:delete requested on table: $table", Corelog::DEBUG);
-
- if ($check_auth) {
- $query = "DELETE FROM $table WHERE $primary_key=%$primary_key% AND %auth_filter%";
- $values[$foreign_key] = $foreign_value;
- return self::query($table, $query, $values, TRUE, $foreign_table, $foreign_key);
- } else {
- $query = "DELETE FROM $table WHERE $primary_key=%$primary_key%";
- return self::query($table, $query, $values, FALSE);
+ public static function raw_insert_delete_update($query)
+ {
+ try {
+ $stmt = self::$pdo->query($query);
+ $stmt->execute();
+ return $stmt->rowCount();
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
+ return 0;
+ }
}
- }
-
- static function auth_filter($table, $auth_key = 'created_by', $auth_value = FALSE)
- {
- if (can_access($table . '_admin')) {
- return TRUE;
- } else {
- $oSession = Session::get_instance();
- if ($auth_key == 'created_by') { // main table
- $auth_value = $oSession->user->user_id;
- if (empty($auth_value)) {
- return FALSE; // null user id is not allowed
+
+
+ static function insert_delete_update($table, $req_query, $aValues = array(), $check_auth = FALSE, $foreign_table = '', $foreign_key = '')
+ {
+ $values = array();
+ foreach ($aValues as $key => $value) {
+ $values["%$key%"] = $value;
+ }
+ if ($check_auth) {
+ if ($foreign_table == '') {
+ $values['%auth_filter%'] = self::auth_filter($table);
+ } else {
+ $values['%auth_filter%'] = self::auth_filter($foreign_table, $foreign_key, $values["%$foreign_key%"]);
+ }
+ } else {
+ $values['%auth_filter%'] = TRUE;
}
- } else { // sub table
- $user_value = $oSession->user->user_id;
- if (empty($user_value)) {
- return FALSE; // null user id is not allowed
+
+ // in case of Boolean following code will remove table prefix if any exist with auth_filter
+ if (is_bool($values['%auth_filter%'])) {
+ $boolStr = ($values['%auth_filter%']) ? 'TRUE' : 'FALSE';
+ $req_query = preg_replace('/(\w*\.)?\%auth_filter\%/', $boolStr, $req_query);
}
- $user_key = 'created_by';
- $auth_value = mysql_real_escape_string($auth_value, DB::$link);
- $parent_query = "SELECT $auth_key FROM $table WHERE $auth_key=$auth_value AND $user_key=$user_value";
- $parent_result = mysql_query($parent_query, DB::$link);
- if (mysql_num_rows($parent_result) == NULL) {
- return FALSE;
+
+
+ $final_query = str_replace(array_keys($values), array_values($values), $req_query);
+ Corelog::log("DB:query executed on table: $table", Corelog::DEBUG, $final_query);
+
+ try {
+ $stmt = self::$pdo->query($final_query);
+ $stmt->execute();
+ return $stmt->rowCount();
+ } catch (\Exception $exception) {
+ echo $exception->getMessage();
}
- }
- return "$auth_key=$auth_value";
+
}
- }
+
+
+
}
diff --git a/core/lib/Data.php b/core/lib/Data.php
old mode 100644
new mode 100755
diff --git a/core/lib/Http.php b/core/lib/Http.php
old mode 100644
new mode 100755
diff --git a/core/lib/Scheme.php b/core/lib/Scheme.php
old mode 100644
new mode 100755
diff --git a/core/lib/Scheme/Node.php b/core/lib/Scheme/Node.php
old mode 100644
new mode 100755
diff --git a/core/lib/Session.php b/core/lib/Session.php
old mode 100644
new mode 100755
index 58258f4..2ef4781
--- a/core/lib/Session.php
+++ b/core/lib/Session.php
@@ -95,13 +95,14 @@ public function read($id)
{
Corelog::log("Session read requested with id: $id", Corelog::DEBUG);
session_write_close();
- $query = "SELECT data FROM session WHERE session_id='$id'";
- if (!$result = mysql_query($query, $this->_db_link)) {
- Corelog::log("Session read failed with error: " . mysql_error($this->_db_link), Corelog::WARNING);
+ $query = "SELECT data FROM session WHERE session_id='".$id."'";
+ if (!$result = DB::rawSelect($query)) {
+ Corelog::log("Session read failed with error: ", Corelog::WARNING);
return FALSE;
}
- if (mysql_num_rows($result)) {
- $row = mysql_fetch_assoc($result);
+
+ if (count($result)) {
+ $row = $result;
$data = unserialize($row["data"]);
if ($data instanceof Data) {
$this->merge($data);
@@ -120,15 +121,15 @@ public function write($id, $data)
$data = $this;
}
$values = array(
- '%id%' => mysql_real_escape_string($id, $this->_db_link),
- '%data%' => mysql_real_escape_string(serialize($data), $this->_db_link)
+ '%id%' => $id,
+ '%data%' => serialize($data)
);
$query = "INSERT INTO session (session_id, time_start, data)
VALUES ('%id%', UNIX_TIMESTAMP(), '%data%')
ON DUPLICATE KEY UPDATE time_start=UNIX_TIMESTAMP(), data='%data%'";
$final_query = str_replace(array_keys($values), array_values($values), $query);
- mysql_query($final_query, $this->_db_link);
- if (mysql_affected_rows($this->_db_link)) {
+
+ if (DB::raw_insert_delete_update($final_query)>0) {
return TRUE;
}
Corelog::log("Session write failed", Corelog::WARNING);
@@ -138,7 +139,7 @@ public function destroy($id)
{
Corelog::log("Session delete requested with id: $id", Corelog::DEBUG);
$query = "DELETE FROM session where session_id='$id'";
- $result = mysql_query($query, $this->_db_link);
+ $result = DB::raw_insert_delete_update($query);
if ($result) {
return TRUE;
} else {
@@ -150,7 +151,7 @@ public function gc($life)
{
Corelog::log("Session gc requested with lif: $life", Corelog::DEBUG);
$query = "DELETE FROM session WHERE time_start < " . (time() - $life);
- $result = mysql_query($query, $this->_db_link);
+ $result = DB::raw_insert_delete_update($query);
if ($result) {
return TRUE;
} else {
diff --git a/core/lib/Thread/Process.php b/core/lib/Thread/Process.php
old mode 100644
new mode 100755
diff --git a/core/lib/Thread/Send.php b/core/lib/Thread/Send.php
old mode 100644
new mode 100755
diff --git a/core/lib/Thread/Task.php b/core/lib/Thread/Task.php
old mode 100644
new mode 100755
diff --git a/core/lib/Token.php b/core/lib/Token.php
old mode 100644
new mode 100755
diff --git a/core/lib/common.php b/core/lib/common.php
old mode 100644
new mode 100755
index ca64e01..099b358
--- a/core/lib/common.php
+++ b/core/lib/common.php
@@ -129,9 +129,9 @@ function do_login($user)
}
$oSession->user = $oUser;
- ICT\Core\Conf\User::load();
+ \ICT\Core\Conf\User::load();
Corelog::log("do_login, results", Corelog::DEBUG, $oSession->user);
- \ICT\Core\Conf\User::load();
+ \ICT\Core\Conf\User::load();
return $oSession->user;
}
diff --git a/core/lib/init.php b/core/lib/init.php
old mode 100644
new mode 100755
index fa44884..ffed034
--- a/core/lib/init.php
+++ b/core/lib/init.php
@@ -35,7 +35,7 @@
include_once "common.php"; // common functions
// Read database and other basic configuration from configuration file
-ConfFile::load('/etc/ictcore.conf');
+ConfFile::load($path_etc.'/ictcore.conf');
// Corelog will be our default error handler
set_error_handler(array('ICT\\Core\\Corelog', 'error_handler'), E_ALL);
diff --git a/data/document/.gitignore b/data/document/.gitignore
old mode 100644
new mode 100755
diff --git a/data/recording/.gitignore b/data/recording/.gitignore
old mode 100644
new mode 100755
diff --git a/data/template/.gitignore b/data/template/.gitignore
old mode 100644
new mode 100755
diff --git a/db/data/role_admin.sql b/db/data/role_admin.sql
index 650e15d..238d692 100755
--- a/db/data/role_admin.sql
+++ b/db/data/role_admin.sql
@@ -1,8 +1,5 @@
INSERT INTO role(name, description) VALUES ('admin', 'system administrator');
-
--- permissions for admin role
SELECT @roleId := role_id FROM role WHERE name='admin';
--- provider permissions
SELECT @permissionId := permission_id FROM permission WHERE name='api';
INSERT INTO role_permission VALUES (NULL, @roleId, @permissionId); /* api */
SELECT @permissionId := permission_id FROM permission WHERE name='statistic';
diff --git a/db/database.sql b/db/database.sql
old mode 100644
new mode 100755
index 33c9120..85e19e5
--- a/db/database.sql
+++ b/db/database.sql
@@ -384,13 +384,13 @@ CREATE TABLE configuration
/*==============================================================*/
CREATE TABLE configuration_data
(
- configuration_id int(11) default NULL,
+ configuration_id int(11) NOT NULL,
class int(11) default 1,
node_id int(11) unsigned default 0,
- campaign_id int(11) unsigned default NULL,
+ campaign_id int(11) unsigned NOT NULL,
data varchar(255) default NULL,
date_created int(11) default NULL,
- created_by int(11) default NULL,
+ created_by int(11) NOT NULL,
last_updated int(11) default NULL,
updated_by int(11) unsigned default NULL,
PRIMARY KEY (configuration_id, class, node_id, created_by, campaign_id)
@@ -604,7 +604,7 @@ DELIMITER ;
/*==============================================================*/
CREATE TABLE session
(
- session_id varchar(80) default NULL,
+ session_id varchar(80) NOT NULL,
time_start int(11) default 0,
data text,
PRIMARY KEY (session_id)
diff --git a/db/email.sql b/db/email.sql
old mode 100644
new mode 100755
index 26e539b..ff6e9a7
--- a/db/email.sql
+++ b/db/email.sql
@@ -32,7 +32,9 @@ CREATE INDEX template_created_by ON template (created_by);
/* Desc: Dumping Default System configurations */
/*==============================================================*/
-- service
-INSERT INTO configuration VALUES (NULL,'service','email_status','0',254); --ready
+INSERT INTO configuration VALUES (NULL,'service','email_status','0',254);
+
+-- ready
/*==============================================================*/
/* Table: insert email module permissions */
diff --git a/db/fax.sql b/db/fax.sql
old mode 100644
new mode 100755
index 501e0d0..008c87e
--- a/db/fax.sql
+++ b/db/fax.sql
@@ -33,8 +33,8 @@ CREATE INDEX document_created_by ON document (created_by);
/*==============================================================*/
/* Desc: Dumping Default System configurations */
/*==============================================================*/
--- service
-INSERT INTO configuration VALUES (NULL,'service','fax_status','0',254); --ready
+
+INSERT INTO configuration VALUES (NULL,'service','fax_status','0',254);
/*==============================================================*/
/* Table: insert fax module permissions */
diff --git a/db/ictfax.sql b/db/ictfax.sql
old mode 100644
new mode 100755
index 9b0d3b6..f13c8cf
--- a/db/ictfax.sql
+++ b/db/ictfax.sql
@@ -1,16 +1,12 @@
DROP TRIGGER IF EXISTS usr_insert;
-DELIMITER |
CREATE TRIGGER usr_insert AFTER INSERT
ON usr FOR EACH ROW BEGIN
INSERT INTO account (account_id, type, username, passwd, passwd_pin, first_name, last_name, phone, email, address,
active, date_created, created_by, last_updated, updated_by)
SELECT NULL, 'eaddress', NEW.username, NEW.passwd, LEFT(RAND()*999999, 4), NEW.first_name, NEW.last_name, NEW.phone,
NEW.email, NEW.address, NEW.active, NEW.date_created, NEW.usr_id, NULL, NULL;
- END |
|
CREATE TRIGGER usr_update AFTER UPDATE
ON usr FOR EACH ROW BEGIN
UPDATE account SET email = NEW.email WHERE type = 'eaddress' AND created_by = NEW.usr_id limit 1;
- END |
-DELIMITER ;
diff --git a/db/sms.sql b/db/sms.sql
old mode 100644
new mode 100755
index 35c85f2..34cfdba
--- a/db/sms.sql
+++ b/db/sms.sql
@@ -28,13 +28,11 @@ CREATE TABLE text
/*==============================================================*/
/* Desc: Dumping Default System configurations */
/*==============================================================*/
--- service
-INSERT INTO configuration VALUES (NULL,'service','sms_status','0',254); --ready
+INSERT INTO configuration VALUES (NULL,'service','sms_status','0',254);
/*==============================================================*/
/* Table: insert sms module permissions */
/*==============================================================*/
--- Text permissions
INSERT INTO permission VALUES (NULL, 'text', '');
INSERT INTO permission VALUES (NULL, 'text_create', '');
INSERT INTO permission VALUES (NULL, 'text_list', '');
diff --git a/db/update/update_0.7.0-to-0.7.1.sql b/db/update/update_0.7.0-to-0.7.1.sql
old mode 100644
new mode 100755
diff --git a/db/update/update_0.7.1-to-0.8.0.sql b/db/update/update_0.7.1-to-0.8.0.sql
old mode 100644
new mode 100755
diff --git a/db/update/update_0.8.0-to-0.8.x.sql b/db/update/update_0.8.0-to-0.8.x.sql
old mode 100644
new mode 100755
diff --git a/db/voice.sql b/db/voice.sql
old mode 100644
new mode 100755
index a16b6cd..065249b
--- a/db/voice.sql
+++ b/db/voice.sql
@@ -32,13 +32,12 @@ CREATE INDEX recording_created_by ON recording (created_by);
/*==============================================================*/
/* Desc: Dumping Default System configurations */
/*==============================================================*/
--- service
-INSERT INTO configuration VALUES (NULL,'service','voice_status','0',254); --ready
+
+INSERT INTO configuration VALUES (NULL,'service','voice_status','0',254);
/*==============================================================*/
/* Table: insert voice module permissions */
/*==============================================================*/
--- Recording permissions
INSERT INTO permission VALUES (NULL, 'recording', '');
INSERT INTO permission VALUES (NULL, 'recording_create', '');
INSERT INTO permission VALUES (NULL, 'recording_list', '');
diff --git a/docs/ApiGuide.md b/docs/ApiGuide.md
old mode 100644
new mode 100755
diff --git a/docs/api.md b/docs/api.md
old mode 100644
new mode 100755
diff --git a/docs/developer-guide/common.md b/docs/developer-guide/common.md
old mode 100644
new mode 100755
diff --git a/docs/developer-guide/introduction.md b/docs/developer-guide/introduction.md
old mode 100644
new mode 100755
diff --git a/docs/features.md b/docs/features.md
old mode 100644
new mode 100755
diff --git a/docs/intro_components.md b/docs/intro_components.md
old mode 100644
new mode 100755
diff --git a/etc/freeswitch/.gitignore b/etc/freeswitch/.gitignore
old mode 100644
new mode 100755
diff --git a/etc/freeswitch/dialplan/provider/.gitkeep b/etc/freeswitch/dialplan/provider/.gitkeep
old mode 100644
new mode 100755
diff --git a/etc/freeswitch/dialplan/user/.gitkeep b/etc/freeswitch/dialplan/user/.gitkeep
old mode 100644
new mode 100755
diff --git a/etc/freeswitch/directory/account/.gitkeep b/etc/freeswitch/directory/account/.gitkeep
old mode 100644
new mode 100755
diff --git a/etc/freeswitch/sip_profiles/provider/.gitkeep b/etc/freeswitch/sip_profiles/provider/.gitkeep
old mode 100644
new mode 100755
diff --git a/etc/http/ictcore.conf b/etc/http/ictcore.conf
old mode 100644
new mode 100755
diff --git a/etc/ictcore.conf b/etc/ictcore.conf
index 86771e5..be8c148 100755
--- a/etc/ictcore.conf
+++ b/etc/ictcore.conf
@@ -36,8 +36,8 @@ node_id = 1
[db]
host = localhost
port = 3306
-user = myuser
-pass = mypass
+user = banna
+pass = Alio@1610
name = ictcore
type = mysql
diff --git a/etc/kannel/.gitignore b/etc/kannel/.gitignore
old mode 100644
new mode 100755
diff --git a/etc/kannel/provider/.gitkeep b/etc/kannel/provider/.gitkeep
old mode 100644
new mode 100755
diff --git a/etc/postscript/rotate.ps b/etc/postscript/rotate.ps
old mode 100644
new mode 100755
diff --git a/log/.gitignore b/log/.gitignore
old mode 100644
new mode 100755
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
old mode 100644
new mode 100755
diff --git a/tests/client.php b/tests/client.php
old mode 100644
new mode 100755
diff --git a/tests/configuration.xml b/tests/configuration.xml
old mode 100644
new mode 100755
diff --git a/tests/core/ContactTest.php b/tests/core/ContactTest.php
old mode 100644
new mode 100755
diff --git a/tests/core/lib/DataTest.php b/tests/core/lib/DataTest.php
old mode 100644
new mode 100755
diff --git a/tests/core/lib/SessionTest.php b/tests/core/lib/SessionTest.php
old mode 100644
new mode 100755
diff --git a/tests/core/lib/TokenTest.php b/tests/core/lib/TokenTest.php
old mode 100644
new mode 100755
diff --git a/tests/get.php b/tests/get.php
old mode 100644
new mode 100755
diff --git a/wwwroot/gateway.php b/wwwroot/gateway.php
old mode 100644
new mode 100755