diff options
author | prashantsinalkar | 2017-12-08 12:48:19 +0530 |
---|---|---|
committer | prashantsinalkar | 2017-12-08 12:48:19 +0530 |
commit | fe27709f114e0ac7edca63f6ee1b0fddc2a9667a (patch) | |
tree | 2be92a01ae796ec4792ce92c3e5731a83cd293a3 /cloud_comments.module~ | |
parent | 2f2076c39f63e760f501aa0720d1426433073a99 (diff) | |
download | scilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.tar.gz scilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.tar.bz2 scilab-cloud-comments-fe27709f114e0ac7edca63f6ee1b0fddc2a9667a.zip |
Diffstat (limited to 'cloud_comments.module~')
-rw-r--r-- | cloud_comments.module~ | 233 |
1 files changed, 233 insertions, 0 deletions
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 & Control Systems", + "Chemical Engineering", + "Thermodynamics", + "Mechanical Engineering", + "Signal Processing", + "Digital Communications", + "Electrical Technology", + "Mathematics & 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"); +} + + +?> |