diff --git a/README.md b/README.md index e8f3661..16d626c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Alert classification is a complicated task, but with Opsweekly a few simple ques * A webserver * PHP 5.4 (or higher), including the curl extensions for PHP, MySQL extension, and short_open_tags enabled * MySQL for data storage - +* PHPMarkdown PEAR package ## Installation/configuration 1. Download/clone the repo into an appropriate folder either in your @@ -173,6 +173,15 @@ The `$sleep_providers` array handles the definition and configuring of the plugi * `lib`: The path to the PHP file that contains your provider code, e.g. `providers/sleep/up.php` * You are also allowed to pass any other arbritray key/value pairs in. As the entire config array is passed to the plugin, you can retrieve any values that are applicable to Opsweekly as a whole, rather than per user (which are specified above) +### Editor configuration +In this section you can define and configure additional editors. To add an editor, first copy `editors/example.php` and implement both the `printEditor` and `formatEntry` methods. Next, add your editor to this array. + +The `$editors` array tells the app what editors are available. The following values are required for each entry: + +* `name`: A friendly display name for this editor. +* `description`: A description of this editor. +* `class`: The class name that implements this editor. +* `lib`: The path to the PHP file that contains the code for this editor. ### Generic configuration There are a few other configuration options, which are documented in the example config file. Some highlights include: diff --git a/add.php b/add.php index d8bb822..b9f3968 100644 --- a/add.php +++ b/add.php @@ -16,8 +16,9 @@ $page_title = getTeamName() . " Weekly Updates - Add new update"; include_once('phplib/header.php'); -include_once('phplib/nav.php') +include_once('phplib/nav.php'); +$editor = getEditorByUser($my_username, $_GET['editor']); ?>
@@ -70,12 +71,12 @@ ?>
- - + + printEditor(); ?> + +
diff --git a/add_generic_weekly.php b/add_generic_weekly.php index 732f04b..cce7371 100644 --- a/add_generic_weekly.php +++ b/add_generic_weekly.php @@ -12,7 +12,8 @@ $report_id = generateWeeklyReportID($username, $range_start, $range_end); $state = "final"; $report = mysql_real_escape_string($_POST['weeklyupdate']); - $query = "INSERT INTO generic_weekly (report_id, range_start, range_end, timestamp, user, state, report) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$state', '$report')"; + $report_type = mysql_real_escape_string($_POST['editor']); + $query = "INSERT INTO generic_weekly (report_id, range_start, range_end, timestamp, user, state, report, report_type) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$state', '$report', '$report_type')"; if (!mysql_query($query)) { echo "Database update failed, error: " . mysql_error(); } else { diff --git a/add_meeting_notes.php b/add_meeting_notes.php index 7844bd2..f4aeef0 100644 --- a/add_meeting_notes.php +++ b/add_meeting_notes.php @@ -11,7 +11,8 @@ $range_end = mysql_real_escape_string($_POST['range_end']); $report_id = generateMeetingNotesID($range_start, $range_end); $notes = mysql_real_escape_string($_POST['weeklynotes']); - $query = "INSERT INTO meeting_notes (report_id, range_start, range_end, timestamp, user, notes) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$notes')"; + $notes_type = mysql_real_escape_string($_POST['editor']); + $query = "INSERT INTO meeting_notes (report_id, range_start, range_end, timestamp, user, notes, notes_type) VALUES ('$report_id', '$range_start', '$range_end', '$timestamp', '$username', '$notes', '$notes_type')"; if (!mysql_query($query)) { echo "Database update failed, error: " . mysql_error(); } else { diff --git a/assets/editors.js b/assets/editors.js new file mode 100644 index 0000000..95fcc5d --- /dev/null +++ b/assets/editors.js @@ -0,0 +1,17 @@ +$(function() { + var unsaved_changes = false; + + $('textarea').on('change', function() { + unsaved_changes = true; + }); + + $('button[type=submit]').on('click', function() { + unsaved_changes = false; + }); + + window.onbeforeunload = function() { + if (unsaved_changes) { + return "You have unsaved changes"; + } + }; +}); diff --git a/edit_profile.php b/edit_profile.php index 54158d9..7d2e225 100644 --- a/edit_profile.php +++ b/edit_profile.php @@ -46,6 +46,7 @@
+
Sleep Tracking
+
+
+ Editor + $e_config) { + $checked = ($profile['editor'] == $editor_key) ? " checked" : ""; + echo '"; + } + ?> +
+
diff --git a/editors/editor.php b/editors/editor.php new file mode 100644 index 0000000..793bd20 --- /dev/null +++ b/editors/editor.php @@ -0,0 +1,8 @@ +$('.textarea').wysihtml5({'image': false, 'color': false});"; + } + public function formatEntry($data) { + return $data; + } +} diff --git a/index.php b/index.php index 76d37d6..0ae0eac 100644 --- a/index.php +++ b/index.php @@ -2,7 +2,6 @@ include_once("phplib/base.php"); - $time_requested = getOrSetRequestedDate(); $start_end = getWeekRange($time_requested); diff --git a/meeting.php b/meeting.php index cc5aa2b..7535016 100644 --- a/meeting.php +++ b/meeting.php @@ -27,6 +27,8 @@ $page_title = getTeamName() . " Weekly Updates - Meeting View"; include_once('phplib/header.php'); include_once('phplib/nav.php'); + +$editor = getEditorByUser($my_username, $_GET['editor']); ?> + + printEditor() ?> + + diff --git a/opsweekly.sql b/opsweekly.sql index 1cbd415..424acda 100644 --- a/opsweekly.sql +++ b/opsweekly.sql @@ -9,6 +9,7 @@ CREATE TABLE `oncall_weekly` ( `state` varchar(20) NOT NULL, `contact` varchar(255) NOT NULL, `output` text NOT NULL, + `output_type` varchar(255) NOT NULL, `tag` varchar(255), `sleep_state` int(1) signed, `mtts` int(5) signed, @@ -28,6 +29,7 @@ CREATE TABLE `generic_weekly` ( `user` varchar(255) NOT NULL, `state` varchar(255) NOT NULL, `report` text NOT NULL, + `report_type` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `report_name` (`report_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -40,6 +42,7 @@ CREATE TABLE `meeting_notes` ( `timestamp` int(10) unsigned NOT NULL, `user` varchar(255) NOT NULL, `notes` text NOT NULL, + `notes_type` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `report_name` (`report_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -50,6 +53,7 @@ CREATE TABLE `user_profile` ( `timezone` varchar(10) NOT NULL, `sleeptracking_provider` varchar(255) NOT NULL, `sleeptracking_settings` text NOT NULL, + `editor` varchar(255) NOT NULL, PRIMARY KEY (`ldap_username`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/phplib/base.php b/phplib/base.php index 349efb9..3a5d2ae 100644 --- a/phplib/base.php +++ b/phplib/base.php @@ -237,6 +237,34 @@ function printHeaderNav() { } } +function getEditor($editor_name) { + global $editors; + $editor_name = array_key_exists($editor_name, $editors) ? $editor_name:array_keys($editors)[0]; + + include_once($editors[$editor_name]['lib']); + return new $editors[$editor_name]['class'](); +} + +function getEditorNameByUser($username) { + $editor_name = ''; + $username = mysql_real_escape_string($username); + if (connectToDB()) { + $results = mysql_query("SELECT editor FROM user_profile where ldap_username='{$username}' LIMIT 1"); + if (mysql_num_rows($results) == 1) { + $editor_name = mysql_fetch_assoc($results)['editor']; + } + } + + return $editor_name; +} + +function getEditorByUser($username, $editor_name=null) { + if (is_null($editor_name)) { + $editor_name = getEditorNameByUser($username); + } + return getEditor($editor_name); +} + function getGenericWeeklyReportsForWeek($range_start, $range_end) { connectToDB(); $query = "SELECT * FROM generic_weekly WHERE id IN (SELECT max(id) FROM generic_weekly where range_start='{$range_start}' AND range_end='{$range_end}' GROUP BY(user)) ORDER BY user ASC;"; @@ -481,22 +509,41 @@ function formatOnCallRowForPrint(array $n) { } function formatWeeklyReportForPrint(array $data) { + $editor = getEditor($data['report_type']); + $content = $editor->formatEntry($data['report']); $pretty_time = getPrettyTime($data['timestamp']); $html = "

{$data['user']} written {$pretty_time}

"; - $html .= "

{$data['report']}

"; + $html .= "

{$content}

"; return $html; } function formatMeetingNotesForPrint(array $data, $small_header = false) { + $editor = getEditor($data['notes_type']); + $content = $editor->formatEntry($data['notes']); $html = ($small_header) ? "

Notes " : "

Meeting Notes "; $html .= "taken by {$data['user']} at the " . getTeamName() ." Meeting held on " . date("l jS F Y", $data['timestamp']); $html .= ($small_header) ? "

" : ""; - $html .= "
{$data['notes']}
"; + $html .= "
{$content}
"; return $html; } +function printEditorsList() { + global $editors; + + echo '
'; + echo ''; + echo 'Editor '; + echo ''; + echo ''; + echo '
'; +} + function printWeeklyHints($username, $from, $to) { $wanted_hints = getTeamConfig('weekly_hints'); diff --git a/phplib/config.php.example b/phplib/config.php.example index 88cd405..dbe9856 100644 --- a/phplib/config.php.example +++ b/phplib/config.php.example @@ -246,6 +246,24 @@ $sleep_providers = array( "graphite_host" => "http://graphite.mycompany.com") ); +/** + * Editors + */ +$editors = array( + 'wysiwyg' => array( + "name" => "WYSIWYG", + "description" => "You get what you see!", + "class" => "WYSIWYGEditor", + "lib" => "editors/wysiwygeditor.php" + ), + 'markdown' => array( + "name" => "Markdown", + "description" => "Less markup with markdown", + "class" => "MarkdownEditor", + "lib" => "editors/markdowneditor.php" + ) +); + // The number of search results per page $search_results_per_page = 25; diff --git a/phplib/header.php b/phplib/header.php index c0c5334..1f9ba52 100644 --- a/phplib/header.php +++ b/phplib/header.php @@ -16,6 +16,7 @@ + diff --git a/save_profile.php b/save_profile.php index 77ac5cd..676aff6 100644 --- a/save_profile.php +++ b/save_profile.php @@ -10,9 +10,10 @@ $tz = mysql_real_escape_string($_POST['timezone']); $sleep_provider = mysql_real_escape_string($_POST['sleeptracking_provider']); $sleep_settings = mysql_real_escape_string(json_encode($_POST['sleeptracking'])); + $editor = mysql_real_escape_string($_POST['editor']); - $query = "REPLACE INTO user_profile (ldap_username, full_name, timezone, sleeptracking_provider, sleeptracking_settings) - VALUES ('$username', '$full_name', '$tz', '$sleep_provider', '$sleep_settings')"; + $query = "REPLACE INTO user_profile (ldap_username, full_name, timezone, sleeptracking_provider, sleeptracking_settings, editor) + VALUES ('$username', '$full_name', '$tz', '$sleep_provider', '$sleep_settings', '$editor')"; if (!mysql_query($query)) { echo "Database update failed, error: " . mysql_error(); } else {