Ejemplo n.º 1
0
Archivo: lib.php Proyecto: lursu/morgue
 static function perform($terms)
 {
     $terms = Search::split_terms($terms);
     $terms_db = Search::db_escape_terms($terms);
     $terms_rx = Search::rx_escape_terms($terms);
     $parts = array();
     foreach ($terms_db as $term_db) {
         array_push($parts, "(summary RLIKE '{$term_db}' OR title RLIKE '{$term_db}')");
     }
     $parts = implode(' AND ', $parts);
     $conn = Persistence::get_database_object();
     $sql = "SELECT id, title, summary, created  FROM postmortems WHERE {$parts}";
     $rows = array();
     $stmt = $conn->prepare($sql);
     $stmt->execute();
     $timezone = getUserTimezone();
     $tz = new DateTimeZone($timezone);
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $row['score'] = 0;
         $row['created'] = new DateTime("@{$row['created']}");
         $row['created']->setTimezone($tz);
         $row['created'] = $row['created']->format('m/d/Y G:ia');
         foreach ($terms_rx as $term_rx) {
             $row['score'] += preg_match_all("/{$term_rx}/i", $row['summary'], $null);
             $row['score'] += preg_match_all("/{$term_rx}/i", $row['title'], $null);
         }
         $rows[] = $row;
     }
     uasort($rows, 'Search::sort_results');
     $conn = null;
     return $rows;
 }
Ejemplo n.º 2
0
        echo "Mail sent!";
    } else {
        echo "Error sending mail";
    }
    return;
});
$app->get("/calendar/facilitators/add/:id", function ($id) use($app) {
    $config = Configuration::get_configuration('calendar');
    if (!$config["facilitator"]) {
        return;
    }
    $user = MorgueAuth::get_auth_data();
    $facilitator = array();
    $facilitator['name'] = $user['username'];
    $facilitator['email'] = Contact::get_email_for_user($user['username']);
    $conn = Persistence::get_database_object();
    $error = Calendar::set_facilitator($id, $facilitator, $conn);
    if (!$error) {
        $userHtml = Contact::get_html_for_user($user['username']);
        $to = implode(", ", $config["facilitators_email"]);
        $from = "Morgue <*****@*****.**>";
        $subject = "Facilitator needed [PM-{$id}]";
        $message = '
            <html>
            <head>
              <title>Facilitator Needed for PM-' . $id . '</title>
            </head>
            <body style="font-family: \'Helvetica Neue\', Helvetica,Arial, sans-serif;">
              <h3>' . $userHtml . ' will facilitate this post-mortem!</h3>
            </body>
            </html>';
Ejemplo n.º 3
0
 /**
  * function to get all history records for a postmortem
  *
  * @param $event_id - ID of the postmortem
  * @param $conn - PDO connection object
  *
  * @returns array - Array containing an entry for each
  * associated history record
  */
 static function get_history($event_id, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     if (is_null($conn)) {
         return array("status" => self::ERROR, "error" => "Couldn't get connection object.");
     }
     $sql = "SELECT * FROM postmortem_history WHERE postmortem_id=:pid";
     $stmt = $conn->prepare($sql);
     $stmt->execute(array("pid" => $event_id));
     return $stmt->fetchAll();
 }
Ejemplo n.º 4
0
 /**
  * Get a postmortem from the database
  *
  * @param $postmortem_id - id of the postmortem to get
  * @param $conn          - PDO connection object, will be newly instantiated when
  *                         null (default: null)
  *
  * @returns a postmortem map including an "id" field on success or a map of the
  * form ( "id" => null, "error" => "an error message" ) on failure
  */
 static function get_postmortem($postmortem_id, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     try {
         $sql = "SELECT id, title, summary, why_surprised, starttime, endtime, statustime,\n                    detecttime,severity, contact, gcal, created, modified, modifier, deleted \n                    FROM postmortems WHERE id = :id LIMIT 1";
         $stmt = $conn->prepare($sql);
         $stmt->execute(array('id' => $postmortem_id));
         $postmortem = $stmt->fetch(PDO::FETCH_ASSOC);
         return $postmortem;
     } catch (PDOException $e) {
         return array("id" => null, "error" => $e->getMessage());
     }
 }
Ejemplo n.º 5
0
Archivo: lib.php Proyecto: lursu/morgue
 /**
  * function to UNdelete a channel from the association table
  *
  * @param $id - ID to delete
  * @param $conn - PDO connection object (default: null)
  *
  * @returns ( "status" => self::OK ) on success
  * or ( "status" => self::ERROR, "error" => "an error message" ) on failure
  */
 static function undelete_channel($theid, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     $table_name = 'irc';
     if (is_null($conn)) {
         return array("status" => self::ERROR, "error" => "Couldn't get connection object.");
     }
     return Persistence::flag_as_undeleted($table_name, 'postmortem_id', $theid, $conn);
 }
Ejemplo n.º 6
0
 /**
  * function to get all data from specific history event
  * @param $id - ID of the postmortem_history row
  * @param $conn - PDO connection object
  *
  * @returns array - Array containing all data for specificed history record
  */
 static function get_history_event($id, $conn = null)
 {
     $conn = $conn ?: Persistence::get_database_object();
     if (is_null($conn)) {
         return array("status" => self::ERROR, "error" => "Couldn't get connection object.");
     }
     try {
         $sql = "SELECT * FROM postmortem_history WHERE id=:id";
         $stmt = $conn->prepare($sql);
         $stmt->execute(array("id" => $id));
         $history = $stmt->fetch(PDO::FETCH_ASSOC);
         $history["status"] = self::OK;
         return $history;
     } catch (PDOException $e) {
         return array("status" => self::ERROR, "error" => $e->getMessage());
     }
 }