summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2017-12-08 12:48:19 +0530
committerprashantsinalkar2017-12-08 12:48:19 +0530
commitfe27709f114e0ac7edca63f6ee1b0fddc2a9667a (patch)
tree2be92a01ae796ec4792ce92c3e5731a83cd293a3
parent2f2076c39f63e760f501aa0720d1426433073a99 (diff)
downloadscilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.tar.gz
scilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.tar.bz2
scilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.zip
updated the module for drupal 7.xHEADmaster
-rw-r--r--README.md3
-rw-r--r--README.md~3
-rw-r--r--[-rwxr-xr-x]cloud_comments.info3
-rw-r--r--[-rwxr-xr-x]cloud_comments.module143
-rw-r--r--cloud_comments.module~233
-rw-r--r--[-rwxr-xr-x]css/cloud_comments.css0
-rw-r--r--[-rwxr-xr-x]js/cloud_comments.js4
-rw-r--r--[-rwxr-xr-x]js/jquery.min.js0
8 files changed, 329 insertions, 60 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9f4f30f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+Scilab Cloud Comment module for Drupal 7.x
+
+Author: Prashant Sinalkar, Jayram Pai
diff --git a/README.md~ b/README.md~
new file mode 100644
index 0000000..9f4f30f
--- /dev/null
+++ b/README.md~
@@ -0,0 +1,3 @@
+Scilab Cloud Comment module for Drupal 7.x
+
+Author: Prashant Sinalkar, Jayram Pai
diff --git a/cloud_comments.info b/cloud_comments.info
index be16916..6cf7642 100755..100644
--- a/cloud_comments.info
+++ b/cloud_comments.info
@@ -1,3 +1,4 @@
name = Cloud comments
description = A module to view and reply to Scilab on Cloud comments.
-core = 6.x
+core = 7.x
+package =IITB
diff --git a/cloud_comments.module b/cloud_comments.module
index 2addaf9..a359a41 100755..100644
--- a/cloud_comments.module
+++ b/cloud_comments.module
@@ -1,5 +1,48 @@
<?php
+
+function cloud_comments_menu() {
+ $items = array();
+ $items['cloud_comments'] = array(
+ 'title' => 'Cloud Comments',
+ 'page callback' => 'cloud_comments_all',
+ 'access arguments' => array("access cloud_comments"),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['cloud_comments/delete'] = array(
+ 'title' => 'Cloud Comments',
+ 'page callback' => 'cloud_comments_delete',
+ 'access arguments' => array("access cloud_comments"),
+ 'type' => MENU_CALLBACK,
+ );
+
+ return $items;
+} // function cloud_comments_menu
+
+function cloud_comments_permission(){
+
+ return array(
+ 'access cloud_comments' => array(
+ 'title' => t('access cloud_comments'),
+ 'restrict access' => TRUE,
+ ),
+ 'reply cloud_comments' => array(
+ 'title' => t('reply cloud_comments'),
+ 'restrict access' => TRUE,
+ ),
+
+ );
+} // function cloud_comments_perm
+
+
+
+function cloud_comments_init() {
+ drupal_add_css(drupal_get_path("module", "cloud_comments") . "/css/cloud_comments.css");
+ drupal_add_js(drupal_get_path("module", "cloud_comments") . "/js/cloud_comments.js");
+} //function cloud_comments_init
+
+
function cloud_comments_help($path, $arg) {
$output = '';
switch($path) {
@@ -10,9 +53,6 @@ function cloud_comments_help($path, $arg) {
return $output;
} // function cloud_comments_help
-function cloud_comments_perm() {
- return array("access cloud_comments", "reply cloud_comments");
-} // function cloud_comments_perm
function cloud_comments_all($example_id=0) {
$types = array(
@@ -44,14 +84,14 @@ function cloud_comments_all($example_id=0) {
$page_content = "";
if($example_id) {
- $query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example WHERE scc.example = {$example_id} ORDER BY scc.date DESC";
+ $query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example WHERE scc.example = {:example_id} ORDER BY scc.date DESC";
} else {
$query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example ORDER BY scc.date DESC";
}
- $query_result = pager_query($query, 5, 0 );
- //$query_result = db_query($query);
+ // $query_result = pager_query($query, 5, 0 );
+ $query_result = db_query($query, array(':example_id' => $example_id));
- while ($row = db_fetch_object($query_result)) {
+ while ($row = $query_result->fetchObject()) {
$border = $row->reply_status?"sent":"not-sent";
$page_content .= t("<div class='feedback {$border}'>");
@@ -63,23 +103,23 @@ function cloud_comments_all($example_id=0) {
$page_content .= t("<div class='type'> <b>Type:</b> ") . $types[$row->type] . t("</div>");
- $q = "SELECT book from {textbook_companion_preference} where id = '%d'";
- $qr = db_query($q, $row->books);
- $obj = db_fetch_object($qr);
+ $q = "SELECT book from {textbook_companion_preference} where id = :book";
+ $qr = db_query($q, array(':book'=>$row->books));
+ $obj = $qr->fetchObject();
$page_content .= t("<div class='type'> <b>Category: </b>") . $categories[$row->category] . t("</div>");
$page_content .= t("<div class='type'> <b>Book:</b> ") . $obj->book . t("</div>");
- $q = "SELECT name from {textbook_companion_chapter} where id = '%d'";
- $qr = db_query($q, $row->chapter);
- $obj = db_fetch_object($qr);
+ $q = "SELECT name from {textbook_companion_chapter} where id = :chapter";
+ $qr = db_query($q, array(':chapter' => $row->chapter));
+ $obj = $qr->fetchObject();
$chapter = $obj->name?$obj->name:"None";
$page_content .= t("<div class='type'> <b>Chapter: </b> ") . $chapter . ($row->chapter_no?" (<b>{$row->chapter_no}</b>)":"") . t("</div>");
- $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";
+ $q = "SELECT caption from {textbook_companion_example} where id = :example";
+ $qr = db_query($q, array(':example' => $row->example));
+ $obj = $qr->fetchObject();
+ $example_link = $obj->caption?l($obj->caption,"https://cloud.scilab.in/index?eid=".$row->example):"None";
$page_content .= t("<div class='example'> <b>Example: </b>") . $example_link . ($row->example_no?" (<b>{$row->example_no}</b>)":"") . t("</div>");
@@ -94,16 +134,17 @@ function cloud_comments_all($example_id=0) {
}
else {
if (user_access("reply cloud_comments")) {
- $page_content .= t("<span class='btn-reply'><a class='form_{$row->id}' href='#form_{$row->id}'>Reply</a></span><br>");
- $page_content .= t("<div id='form_{$row->id}' class='form-wrapper'>");
- $page_content .= drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
+ // $page_content .= t("<span class='btn-reply'><a class='form_{$row->id}' href='#form_{$row->id}'>Reply</a></span><br>");
+ $page_content .= t("<div id='form_{$row->id}' class='formwrapper'>");
+ $cloud_comments_reply_form = drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
+ $page_content .= drupal_render($cloud_comments_reply_form);
$page_content .= t("</div>");
$page_content .= t("<a href='cloud_comments/delete/{$row->id}' id='del_{$row->id}' class='delete'>x</a>");
}
}
$page_content .= t("</div>");
} // while ends
- $page_content .= theme('pager', NULL, 5, 0);
+ $page_content .= theme('pager', array('header' => NULL, 'rows' => 5 ));
return $page_content;
} // function cloud_comments_all
@@ -117,7 +158,7 @@ function cloud_comments_forms($form_id) {
return $forms;
} // function cloud_comments_forms
-function cloud_comments_reply_form($form_state, $comment_id) {
+function cloud_comments_reply_form($form, $form_state, $comment_id) {
$form = array();
$form["#submit"] = array(
'cloud_comments_reply_form_submit',
@@ -129,11 +170,11 @@ function cloud_comments_reply_form($form_state, $comment_id) {
);
$form["hidden"] = array(
'#type' => 'hidden',
- '#value' => $comment_id
+ '#default_value' => $comment_id
);
$form["submit"] = array(
'#type' => 'submit',
- '#value' => 'submit'
+ '#value' => 'Reply'
);
return $form;
@@ -142,21 +183,30 @@ function cloud_comments_reply_form($form_state, $comment_id) {
function cloud_comments_reply_form_submit($form, &$form_state) {
global $user;
- $query = "UPDATE {scilab_cloud_comment} SET reply = '%s', user= '%s', reply_status = 1 WHERE id = %d";
- $query_result = db_query($query, $form_state["values"]["content"], $user->name, $form_state["values"]["hidden"]);
+ $query = "UPDATE {scilab_cloud_comment} SET reply = :reply, user= :users, reply_status = 1 WHERE id = :id";
+ $query_result = db_query($query, array(':reply'=> $form_state["values"]["content"], ':users' => $user->name, ':id' => $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);
+ $email_query = "SELECT email FROM {scilab_cloud_comment} WHERE id = :id";
+ $result = db_query($email_query, array(':id' => $form_state["values"]["hidden"]));
+ $obj = $result->fetchObject();
- $message = array(
+ /* $message = array(
'to' => $obj->email,
'subject' => t("Comment Reply"),
- 'body' => t($form_state["values"]["content"]),
+ 'body' => array(0=> t($form_state["values"]["content"])),
'headers' => array("From" => "textbook@scilab.in", "Content-type" => "text/html; charset=iso-8859-1")
);
- drupal_mail_send($message);
+ send_mail($message);
+*/
+/* sending mail */
+ $to = $obj->email;
+ $subject = t("Scilab on Cloud Comment Reply");
+ $message = t($form_state["values"]["content"]);
+ // drupal_mail_send($message);
+ send_mail("textbook@scilab.in", $to, $subject, $message);
+
+
if (!$query_result) {
drupal_set_message("Database updation failed");
@@ -168,9 +218,9 @@ function cloud_comments_reply_form_submit($form, &$form_state) {
function cloud_comments_delete($comment_id=NULL) {
if ($comment_id && user_access("reply cloud_comments")) {
- $query = "DELETE FROM {scilab_cloud_comment} WHERE id = %d";
- $query_result = db_query($query, $comment_id);
- if (db_affected_rows() > 0) {
+ $query = "DELETE FROM {scilab_cloud_comment} WHERE id = :id";
+ $query_result = db_query($query, array(':id' => $comment_id));
+ if ($query_result->rowCount() > 0) {
drupal_set_message("Deleted");
} else {
drupal_set_message("MySQL Error: row deletion failed.");
@@ -179,28 +229,5 @@ function cloud_comments_delete($comment_id=NULL) {
drupal_goto("cloud_comments");
}
-function cloud_comments_menu() {
- $items = array();
- $items['cloud_comments'] = array(
- 'title' => 'Cloud Comments',
- 'page callback' => 'cloud_comments_all',
- 'access arguments' => array("access cloud_comments"),
- 'type' => MENU_CALLBACK,
- );
-
- $items['cloud_comments/delete'] = array(
- 'title' => 'Cloud Comments',
- 'page callback' => 'cloud_comments_delete',
- 'access arguments' => array("access cloud_comments"),
- 'type' => MENU_CALLBACK,
- );
-
- return $items;
-} // function cloud_comments_menu
-
-function cloud_comments_init() {
- drupal_add_css(drupal_get_path("module", "cloud_comments") . "/css/cloud_comments.css");
- drupal_add_js(drupal_get_path("module", "cloud_comments") . "/js/cloud_comments.js");
-} //function cloud_comments_init
?>
diff --git a/cloud_comments.module~ b/cloud_comments.module~
new file mode 100644
index 0000000..a359a41
--- /dev/null
+++ b/cloud_comments.module~
@@ -0,0 +1,233 @@
+<?php
+
+
+function cloud_comments_menu() {
+ $items = array();
+ $items['cloud_comments'] = array(
+ 'title' => 'Cloud Comments',
+ 'page callback' => 'cloud_comments_all',
+ 'access arguments' => array("access cloud_comments"),
+ 'type' => MENU_CALLBACK,
+ );
+
+ $items['cloud_comments/delete'] = array(
+ 'title' => 'Cloud Comments',
+ 'page callback' => 'cloud_comments_delete',
+ 'access arguments' => array("access cloud_comments"),
+ 'type' => MENU_CALLBACK,
+ );
+
+ return $items;
+} // function cloud_comments_menu
+
+function cloud_comments_permission(){
+
+ return array(
+ 'access cloud_comments' => array(
+ 'title' => t('access cloud_comments'),
+ 'restrict access' => TRUE,
+ ),
+ 'reply cloud_comments' => array(
+ 'title' => t('reply cloud_comments'),
+ 'restrict access' => TRUE,
+ ),
+
+ );
+} // function cloud_comments_perm
+
+
+
+function cloud_comments_init() {
+ drupal_add_css(drupal_get_path("module", "cloud_comments") . "/css/cloud_comments.css");
+ drupal_add_js(drupal_get_path("module", "cloud_comments") . "/js/cloud_comments.js");
+} //function cloud_comments_init
+
+
+function cloud_comments_help($path, $arg) {
+ $output = '';
+ switch($path) {
+ case "admin/help#cloud_comments":
+ $output = "<p>" . t("Displays the Comments on cloud and enables the admin to reply to them via e-mail: textbook@scilab.in") . "</p>";
+ break;
+ }
+ return $output;
+} // function cloud_comments_help
+
+
+function cloud_comments_all($example_id=0) {
+ $types = array(
+ "None",
+ "Blank Code / Incorrect code",
+ "Output error",
+ "Execution error",
+ "Missing example(s)",
+ "None",
+ "Blank output",
+ "Any other"
+ );
+ $categories = array(
+ "Others",
+ "Fluid Mechanics",
+ "Control Theory &amp; Control Systems",
+ "Chemical Engineering",
+ "Thermodynamics",
+ "Mechanical Engineering",
+ "Signal Processing",
+ "Digital Communications",
+ "Electrical Technology",
+ "Mathematics &amp; Pure Science",
+ "Analog Electronics",
+ "Digital Electronics",
+ "Computer Programming",
+ "Others"
+ );
+
+ $page_content = "";
+ if($example_id) {
+ $query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example WHERE scc.example = {:example_id} ORDER BY scc.date DESC";
+ } else {
+ $query = "SELECT scc.*, tcc.number AS chapter_no, tce.number AS example_no FROM scilab_cloud_comment scc LEFT JOIN textbook_companion_chapter tcc ON tcc.id = scc.chapter LEFT JOIN textbook_companion_example tce ON tce.id = scc.example ORDER BY scc.date DESC";
+ }
+ // $query_result = pager_query($query, 5, 0 );
+ $query_result = db_query($query, array(':example_id' => $example_id));
+
+ while ($row = $query_result->fetchObject()) {
+
+ $border = $row->reply_status?"sent":"not-sent";
+ $page_content .= t("<div class='feedback {$border}'>");
+
+ $page_content .= t("<div class='timestamp'>") . $row->date . t("</div>");
+ if (user_access("reply cloud_comments")) {
+ $page_content .= t("<div class='from'> <b>From:</b> ") . $row->email . t("</div>");
+ }
+
+ $page_content .= t("<div class='type'> <b>Type:</b> ") . $types[$row->type] . t("</div>");
+
+ $q = "SELECT book from {textbook_companion_preference} where id = :book";
+ $qr = db_query($q, array(':book'=>$row->books));
+ $obj = $qr->fetchObject();
+ $page_content .= t("<div class='type'> <b>Category: </b>") . $categories[$row->category] . t("</div>");
+ $page_content .= t("<div class='type'> <b>Book:</b> ") . $obj->book . t("</div>");
+
+ $q = "SELECT name from {textbook_companion_chapter} where id = :chapter";
+ $qr = db_query($q, array(':chapter' => $row->chapter));
+ $obj = $qr->fetchObject();
+ $chapter = $obj->name?$obj->name:"None";
+ $page_content .= t("<div class='type'> <b>Chapter: </b> ") . $chapter . ($row->chapter_no?" (<b>{$row->chapter_no}</b>)":"") . t("</div>");
+
+
+ $q = "SELECT caption from {textbook_companion_example} where id = :example";
+ $qr = db_query($q, array(':example' => $row->example));
+ $obj = $qr->fetchObject();
+ $example_link = $obj->caption?l($obj->caption,"https://cloud.scilab.in/index?eid=".$row->example):"None";
+
+ $page_content .= t("<div class='example'> <b>Example: </b>") . $example_link . ($row->example_no?" (<b>{$row->example_no}</b>)":"") . t("</div>");
+
+ $page_content .= t("<div class='comment'> <br><b>Comment:</b><br>") . $row->comment . t("</div>");
+
+ if ($row->reply) {
+ if(!$row->user){
+ $page_content .= t("<div class='reply'> <br><b>Reply Sent:</b><br>") . $row->reply . t("</div>");
+ }else{
+ $page_content .= t("<div class='reply'> <br><b>Reply Sent By ".$row->user.":</b><br>") . $row->reply . t("</div>");
+ }
+ }
+ else {
+ if (user_access("reply cloud_comments")) {
+ // $page_content .= t("<span class='btn-reply'><a class='form_{$row->id}' href='#form_{$row->id}'>Reply</a></span><br>");
+ $page_content .= t("<div id='form_{$row->id}' class='formwrapper'>");
+ $cloud_comments_reply_form = drupal_get_form("cloud_comments_reply_form_".$row->id, $row->id);
+ $page_content .= drupal_render($cloud_comments_reply_form);
+ $page_content .= t("</div>");
+ $page_content .= t("<a href='cloud_comments/delete/{$row->id}' id='del_{$row->id}' class='delete'>x</a>");
+ }
+ }
+ $page_content .= t("</div>");
+ } // while ends
+ $page_content .= theme('pager', array('header' => NULL, 'rows' => 5 ));
+ return $page_content;
+} // function cloud_comments_all
+
+function cloud_comments_forms($form_id) {
+ $forms = array();
+ if (strpos($form_id, 'cloud_comments_reply_form_') === 0) {
+ $forms[$form_id] = array(
+ 'callback' => 'cloud_comments_reply_form',
+ );
+ }
+ return $forms;
+} // function cloud_comments_forms
+
+function cloud_comments_reply_form($form, $form_state, $comment_id) {
+ $form = array();
+ $form["#submit"] = array(
+ 'cloud_comments_reply_form_submit',
+ );
+
+ $form["content"] = array(
+ '#type' => 'textarea',
+ '#wysiwyg' => True
+ );
+ $form["hidden"] = array(
+ '#type' => 'hidden',
+ '#default_value' => $comment_id
+ );
+ $form["submit"] = array(
+ '#type' => 'submit',
+ '#value' => 'Reply'
+ );
+
+ return $form;
+} // function reply_form
+
+function cloud_comments_reply_form_submit($form, &$form_state) {
+ global $user;
+
+ $query = "UPDATE {scilab_cloud_comment} SET reply = :reply, user= :users, reply_status = 1 WHERE id = :id";
+ $query_result = db_query($query, array(':reply'=> $form_state["values"]["content"], ':users' => $user->name, ':id' => $form_state["values"]["hidden"]));
+
+ $email_query = "SELECT email FROM {scilab_cloud_comment} WHERE id = :id";
+ $result = db_query($email_query, array(':id' => $form_state["values"]["hidden"]));
+ $obj = $result->fetchObject();
+
+ /* $message = array(
+ 'to' => $obj->email,
+ 'subject' => t("Comment Reply"),
+ 'body' => array(0=> t($form_state["values"]["content"])),
+ 'headers' => array("From" => "textbook@scilab.in", "Content-type" => "text/html; charset=iso-8859-1")
+
+ );
+ send_mail($message);
+*/
+/* sending mail */
+ $to = $obj->email;
+ $subject = t("Scilab on Cloud Comment Reply");
+ $message = t($form_state["values"]["content"]);
+ // drupal_mail_send($message);
+ send_mail("textbook@scilab.in", $to, $subject, $message);
+
+
+
+ if (!$query_result) {
+ drupal_set_message("Database updation failed");
+ } else {
+ drupal_set_message("Message sent. . .");
+ }
+
+} // function reply_form_submit
+
+function cloud_comments_delete($comment_id=NULL) {
+ if ($comment_id && user_access("reply cloud_comments")) {
+ $query = "DELETE FROM {scilab_cloud_comment} WHERE id = :id";
+ $query_result = db_query($query, array(':id' => $comment_id));
+ if ($query_result->rowCount() > 0) {
+ drupal_set_message("Deleted");
+ } else {
+ drupal_set_message("MySQL Error: row deletion failed.");
+ }
+ }
+ drupal_goto("cloud_comments");
+}
+
+
+?>
diff --git a/css/cloud_comments.css b/css/cloud_comments.css
index 6392101..6392101 100755..100644
--- a/css/cloud_comments.css
+++ b/css/cloud_comments.css
diff --git a/js/cloud_comments.js b/js/cloud_comments.js
index 59523d4..24ee357 100755..100644
--- a/js/cloud_comments.js
+++ b/js/cloud_comments.js
@@ -1,6 +1,7 @@
+(function($) {
$(document).ready(function(){
/* to avoid CKE partial loading... */
- $('.form-wrapper').slideToggle();
+// $('.formwrapper').slideToggle();
/* reply button action */
$(".btn-reply a").click(function(){
@@ -27,3 +28,4 @@ $(document).ready(function(){
e.preventDefault();
});
});
+})(jQuery);
diff --git a/js/jquery.min.js b/js/jquery.min.js
index 29b3a2c..29b3a2c 100755..100644
--- a/js/jquery.min.js
+++ b/js/jquery.min.js