public static function getMKPwd($sPWD) { if (!$sPWD) { return false; } return SELF::_getMKPwd($sPWD); }
public function excel() { $table = with(new Customer())->getTable(); $data = DB::select(DB::raw("SELECT * FROM {$table}")); $data = json_encode($data); SELF::data2excel('Excel', 'Sheet1', json_decode($data, true)); }
public function run() { session_start(); //路由 $this->route(); //链接数据库 require_once ROOT . '/../System/Class/db.class.php'; $db_config = (require_once ROOT . '/../Config/db.php'); SELF::$db = new db($db_config['db_host'], $db_config['db_user'], $db_config['db_password'], $db_config['db_name'], 'utf8'); if (file_exists(ROOT . '/../Controller/' . $this->controller_id . 'Controller.php')) { include_once ROOT . '/../Controller/' . $this->controller_id . 'Controller.php'; } else { exit(ROOT . '/../Controller/' . $this->controller_id . 'Controller.php not exists'); } //执行Controller $controller_class = $this->controller_id . 'Controller'; if (class_exists($controller_class)) { $controller_obj = new $controller_class(); if (method_exists($controller_obj, 'init')) { $controller_obj->init(); } $action_function = $this->action_id; echo $controller_obj->{$action_function}(); } else { exit($controller_class . ' not exists'); } SELF::$db->close(); }
public function __construct($id = NULL, $nom = "", $code = NULL) { SELF::$_PDO = $this->load->database('pdo', true); $this->_id = $id; $this->_nom = $nom; $this->_code = $code; }
function log($args, $tofile = false) { if (defined('WP_DEBUG') && WP_DEBUG === true) { if (isset($args)) { $log_message = '>--- ' . date('r') . ' '; if (!is_array($args)) { $log_message .= $args; } else { $count = 0; foreach ($args as $a) { if (!is_array($a)) { if (strlen($a) > 30) { $out = substr($a, 0, 30) . '...'; } else { $out = $a; } if ($count > 0) { $log_message .= ', '; } $log_message .= $out; $count += 1; } } } if ($tofile) { $log_message .= '\\n'; SELF::append_log($log_message); } else { } } } return $args; }
public static function selectBySql($sql, $att) { //clear SQL statment $conn = SELF::getConection(); $sth = $conn->prepare($sql); $sth->execute($att); if (!$sth) { //obsługa błędów zapytania do bazy $error_message = "\n" . date("d.m.y") . ", " . date("H:i:s") . ":\n Nastąpił błąd w zapytaniu do bazy: " . $e->getMessage() . ", w lini: " . __LINE__ . ", w pliku: " . __FILE__ . "\n"; error_log($error_message, 3, '_log/db_log.log'); die; exit; } else { $resultArray = $sth->fetchAll(PDO::FETCH_ASSOC); } //sprawdzenie czy wynik z bazy jest poprawny if (count($resultArray) > 0) { return $resultArray; } else { //obsługa błędów zapytania do bazy $error_message = "\n" . date("d.m.y") . ", " . date("H:i:s") . ":\n Zapytanie bazodanowe o treści: \"" . $sql . "\" o wartnościach: \"" . implode(", ", $att) . "\" zwróciło pusty wynik! W lini: " . __LINE__ . ", w pliku: " . __FILE__ . "\n"; error_log($error_message, 3, '_log/db_log.log'); die; exit; } die; exit; }
public function __construct($idActivite = null, $nomActivite = "", $descriptionActivite = "", $idTheme = null) { $this->_idActivite = $idActivite; $this->_nomActivite = $nomActivite; $this->_descriptionActivite = $descriptionActivite; $this->_idTheme = $idTheme; SELF::$_PDO = $this->load->database('pdo', true); }
public function __construct($id = NULL, $nom = "", $prenom = "", $ddn = "", $idClasse = "") { SELF::$_PDO = $this->load->database('pdo', true); $this->_id = $id; $this->_nom = $nom; $this->_prenom = $prenom; $this->_ddn = $ddn; $this->_idClasse = $idClasse; }
public function __construct($id = NULL, $nom = "", $prof = "", $niveau = "", $responsable = "") { SELF::$_PDO = $this->load->database('pdo', true); $this->_idClasse = $id; $this->_nomClasse = $nom; $this->_professeur = $prof; $this->_niveau = $niveau; $this->_profRespClasse = $responsable; }
private static function GETtoArray() { if (is_array($_GET)) { foreach ($_GET as $name => $var) { SELF::$GET[$name] = $var; } } else { SELF::$GET = NULL; } }
private static function POSTtoArray() { if (is_array($_POST)) { foreach ($_POST as $name => $var) { SELF::$POST["{$name}"] = $var; } } else { SELF::$POST = NULL; } }
private static function SESSIONtoArray() { if (is_array($_SESSION)) { foreach ($_SESSION as $name => $var) { SELF::$SESSION[$name] = $var; } } else { SELF::$SESSION = NULL; } }
/** * * @return type */ public function init() { parent::init(); $this->wtControllerPath = SimpleController::className(); if (\Yii::$app->user->isGuest) { return $this->redirect(['/user/login']); } else { SELF::_hooks(); } }
private static function LoadConfig() { $file = SELF::ReadoutConfig(); if (count($file) > 0) { foreach ($file as $line) { $line = explode("=", $line); $new_cline[$line[0]] = $line[1]; } } SELF::$config = $new_cline; }
function y() { SELF::definedInParent(); SELF::definedInParentParent(); SELF::undefined(); SELF::definedinStatic(); SELF::$pdefinedInParent; SELF::$pdefinedInParentParent; SELF::$pundefined; SELF::$pdefinedinStatic; }
public function __construct($idAgenda = null, $idActivite = null, $dateDebutActivite = "", $dateFinActivite = "", $jour = null, $horaireDebutActivite = "", $horaireFinActivite = "") { $this->_idAgenda = $idAgenda; $this->_idActivite = $idActivite; $this->_dateDebutActivite = $dateDebutActivite; $this->_dateFinActivite = $dateFinActivite; $this->_jour = $jour; $this->_horaireDebutActivite = $horaireDebutActivite; $this->_horaireFinActivite = $horaireFinActivite; SELF::$_PDO = $this->load->database('pdo', true); }
public static function connect() { if (self::$conn == null) { try { SELF::$conn = new PDO("mysql:host=" . SELF::$server . ";dbname=" . SELF::$database, SELF::$username, SELF::$password); } catch (PDOException $e) { die($e->getMessage()); } } return self::$conn; }
public function passed($passing_grade) { if (!SELF::validate($passing_grade)) { throw new Exception('Invalid Grade'); } if (!$this->grade) { return TRUE; } if (SELF::$marks[$this->grade] <= SELF::$marks[$passing_grade]) { return TRUE; } return FALSE; }
/** * @param $unit * @return string */ public static function readThaiUnit($unit) { $number_count_thai = ["ศูนย์", "หนึ่ง", "สอง", "สาม", "สี่", "ห้า", "หก", "เจ็ด", "แปด", "เก้า"]; $number = str_split("0123456789"); $exploded = explode('.', $unit); print_r($number); if (count($exploded) > 1) { $txt = SELF::readThaiNumber($exploded[0]) . 'จุด' . str_replace($number, $number_count_thai, $exploded[1]); } else { $txt = SELF::readThaiNumber($unit); } return $txt; }
public function __construct($idAdulteResponsable = NULL, $nom = "", $prenom = "", $idVille = NULL, $login = "", $motDePasse = "", $adresseMail = "", $telephone = "", $rang = NULL) { SELF::$_PDO = $this->load->database('pdo', true); $this->_idAdulteResponsable = $idAdulteResponsable; $this->_nom = $nom; $this->_prenom = $prenom; $this->_idVille = $idVille; $this->_login = $login; $this->_motDePasse = $motDePasse; $this->_adresseMail = $adresseMail; $this->_telephone = $telephone; $this->_rang = $rang; }
public function updateAction() { $data = SELF::checkItemElement(); $this->view->elements = $data["elements"]; $this->view->output = $data["output"]; $this->view->title = $data["title"]; $this->view->elementTitle = $data["elementTitle"]; $elements = $data["elements"]; $output = $data["output"]; $title = $data["title"]; if ($elements) { // echo "<pre>" . print_r($_GET,true) . "</pre>"; // echo "<pre>Elements: " . print_r($elements,true) . "</pre>"; $itemId = intval($_GET["item"]); $elementId = intval($_GET["element"]); $order = json_decode($_GET["reorderElementTextsOrder"]); // echo "<pre>Order: " . print_r($order,true) . "</pre>"; if (count($order) != count($elements)) { $returnLink = "<a href='javascript:window.history.back();'>" . __("Please return to the referring page.") . "</a>"; $output .= __("Mismatching number of elements.") . " " . $returnLink; } else { $index = array(); foreach ($elements as $idx => $element) { $index[$element["id"]] = $idx; } // echo "<pre>Index: " . print_r($index,true) . "</pre>"; $newOrder = array(); foreach ($order as $txt) { $newOrder[] = array("text" => $elements[$index[$txt]]["text"], "html" => $elements[$index[$txt]]["html"]); } // echo "<pre>NewOrder: " . print_r($newOrder,true) . "</pre>"; $db = get_db(); $success = true; # Init -- nothing done yet, so sucess ;-) foreach ($elements as $idx => $element) { $sql = "UPDATE {$db->ElementTexts}" . " SET text='" . addslashes($newOrder[$idx]["text"]) . "'," . " html=" . $newOrder[$idx]["html"] . " WHERE id=" . $element["id"]; $locSuccess = $db->query($sql); $success = ($success and $locSuccess); } if ($success) { $this->_helper->flashMessenger(__('Reordering successful.'), 'success'); } else { $this->_helper->flashMessenger(__('Reordering failed.'), 'error'); } $this->_helper->redirector($itemId, 'show', 'items'); update_item($itemId); } } }
/** * */ public static function getBlockedDate($arrLocation) { //query to read all the block dates for the locations $queryResult = SELF::whereIn('product_vendor_location_id', $arrLocation)->select('id', 'product_vendor_location_id', 'block_date')->get(); //array to store the block dates $arrBlockedDate = array(); foreach ($queryResult as $row) { if (!array_key_exists($row->vendor_location_id, $arrBlockedDate)) { $arrBlockedDate[$row->vendor_location_id] = array($row->block_date); } else { $arrBlockedDate[$row->vendor_location_id][] = $row->block_date; } } return $arrBlockedDate; }
/** * Sends a magic packet to the specified IP/MAC address using the specified * address protocol. * @param string $ip The broadcast IP address to use * @param string $mac The MAC address of the device to wake * @param int $protocol The type of IP to use. Deafult AF_INET * @return int|bool The result of sending the packet */ public static function wake($ip, $mac, $protocol = AF_INET) { if (empty($ip) || empty($mac)) { throw new \Exception('Broadcast IP address and MAC address required.'); } if (!in_array($protocol, array(AF_INET, AF_INET6, AF_UNIX))) { throw new \Exception('Invalid protocol.'); } $socket = socket_create($protocol, SOCK_DGRAM, SOL_UDP); if ($socket && is_resource($socket)) { if (!socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => $timeout, 'usec' => 0))) { throw new \Exception('Unable to set options on socket: ' . socket_strerror(socket_last_error()) . PHP_EOL); } $packet = SELF::generateMagicPacket(); $result = socket_sendto($socket, $packet, strlen($packet), 0, $ip, 7); socket_close($socket); return $result; } else { throw new \Exception('Connection failed: ' . socket_strerror(socket_last_error()) . PHP_EOL); } }
/** * Affiche les messages d'un membre à partir de la liste de ses messages. * Est utilisé avec SELF::getMessagesMembre() et est comparable à * SELF::afficherMessage(), n'ayant que de petites différences. * * @param $arrayMessages - un array de messages à afficher. */ function afficherMessagesMembre($arrayMessages) { foreach ($arrayMessages as $message) { echo '<fieldset>'; echo '<legend>' . SELF::getAuteurMessage($message) . ' - ' . SELF::getNomForum($message->getIdForum()) . '</legend>'; echo '<p>' . $message->getTexte() . '</p>'; echo '<p>'; echo '<a href="index.php?module=membres&action=afficher_messages&id=' . $message->getIdForum() . '#' . $message->getId() . '" class="repondre">Aller au message</a> '; echo $message->getHoroDate() . '</p>'; echo '</fieldset>'; } }
/** * Take a valid yyyy / yyyy-m / yyyy-mm / yyyy-m-d / yyyy-mm-d / yyyy-mm-dd * and transform it towards a left edge of possibly yyyy-01-01 or yyyy-12-31 * or at least add leading zeros, as in yyyy-0m-0d * * @param string $date to be updated * @param int edge -- -1 -> left edge (-01-01) / +1 -> right edge (-12-31) * @result string $date -- transformed towards edge and with leading zeros */ protected function _updateDate($date, $edge) { $result = $date; $regEx = SELF::_constructRegEx(); $year = $regEx["year"]; $month = $regEx["month"]; $day = $regEx["day"]; $yearOnly = "^{$year}\$"; $yearMonth = "^{$year}-{$month}\$"; $yearMonthDay = "^{$year}-{$month}-{$day}\$"; if (preg_match("({$yearOnly})", $result)) { $result = $result . "-" . ($edge < 0 ? "1" : "12"); } if (preg_match("({$yearMonth})", $result)) { $result = $result . "-" . ($edge < 0 ? "1" : "31"); } if (preg_match("({$yearMonthDay})", $result)) { $oneDigit = "\\b(\\d)\\b"; $result = preg_replace("({$oneDigit})", '0${0}', $result); } return $result; }
/** * Создает массив из XML объекта * @param mixed $xmlObject XML объект - результат функции simplexml_load_string(), например * @return array */ public static function XmlToArray($xmlObject) { $out = array(); foreach ((array) $xmlObject as $index => $node) { if (empty($node) and is_object($node) || is_array($node)) { $node = ''; } if (is_object($node) || is_array($node)) { $out[$index] = SELF::xmlToArray($node); } else { $out[$index] = $node; } } return $out; }
/** * Transform a (valid) number xxxx-pp-qq into a numer ranger-- down to xxxx-00-00 to yyyy-99-99 * * @param string $range as in single number or range * @result array [0] => left edge, [1] => right edge */ private function _expandNumberRange($range) { $result = $range; #echo "<pre>_expandNumberRange:\n" . print_r($range,true) . "</pre>"; if (!is_array($result)) { $result = array($result, $result); } $result[0] = SELF::_updateRange($result[0], -1); # -1 == left edge, xxxxxxxxxx-00-00 $result[1] = SELF::_updateRange($result[1], +1); # +1 == right edge, xxxxxxxxxx-99-99 return $result; }
public function recipesPdf($offset = 0, $limit = 1) { $table = with(new Recipe())->getTable(); $recipes = DB::select(DB::raw("SELECT * FROM {$table} ORDER BY category, name LIMIT {$offset}, {$limit}")); $view = view('reports.recipes')->with('recipes', $recipes); $contents = $view->render(); SELF::html2pdf($contents); }
/** * Execute the console command. * * @return mixed */ public function handle() { /** * Argument */ $model = $this->argument('file'); $tableModel = str_plural(snake_case($model)); $this->info($tableModel); /** * Models, by default in Laravel 5.1, are located in the app folder. * In this project a folder called Models has been created under app. * This is defined in the .env file. * * MODELS=app/Models/ */ $pathModels = env('MODELS'); if ($pathModels == '') { $pathModels = 'app/'; } /** * php wordwrap width */ $width = 120; // Path to database migration files $path = "database/migrations/"; $files = scandir($path); $files = SELF::filesOnly($files); // Looking for a single model? if ($tableModel) { $str = ''; foreach ($files as $file) { if (strpos($file, $tableModel)) { $str = $file; } } $files = [$str]; } // Fill if ($this->option('fill')) { $this->info('Fill ...'); $models = array(); foreach ($files as $file) { if (file_exists($path . $file)) { // Get contents of this database migration file $contents = file_get_contents($path . $file); #echo $contents; // Get database table name if (preg_match('/Schema::.*?\\{(.*?)\\}\\)\\;/is', $contents, $match)) { $str = $match[1]; } #echo $str; // Get all column names from table if (preg_match_all('/table.*?\\([\'](.*?)[\']/', $str, $matches)) { $s = "protected \$fillable = [\n"; for ($i = 0; $i < sizeof($matches[1]); $i++) { $s .= "\t\t'" . $matches[1][$i] . "',\n"; } $s .= "\t];"; $s = preg_replace("/'id',\n\t\t/", '', $s); $s = wordwrap($s, $width); $this->line($s); } $model = preg_replace('/^.*?create_(.*?)_table.*/', "\$1", $file); $model = str_singular($model); #$this->line($model); $models[] = $model; $fileName = $pathModels . ucfirst($model . '.php'); #echo $fileName; if (file_exists($fileName)) { #$this->info('file exists'); // Get contents of model file $text = file_get_contents($fileName); #$this->line($contents); // Replace fillable section with new string if (preg_match('/(protected \\$fillable.*?;)/s', $text, $match)) { $text = preg_replace('/(protected \\$fillable.*?;)/s', $s, $text); } file_put_contents($fileName, $text); #$this->line($text); #$this->line($model); } } } } // Cast if ($this->option('cast')) { $this->info('Cast ...'); // Unset these data types $unset = array('increments', 'date', 'datetime', 'enum', 'string', 'text', 'timestamp'); // Loop through each data migrations file foreach ($files as $file) { if (file_exists($path . $file)) { // Get model name $model = preg_replace('/^.*?create_(.*?)_table.*/', "\$1", $file); // Singular $model = preg_replace('/ies$/', "y", $model); $model = preg_replace('/s$/', "", $model); $types = array(); $vars = array(); // Get contents of database migration file $contents = file_get_contents($path . $file); // Get substring containing variable type and variable name if (preg_match_all("/table->(.*?)\\'\\)/", $contents, $match)) { for ($i = 0; $i < sizeof($match[1]); $i++) { $s = $match[1][$i]; // Get variable type and variable name if (preg_match('/(.*?)\\(\'(.*)/', $s, $match2)) { if (!in_array($match2[1], $unset)) { $types[] = $match2[1]; $vars[] = $match2[2]; } } } } // Build string for casting each variable name and type $s = ''; for ($i = 0; $i < sizeof($types); $i++) { $s .= "\t\t'" . $vars[$i] . "' => '" . $types[$i] . "',\n"; } // Get model file name $fileName = $pathModels . $model . ".php"; if (file_exists($fileName)) { $text = file_get_contents($fileName); // Create casting list if (preg_match('/protected \\$casts = \\[(.*?)\\];/is', $text)) { if (strlen($s) > 0) { $text = preg_replace('/protected \\$casts = \\[(.*?)\\];/is', "protected \$casts = [\n{$s}\t];", $text); } file_put_contents($fileName, $text); #$this->line($text); #$this->line($model); } } } } } }
public static function GetByUserID($userid) { return SELF::where('usrid', '=', $userid); }