5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright (C) 2010 Alain Peyrat - Alcatel-Lucent
7 * Copyright 2011,2016, Franck Villaume - TrivialDev
8 * Copyright 2014, Stéphane-Eymeric Bredthauer
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once '../env.inc.php';
27 require_once $gfcommon.'include/pre.php';
28 require_once $gfwww.'include/vote_function.php';
30 global $HTML; // Layout object
32 if (!forge_get_config('use_diary')) {
36 if (!session_loggedin()) {
40 $u = session_get_user();
41 $diary_id = getIntFromRequest('diary_id');
43 if (getStringFromRequest('submit')) {
44 if (!form_key_is_valid(getStringFromRequest('form_key'))) {
45 exit_form_double_submit('my');
48 $summary = getHtmlStringFromRequest('summary');
49 $details = getHtmlTextFromRequest('details');
50 $is_public = getIntFromRequest('is_public', 0);
52 //make changes to the database
53 if (getStringFromRequest('update')) {
54 //updating an existing diary entry
55 $res=db_query_params ('UPDATE user_diary SET summary=$1,details=$2,is_public=$3
56 WHERE user_id=$4 AND id=$5',
62 if ($res && db_affected_rows($res) > 0) {
63 $feedback .= _('Diary Updated');
65 form_release_key(getStringFromRequest("form_key"));
67 $feedback .= _('Nothing Updated');
69 } elseif (getStringFromRequest('add')) {
70 //inserting a new diary entry
71 $currenttime = time();
72 $res = db_query_params('INSERT INTO user_diary (user_id,date_posted,summary,details,is_public, year, month, is_approved) VALUES
73 ($1,$2,$3,$4,$5, $6, $7, $8)',
79 date('Y', $currenttime),
80 date('m', $currenttime),
82 if ($res && db_affected_rows($res) > 0) {
83 $feedback .= _('Item Added');
86 //send an email if users are monitoring
87 $result = db_query_params ('SELECT users.email from user_diary_monitor,users
88 WHERE user_diary_monitor.user_id=users.user_id
89 AND user_diary_monitor.monitored_user=$1',
90 array(user_getid() ));
91 $rows = db_numrows($result);
95 $tolist=implode(util_result_column_to_array($result),', ');
97 $to = ''; // send to noreply@
98 $subject = sprintf (_("[%s User Notes: %s] %s"),
99 forge_get_config ('forge_name'),
102 $sanitizer = new TextSanitizer();
104 if (strstr($body,'<br/>') || strstr($body,'<br />')) {
105 $body = preg_replace("/[\n\r]/", '', $body);
107 $body = $sanitizer->convertNeededTagsForEmail($body);
108 $body = strip_tags($body);
109 $body = $sanitizer->convertExtendedCharsForEmail($body);
112 $body .= '______________________________________________________________________';
114 $body .= _('You are receiving this email because you elected to monitor this user.');
116 $body .= _('To stop monitoring this user, visit the following link:');
119 $body .= util_make_url('/developer/monitor.php?diary_user='.user_getid());
121 util_send_message($to, $subject, $body, $to, $tolist);
123 $feedback .= " ".sprintf(ngettext("email sent to %s monitoring user",
124 "email sent to %s monitoring users",
128 $feedback .= " "._("email not sent - no one monitoring") ;
135 //don't send an email to monitoring users
136 //since this is a private note
139 form_release_key(getStringFromRequest("form_key"));
140 $error_msg .= _('Error Adding Item')._(': ').db_error();
151 $res=db_query_params('SELECT * FROM user_diary WHERE user_id=$1 AND id=$2',
154 if (!$res || db_numrows($res) < 1) {
155 $feedback .= _('Entry not found or does not belong to you');
157 $info_str = _('Add A New Entry');
159 $proc_str = 'update';
160 $info_str = _('Update An Entry');
161 $_summary = db_result($res,0,'summary');
162 $_details = db_result($res,0,'details');
163 $_is_public = db_result($res,0,'is_public');
164 $_diary_id = db_result($res,0,'id');
168 $info_str = _('Add A New Entry');
172 site_user_header(array('title' => _('My Diary and Notes')));
174 $params['id'] = 'details';
175 $params['name'] = 'details';
176 $params['body'] = $_details;
177 $params['height'] = '350';
178 $params['width'] = '100%';
179 $params['content'] = html_e('textarea', array('required' => 'required', 'name' => 'details', 'rows' => 10, 'cols' => 60), $_details, false);
180 $params['user_id'] = $u->getID();
181 plugin_hook_by_reference("text_editor", $params);
183 echo html_e('h2', array(), $info_str);
184 if (forge_get_config('diary_parser_type') == 'markdown') {
185 echo html_e('p', array(), sprintf(_('You can use markdown syntax in the details of your blog post. Documentation for Markdown syntax is available at <a href="%1$s">%1$s</a>.'),
186 'https://michelf.ca/projets/php-markdown/syntaxe/'));
188 echo $HTML->openForm(array('action' => '/my/diary.php', 'method' => 'post'));
189 echo html_e('input', array('type' => 'hidden', 'name' => 'form_key', 'value' => form_generate_key()));
190 echo html_e('input', array('type' => 'hidden', 'name' => $proc_str, 'value' => '1'));
191 echo html_e('input', array('type' => 'hidden', 'name' => 'diary_id', 'value' => $_diary_id));
192 echo $HTML->listTableTop(array(), array(), 'full');
193 echo html_ao('tr').html_ao('td').html_ao('label', array('for' => 'summary'));
194 echo html_e('strong', array(), _('Summary')._(':')).'<br />';
195 echo html_ac(html_ap()-1);
196 echo html_e('input', array('id' => 'summary', 'required' => 'required', 'type' => 'text', 'name' => 'summary', 'size' => '60', 'maxlength' => '60', 'value' => $_summary));
197 echo html_ac(html_ap()-2);
199 echo html_ao('tr').html_ao('td').html_ao('label', array('for' => 'details'));
200 echo html_e('strong', array(),_('Details')._(':')).'<br />';
201 echo html_ac(html_ap()-1);
202 echo $params['content'];
203 echo html_ac(html_ap()-2);
205 echo html_ao('tr').html_ao('td');
207 echo html_e('input', array('type' => 'submit', 'name' => 'submit', 'value' => _('Submit'))).' ';
209 echo html_e('input', array('id' => 'is_public', 'type' => 'checkbox', 'name' => 'is_public', 'value' => '1', 'checked' => 'checked')).'<label for="is_public">'._('Is Public').'</label>';
211 echo html_e('input', array('id' => 'is_public', 'type' => 'checkbox', 'name' => 'is_public', 'value' => '1')).'<label for="is_public">'._('Is Public').'</label>';
213 echo html_ac(html_ap()-1);
215 echo html_e('p', array(), _('If marked as public, your entry will be mailed to any monitoring users when it is first submitted.'));
216 echo html_ac(html_ap()-2);
217 echo $HTML->listTableBottom();
218 echo $HTML->closeForm();
220 echo html_e('h2', array(), _('Existing Diary and Notes Entries'));
221 $result=db_query_params('SELECT * FROM user_diary WHERE user_id=$1 ORDER BY id DESC',
222 array(user_getid()));
223 $rows=db_numrows($result);
224 if (!$result || $rows < 1) {
225 echo $HTML->information(_('You Have No Diary Entries'));
227 echo $HTML->listTableTop(array(),array(),'fullwidth');
228 for ($i=0; $i<$rows; $i++) {
229 $date = relative_date(db_result($result,$i,'date_posted'));
230 $public = db_result($result,$i,'is_public') ? _('Public') : _('Private');
231 $row_attrs = array();
232 $cell_data = array();
233 $cell_data [] = array(util_make_link('/my/diary.php?diary_id='.db_result($result,$i,'id'), db_result($result,$i,'summary')));
234 $cell_data [] = array($date);
235 $cell_data [] = array($public);
236 echo $HTML->multiTableRow($row_attrs, $cell_data);
238 echo $HTML->listTableBottom();