From 265e6a621ed3a171c0672866105b92c61678c0dc Mon Sep 17 00:00:00 2001
From: Jayaram Pai
Date: Sun, 24 Nov 2013 12:28:34 +0530
Subject: adding timestamp, dynamic emails
---
cloud_comments.module | 45 ++++++++++++++++++++++++++++-----------------
css/cloud_comments.css | 25 ++++++++++++++++++++++++-
js/cloud_comments.js | 27 +++++++++++++++++++++++----
3 files changed, 75 insertions(+), 22 deletions(-)
diff --git a/cloud_comments.module b/cloud_comments.module
index 868319a..ff5bf9f 100755
--- a/cloud_comments.module
+++ b/cloud_comments.module
@@ -41,51 +41,53 @@ function cloud_comments_all() {
"Computer Programming",
"Others"
);
-
+
$page_content = "";
$query = "SELECT * FROM {scilab_cloud_comment}";
$query_result = db_query($query);
while ($row = db_fetch_object($query_result)) {
-
+
$border = $row->reply_status?"sent":"not-sent";
$page_content .= t("
");
+ $page_content .= t("
") . $row->date . t("
");
$page_content .= t("
From: ") . $row->email . t("
");
-
+
$page_content .= t("
Type: ") . $types[$row->type] . t("
");
-
+
$q = "SELECT book from {textbook_companion_preference} where id = '%d'";
$qr = db_query($q, $row->books);
$obj = db_fetch_object($qr);
$page_content .= t("
Book: ") . $obj->book . t("
");
-
+
$q = "SELECT name from {textbook_companion_chapter} where id = '%d'";
$qr = db_query($q, $row->chapter);
$obj = db_fetch_object($qr);
$chapter = $obj->name?$obj->name:"None";
$page_content .= t("
Chapter: ") . $chapter . t("
");
-
+
$page_content .= t("
Category: ") . $categories[$row->category] . t("
");
-
+
$q = "SELECT caption from {textbook_companion_example} where id = '%d'";
$qr = db_query($q, $row->example);
$obj = db_fetch_object($qr);
$example_link = $obj->caption?l($obj->caption,"http://cloud.scilab.in/index.php?eid=".$row->example):"None";
-
+
$page_content .= t("
Example: ") . $example_link .t("
");
-
+
$page_content .= t("");
-
+
if ($row->reply) {
$page_content .= t("
Reply Sent:
") . $row->reply . t("
");
}
else {
if (user_access("reply cloud_comments")) {
- $page_content .= t("
Reply");
+ $page_content .= t("
Reply");
$page_content .= t("
");
$page_content .= drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
$page_content .= t("
");
+ $page_content .= t("
x");
}
}
$page_content .= t("
");
@@ -130,8 +132,12 @@ function cloud_comments_reply_form_submit($form, &$form_state) {
$query = "UPDATE {scilab_cloud_comment} SET reply = '%s', reply_status = 1 WHERE id = %d";
$query_result = db_query($query, $form_state["values"]["content"], $form_state["values"]["hidden"]);
+ $email_query = "SELECT email FROM {scilab_cloud_comment} WHERE id = %d";
+ $result = db_query($email_query, $form_state["values"]["hidden"]);
+ $obj = db_fetch_object($result);
+
$message = array(
- 'to' => 'rush2jrp@gmail.com',
+ 'to' => $obj->email,
'subject' => t("Comment Reply"),
'body' => t($form_state["values"]["content"]),
'headers' => array("Content-type" => "text/html; charset=iso-8859-1")
@@ -141,17 +147,22 @@ function cloud_comments_reply_form_submit($form, &$form_state) {
if (!$query_result) {
drupal_set_message("Database updation failed");
} else {
- drupal_set_message("Message sent. . . ");
+ drupal_set_message("Message sent. . .");
}
} // function reply_form_submit
function cloud_comments_delete($comment_id=NULL) {
if ($comment_id && user_access("reply cloud_comments")) {
- return $comment_id;
- } else {
- return "NULL";
+ $query = "DELETE FROM {scilab_cloud_comment} WHERE id = %d";
+ $query_result = db_query($query, $comment_id);
+ if (db_affected_rows() > 0) {
+ drupal_set_message("Deleted");
+ } else {
+ drupal_set_message("MySQL Error: row deletion failed.");
+ }
}
+ drupal_goto("cloud_comments");
}
function cloud_comments_menu() {
@@ -169,7 +180,7 @@ function cloud_comments_menu() {
'access arguments' => array("access cloud_comments"),
'type' => MENU_CALLBACK,
);
-
+
return $items;
} // function cloud_comments_menu
diff --git a/css/cloud_comments.css b/css/cloud_comments.css
index cffaa7e..6392101 100644
--- a/css/cloud_comments.css
+++ b/css/cloud_comments.css
@@ -1,6 +1,7 @@
.feedback {
+ position: relative;
padding: 10px;
- margin: 10px;
+ margin: 15px 10px;
min-height: 100px;
background: #f5f5f5;
-webkit-border-radius: 5px;
@@ -8,9 +9,31 @@
-o-border-radius: 5px;
border-radius: 5px;
}
+.timestamp {
+ position: absolute;
+ right: 55px;
+ top: 10px;
+ color: #aaaaaa;
+}
.sent {
border: 2px solid #86c543;
}
.not-sent {
border: 2px solid tomato;
}
+.btn-reply {
+ position: absolute;
+ right: 10px;
+ bottom: 10px;
+ padding: 5px;
+ background: brown;
+}
+.btn-reply a{
+ text-decoration: none;
+ color: #ffffff;
+}
+.delete {
+ position: absolute;
+ top: 10px;
+ right: 10px;
+}
diff --git a/js/cloud_comments.js b/js/cloud_comments.js
index 9f4c2ad..59523d4 100644
--- a/js/cloud_comments.js
+++ b/js/cloud_comments.js
@@ -1,10 +1,29 @@
$(document).ready(function(){
- $(".feedback a").click(function(){
+ /* to avoid CKE partial loading... */
+ $('.form-wrapper').slideToggle();
+
+ /* reply button action */
+ $(".btn-reply a").click(function(){
var clicked = $(this).attr("class");
- console.log(clicked);
$('#'+clicked).slideToggle();
+ console.log($(this).html());
+ if ($(this).html() == "Reply") {
+ $(this).html("Close");
+ } else {
+ $(this).html("Reply");
+ }
});
- /* to avoid CKE partial loading... */
- $('.form-wrapper').slideToggle();
+ /* delete link */
+ $(".delete").click(function(e){
+ sure = confirm("Are you sure ?");
+ console.log(sure);
+ if (sure) {
+ window.location.href = $(this).attr("href");
+ }
+ else {
+ console.log("nopees");
+ }
+ e.preventDefault();
+ });
});
--
cgit
Comment:
") . $row->comment . t("