コード例 #1
0
ファイル: Login.php プロジェクト: mts7/mtsapps-framework
 /**
  * Add an entry to the login tracking table.
  *
  * @param int $user_id
  * @param int $success
  * @param string $message
  * @return bool|mixed
  */
 public function add($user_id = 0, $success = 0, $message = '')
 {
     $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION);
     // input validation
     if (!Helpers::is_valid_int($user_id, true)) {
         $this->Log->write('user_id is not a valid integer', Log::LOG_LEVEL_WARNING);
         return false;
     }
     if (!Helpers::is_valid_int($success, true)) {
         $this->Log->write('success is not a valid integer', Log::LOG_LEVEL_WARNING);
         return false;
     }
     if (!in_array($success, array(0, 1))) {
         $this->Log->write('success is not 0 or 1', Log::LOG_LEVEL_WARNING, $success);
         return false;
     }
     if (!is_string($message)) {
         $message = Helpers::get_string($message);
     }
     // get values from PHP
     $ip_address = $_SERVER['REMOTE_ADDR'];
     $user_agent = $_SERVER['HTTP_USER_AGENT'];
     $session_id = session_id();
     if (!Helpers::is_string_ne($session_id)) {
         session_start();
         $session_id = session_id();
     }
     // prepare values for insert
     $pairs = array('user_id' => $user_id, 'ip_address' => $ip_address, 'user_agent' => $user_agent, 'success' => $success, 'session_id' => $session_id, 'message' => $message);
     $insert_id = $this->insert($this->table, $pairs);
     $this->Log->write('insert_id', Log::LOG_LEVEL_USER, $insert_id);
     return $insert_id;
 }
コード例 #2
0
ファイル: Upload.php プロジェクト: mts7/mtsapps-framework
 /**
  * Return error message, based on upload error status.
  *
  * @param int $error
  * @return bool|string
  */
 private function handleError($error)
 {
     $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION);
     if (!Helpers::is_valid_int($error, true)) {
         $this->Log->write('Cannot handle an error that is not a positive integer.', Log::LOG_LEVEL_WARNING);
         return false;
     }
     switch ($error) {
         case UPLOAD_ERR_INI_SIZE:
             $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini.';
             break;
         case UPLOAD_ERR_FORM_SIZE:
             $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';
             break;
         case UPLOAD_ERR_PARTIAL:
             $message = 'The uploaded file was only partially uploaded.';
             break;
         case UPLOAD_ERR_NO_FILE:
             $message = 'No file was uploaded.';
             break;
         case UPLOAD_ERR_NO_TMP_DIR:
             $message = 'Missing a temporary folder.';
             break;
         case UPLOAD_ERR_CANT_WRITE:
             $message = 'Failed to write file to disk.';
             break;
         case UPLOAD_ERR_EXTENSION:
             $message = 'A PHP extension stopped the file upload.';
             break;
         default:
             $message = 'Unknown upload error (' . Helpers::get_string($error) . ')';
             break;
     }
     $this->Log->write('Error: ' . $message, Log::LOG_LEVEL_ERROR);
     return $message;
 }
コード例 #3
0
ファイル: User.php プロジェクト: mts7/mtsapps-framework
 /**
  * Save the password in the database.
  *
  * @param string $password
  * @return bool|mixed
  */
 private function savePassword($password = '')
 {
     $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION);
     // input validation
     if (!Helpers::is_string_ne($password)) {
         $this->Log->write('password must be provided', Log::LOG_LEVEL_WARNING);
         return false;
     }
     $pairs = array('password' => $password);
     $updated = $this->update($this->table, $pairs, array($this->id_field => $this->id));
     $this->Log->write('password saved', Log::LOG_LEVEL_USER, Helpers::get_string($updated));
     return $updated;
 }
コード例 #4
0
ファイル: Log.php プロジェクト: mts7/mtsapps-framework
 /**
  * Write the message to the log file if the log level is appropriate.
  *
  * @param string $message
  * @param int $log_level
  * @return bool|int
  * @uses Log::$log_level
  * @uses Log::$file
  * @uses Log::$date_format
  * @uses Log::$separator
  * @uses get_string()
  */
 public function write($message = '', $log_level = Log::LOG_LEVEL_SYSTEM_INFORMATION)
 {
     // input validation
     if (!Helpers::is_string_ne($message)) {
         return false;
     }
     if (func_num_args() === 3) {
         $value = func_get_arg(2);
         // check for value and convert it to a string for writing
         if (isset($value)) {
             // convert $value to string
             $value = Helpers::get_string($value);
             // remove HTML line breaks from log message
             $value = str_replace(array("<br />\n", '<br />', '&nbsp;'), array("\n", "\n", ' '), $value);
             $message = $message . ': ' . $value;
         }
     }
     if ($this->log_level <= $log_level && Helpers::is_string_ne($this->file)) {
         // get call string from backtrace
         $call_string = Helpers::get_call_string();
         // build the message
         $message = date($this->date_format) . $this->separator . $call_string . $this->separator . $message;
         $this->messages[] = $message;
         // write the message to the provided log file
         //return file_put_contents($this->log_directory . $this->file, $message . PHP_EOL, FILE_APPEND);
         return fwrite($this->handle, $message . PHP_EOL);
     }
     return true;
 }
コード例 #5
0
 /**
  * Insert values into to table.
  *
  * @param string $table
  * @return bool|string
  * @uses DatabaseMap::$to_values
  * @uses Db::buildInsert()
  * @uses Db::begin()
  * @uses Db::query()
  * @uses Db::commit()
  */
 private function insertValues($table = '')
 {
     $this->Log->write(__METHOD__, Log::LOG_LEVEL_SYSTEM_INFORMATION);
     // input validation
     if (!Helpers::is_string_ne($table) || !Helpers::is_array_ne($this->to_values[$table])) {
         $this->Log->write('table is invalid or to values does not contain table ' . $table, Log::LOG_LEVEL_WARNING);
         return false;
     }
     // get values for table
     $values = $this->to_values[$table];
     // build insert query and parameters
     $result = $this->buildInsert($table, $values, true, true);
     if ($result === false) {
         $this->Log->write('could not build insert for ' . $table, Log::LOG_LEVEL_WARNING);
         return false;
     }
     list($sql, $parameters) = $result;
     $this->Log->write('trying insert query in transaction', Log::LOG_LEVEL_USER);
     $this->begin();
     $this->query($sql, $parameters, 'insert');
     if ($this->debug) {
         $this->Log->write('rolling back transaction due to debug', Log::LOG_LEVEL_USER);
         $this->rollback();
         $output = $sql . PHP_EOL . Helpers::get_string($parameters);
     } else {
         $this->Log->write('committing transaction', Log::LOG_LEVEL_USER);
         $this->commit();
         $output = true;
     }
     return $output;
 }
コード例 #6
0
ファイル: PdfMerge.php プロジェクト: mts7/mtsapps-framework
 /**
  * Set and/or get the creator.
  *
  * [@param] string|array|mixed $creator
  * @return string
  */
 public function creator()
 {
     $args = func_get_args();
     if (Helpers::is_array_ne($args)) {
         if (Helpers::is_string_ne($args[0])) {
             $this->creator = $args[0];
         } elseif (Helpers::is_array_ne($args[0])) {
             $this->creator = implode(', ', $args[0]);
         } else {
             $this->creator = Helpers::get_string($args[0]);
         }
     }
     return $this->creator;
 }