summaryrefslogtreecommitdiff
path: root/cloud_comments.module
diff options
context:
space:
mode:
authorprashantsinalkar2017-12-08 12:48:19 +0530
committerprashantsinalkar2017-12-08 12:48:19 +0530
commitfe27709f114e0ac7edca63f6ee1b0fddc2a9667a (patch)
tree2be92a01ae796ec4792ce92c3e5731a83cd293a3 /cloud_comments.module
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
Diffstat (limited to 'cloud_comments.module')
-rw-r--r--[-rwxr-xr-x]cloud_comments.module143
1 files changed, 85 insertions, 58 deletions
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
?>