Exemplo n.º 1
0
 public function setNewServer($host, $user, $password, $database, $faild = self::EXCEPTION_FAILD_MODE)
 {
     //$this->server=null;
     //
     if ($host == "" and $user == "" and $database == "") {
         throw new DatabaseArgumentsException();
     } else {
         Database::$server = mysqli_connect($host, $user, $password, $database);
         //
         if (!Database::$server) {
             if ($faild == 2 && Config::get('panel.configured')) {
                 throw new DatabaseConnectionException();
             } else {
                 if ($faild == 1) {
                     \Errors::r_db();
                 }
             }
         }
         //
         mysqli_query(Database::$server, "SET NAMES " . Config::get("database.charset"));
         //
         Database::$serverData = ['host' => $host, "username" => $user, "password" => $password, "database" => $database];
         //
         //
         return Database::$server;
     }
 }
Exemplo n.º 2
0
 /**
  * To count rows by where clause
  *
  * @param $where (string) : the where clause
  **/
 public static function count($where)
 {
     $self = self::instance();
     $rows = new ModelArray();
     //
     $sql = "select count(*) as cnt from " . $self->DBtable . " where {$where} ";
     $data = Database::read($sql, 1);
     //
     return $data[0]['cnt'];
 }
Exemplo n.º 3
0
 public static function exec_cos()
 {
     $Root = "../";
     $r = glob("../app/schemas/*.php");
     $r2 = array();
     $r2 = array();
     foreach ($r as $value) {
         $temp1 = explode("schemas/", $value);
         $temp2 = explode("_", $temp1[1]);
         $temp3 = explode(".", $temp2[1]);
         $ex = $temp3[0];
         //
         if ($ex == $_POST['exec_cos_migrate_select']) {
             $r2[] = $ex;
             $r3[] = $temp2[0];
         }
     }
     $v = "";
     $full_name = "";
     //
     if (count($r2) > 1) {
         for ($i = 1; $i < count($r2); $i++) {
             error_log($r3[$i] . '*/*' . $r3[$i - 1]);
             if ($r3[$i] >= $r3[$i - 1]) {
                 $v = "../app/schemas/" . $r3[$i] . "_" . $r2[$i] . ".php";
                 $full_name = $r3[$i] . "_" . $r2[$i];
             }
         }
     } else {
         $v = "../app/schemas/" . $r3[0] . "_" . $r2[0] . ".php";
         $full_name = $r3[0] . "_" . $r2[0];
     }
     try {
         include_once $v;
         if (up()) {
             Migration::updateRegister($full_name, "exec", $Root);
             echo "Schéma executé";
         } else {
             echo Database::execErr();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
Exemplo n.º 4
0
 public static function run($root = "../", $routes = true, $session = true)
 {
     ob_start();
     //
     self::$root = $root;
     //
     require self::$root . 'vendor/fiesta/kernel/Logging/Handler.php';
     require self::$root . 'vendor/fiesta/kernel/Logging/Log.php';
     // Config
     require self::$root . 'vendor/fiesta/kernel/Config/Config.php';
     require self::$root . 'vendor/fiesta/kernel/Config/Exceptions/ConfigException.php';
     Config::load();
     // Set Timezone
     self::timeCall();
     // Set the error log
     Log::ini();
     // Set Whoops error handler
     Handler::run();
     //session
     require self::$root . 'vendor/fiesta/kernel/Storage/Session.php';
     if ($session) {
         Session::start(self::$root . 'app/storage/session');
     }
     //Maintenance
     require self::$root . 'vendor/fiesta/kernel/Maintenance/Maintenance.php';
     //Objects
     require self::$root . 'vendor/fiesta/kernel/Objects/Vars.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Strings/Strings.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Strings/Exceptions/StringOutIndexException.php';
     // Access
     require self::$root . 'vendor/fiesta/kernel/Access/Path.php';
     //Alias
     require self::$root . 'vendor/fiesta/kernel/Config/Alias.php';
     //
     //require self::$root.'vendor/fiesta/kernel/MVC/Templete.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Exception.php';
     require self::$root . 'vendor/fiesta/kernel/Resources/Faker.php';
     require self::$root . 'vendor/fiesta/kernel/Storage/Cookie.php';
     // Routes
     require self::$root . 'vendor/fiesta/kernel/Router/Routes.php';
     require self::$root . 'vendor/fiesta/kernel/Router/Route.php';
     require self::$root . 'vendor/fiesta/kernel/Router/Exceptions/NotFoundHttpException.php';
     // Caches
     require self::$root . 'vendor/fiesta/kernel/Caches/Caches.php';
     require self::$root . 'vendor/fiesta/kernel/Caches/Cache.php';
     require self::$root . 'vendor/fiesta/kernel/Caches/FileCache.php';
     require self::$root . 'vendor/fiesta/kernel/Caches/DatabaseCache.php';
     require self::$root . 'vendor/fiesta/kernel/Caches/Exceptions/DriverNotFoundException.php';
     require self::$root . 'vendor/fiesta/kernel/Storage/Storage.php';
     require self::$root . 'vendor/fiesta/kernel/Security/Auth.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Table.php';
     // Database
     require self::$root . 'vendor/fiesta/kernel/Database/Schema.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Migration.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Seeder.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Database.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Drivers/MySql.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Exceptions/DatabaseArgumentsException.php';
     require self::$root . 'vendor/fiesta/kernel/Database/Exceptions/DatabaseConnectionException.php';
     require self::$root . 'vendor/fiesta/kernel/Access/Url.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Sys.php';
     require self::$root . 'vendor/fiesta/kernel/Http/Links.php';
     require self::$root . 'vendor/fiesta/kernel/Http/Http.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/Base.php';
     require self::$root . 'vendor/fiesta/kernel/Resources/Libs.php';
     require self::$root . 'vendor/fiesta/kernel/Hypertext/Res.php';
     require self::$root . 'vendor/fiesta/kernel/Hypertext/Input.php';
     require self::$root . 'vendor/fiesta/kernel/Security/License.php';
     self::translatorCalls();
     self::modelsCalls();
     self::relationsCalls();
     self::mediaCalls();
     // MVC - View
     require self::$root . 'vendor/fiesta/kernel/MVC/View/View.php';
     require self::$root . 'vendor/fiesta/kernel/MVC/View/Libs/Template.php';
     require self::$root . 'vendor/fiesta/kernel/MVC/View/Libs/Views.php';
     require self::$root . 'vendor/fiesta/kernel/MVC/View/Exceptions/ViewNotFoundException.php';
     require self::$root . 'vendor/fiesta/kernel/Hypertext/HTML.php';
     require self::$root . 'vendor/fiesta/kernel/Security/Encrypt.php';
     require self::$root . 'vendor/fiesta/kernel/Security/Security.php';
     require self::$root . 'vendor/fiesta/kernel/MVC/Controller.php';
     require self::$root . 'vendor/fiesta/kernel/Http/Error.php';
     require self::$root . 'vendor/fiesta/kernel/Http/Root.php';
     require self::$root . 'vendor/fiesta/kernel/Mailing/Mail.php';
     require self::$root . 'vendor/fiesta/kernel/Objects/DataCollection.php';
     require self::$root . 'vendor/fiesta/kernel/Maintenance/Debug.php';
     // Filesystem
     require self::$root . 'vendor/fiesta/kernel/Filesystem/Exceptions/FileNotFoundException.php';
     require self::$root . 'vendor/fiesta/kernel/Filesystem/Exceptions/DirectoryNotFoundException.php';
     require self::$root . 'vendor/fiesta/kernel/Filesystem/Filesystem.php';
     // Database files
     require self::$root . 'vendor/fiesta/kernel/Database/DBTable.php';
     //
     Alias::ini(self::$root);
     Sys::ini();
     Url::ini();
     Path::ini();
     Template::run();
     Faker::ini();
     Links::ini();
     Errors::ini(self::$root);
     License::ini(self::$page);
     Lang::ini();
     Database::ini();
     Auth::ini();
     Panel::run();
     self::scoopCall();
     //
     if (self::$root != null) {
         // include models
         foreach (glob(self::$root . "app/models/*.php") as $file) {
             include_once $file;
         }
         //include the controllers files
         foreach (glob(self::$root . "app/controllers/*.php") as $file) {
             include_once $file;
         }
         //include the link files
         foreach (glob(self::$root . "app/paths/*.php") as $file) {
             include_once $file;
         }
         //include the seeders files
         foreach (glob(self::$root . "app/seeds/*.php") as $file) {
             include_once $file;
         }
         //
         //include filters
         include_once self::$root . "app/http/Filters.php";
         //include for routes
         if ($routes) {
             include_once self::$root . "app/http/Routes.php";
             Routes::run();
         }
     } else {
         // include models
         foreach (glob("app/models/*.php") as $file) {
             include_once $file;
         }
         //include the controllers files
         foreach (glob("app/controllers/*.php") as $file) {
             include_once $file;
         }
         //include the seeders files
         foreach (glob("app/seeds/*.php") as $file) {
             include_once $file;
         }
         //include filters
         include_once "app/http/Filters.php";
         //include for routes
         if ($routes) {
             include_once "app/http/Routes.php";
             Routes::run();
         }
     }
     return true;
 }
Exemplo n.º 5
0
 public static function remove($nom, $colmuns)
 {
     $name = self::tableName($nom);
     //
     self::$main_sql = "alter table " . $name . " ";
     //
     if (is_array($colmuns)) {
         // foreach ($colmuns as $value) {
         for ($i = 0; $i < count($colmuns); $i++) {
             if ($i == count($colmuns) - 1) {
                 self::$main_sql .= " drop " . $colmuns[$i];
             } else {
                 self::$main_sql .= " drop " . $colmuns[$i] . ",";
             }
         }
     } else {
         self::$main_sql .= " drop " . $colmuns;
     }
     //
     return Database::exec(self::$main_sql);
 }
Exemplo n.º 6
0
 public function getAll()
 {
     return Database::read('select * from ' . $this->DatabaseTableName());
 }
Exemplo n.º 7
0
 public static function check()
 {
     if (Session::existe('auths')) {
         return true;
     } else {
         if (Cookie::existe(Config::get('auth.rememeber_cookie'))) {
             $y = Database::countS('select * from ' . Config::get('auth.table') . ' where rememberToken="' . Cookie::get(Config::get('auth.rememeber_cookie')) . '"');
             if ($y == 1) {
                 return true;
             } else {
                 return false;
             }
         } else {
             return false;
         }
     }
 }
Exemplo n.º 8
0
 public function paginate($RowsPerPage)
 {
     // count data
     $sql = "select count(*) as nbRows from " . $this->name;
     $var = Database::read($sql);
     $this->RowsPerPage = $RowsPerPage;
     $this->nbRows = $var[0]['nbRows'];
     $this->nbPages = ceil($this->nbRows / $RowsPerPage);
     //if isset get
     $this->CurrentPage = 1;
     if (isset($_GET[Config::get('view.pagination_param')]) && !empty($_GET[Config::get('view.pagination_param')])) {
         if ($_GET[Config::get('view.pagination_param')] > 0 && $_GET[Config::get('view.pagination_param')] <= $this->nbPages) {
             $this->CurrentPage = Res::get(Config::get('view.pagination_param'));
         }
     }
     //get Data
     $r = array();
     $sql = "select * from " . $this->name . " Limit " . ($this->CurrentPage - 1) * $this->RowsPerPage . ",{$this->RowsPerPage}";
     $this->data = Database::read($sql);
     //
     return $this;
 }